Skip to content

Commit

Permalink
lib/test: delete five error messages for failed memory allocations
Browse files Browse the repository at this point in the history
Omit extra messages for a memory allocation failure in these functions.

This issue was detected by using the Coccinelle software.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Markus Elfring <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
elfring authored and torvalds committed Nov 18, 2017
1 parent d6b28e0 commit dc2bf00
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
5 changes: 2 additions & 3 deletions lib/test_kasan.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,9 @@ static noinline void __init memcg_accounted_kmem_cache(void)
*/
for (i = 0; i < 5; i++) {
p = kmem_cache_alloc(cache, GFP_KERNEL);
if (!p) {
pr_err("Allocation failed\n");
if (!p)
goto free_cache;
}

kmem_cache_free(cache, p);
msleep(100);
}
Expand Down
8 changes: 2 additions & 6 deletions lib/test_kmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,10 +783,8 @@ static int kmod_config_sync_info(struct kmod_test_device *test_dev)
free_test_dev_info(test_dev);
test_dev->info = vzalloc(config->num_threads *
sizeof(struct kmod_test_device_info));
if (!test_dev->info) {
dev_err(test_dev->dev, "Cannot alloc test_dev info\n");
if (!test_dev->info)
return -ENOMEM;
}

return 0;
}
Expand Down Expand Up @@ -1089,10 +1087,8 @@ static struct kmod_test_device *alloc_test_dev_kmod(int idx)
struct miscdevice *misc_dev;

test_dev = vzalloc(sizeof(struct kmod_test_device));
if (!test_dev) {
pr_err("Cannot alloc test_dev\n");
if (!test_dev)
goto err_out;
}

mutex_init(&test_dev->config_mutex);
mutex_init(&test_dev->trigger_mutex);
Expand Down
9 changes: 3 additions & 6 deletions lib/test_list_sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,14 @@ static int __init list_sort_test(void)
pr_debug("start testing list_sort()\n");

elts = kcalloc(TEST_LIST_LEN, sizeof(*elts), GFP_KERNEL);
if (!elts) {
pr_err("error: cannot allocate memory\n");
if (!elts)
return err;
}

for (i = 0; i < TEST_LIST_LEN; i++) {
el = kmalloc(sizeof(*el), GFP_KERNEL);
if (!el) {
pr_err("error: cannot allocate memory\n");
if (!el)
goto exit;
}

/* force some equivalencies */
el->value = prandom_u32() % (TEST_LIST_LEN / 3);
el->serial = i;
Expand Down

0 comments on commit dc2bf00

Please sign in to comment.