lib: Adjustments for 11 function implementations
Subsystems (4)
cover lib: Adjustments for 11 function implementations
From: Markus Elfring <[email protected]>
Date: Sat, 7 Oct 2017 19:39:29 +0200
Two update suggestions were taken into account
from static source code analysis.
Markus Elfring (2):
test: Delete five error messages for a failed memory allocation Improve a size determination in seven functions
lib/dma-debug.c | 2 +- lib/flex_array.c | 4 ++-- lib/genalloc.c | 2 +- lib/lru_cache.c | 2 +- lib/reed_solomon/reed_solomon.c | 2 +- lib/test_kasan.c | 5 ++--- lib/test_kmod.c | 10 +++------- lib/test_list_sort.c | 9 +++------ 8 files changed, 14 insertions(+), 22 deletions(-)
Signature · 1 line
2.14.2
PATCH 1/2 lib/test: Delete five error messages for a failed memory allocation
From: Markus Elfring <[email protected]>
Date: Sat, 7 Oct 2017 17:34:23 +0200
Omit extra messages for a memory allocation failure in these functions.
This issue was detected by using the Coccinelle software.
--- lib/test_kasan.c | 5 ++--- lib/test_kmod.c | 8 ++------ lib/test_list_sort.c | 9 +++------ 3 files changed, 7 insertions(+), 15 deletions(-)
lib/test_kasan.c +2 -3
@@ -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 ); }
lib/test_kmod.c +2 -6
@@ -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 ; }
@@ -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);
lib/test_list_sort.c +3 -6
@@ -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;
Signature · 1 line
2.14.2
PATCH 2/2 lib: Improve a size determination in seven functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 7 Oct 2017 19:19:45 +0200
Replace the specification of data structures by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
This issue was detected by using the Coccinelle software.
--- lib/dma-debug.c | 2 +- lib/flex_array.c | 4 ++-- lib/genalloc.c | 2 +- lib/lru_cache.c | 2 +- lib/reed_solomon/reed_solomon.c | 2 +- lib/test_kmod.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-)
lib/dma-debug.c +1 -1
@@ -993,7 +993,7 @@ void dma_debug_add_bus(struct bus_type *bus)if (dma_debug_disabled ())return ; - nb =kzalloc (sizeof (struct notifier_block ),GFP_KERNEL ); + nb =kzalloc (sizeof (*nb),GFP_KERNEL );if (nb =NULL ) {pr_err ("dma_debug_add_bus: out of memory\n" );return ;
lib/flex_array.c +2 -2
@@ -102,7 +102,7 @@ struct flex_array *flex_array_alloc(int element_size, unsigned int total,/* max_size will end up 0 if element_size > PAGE_SIZE */ if (total > max_size)return NULL ; - ret =kzalloc (sizeof (struct flex_array ), flags); + ret =kzalloc (sizeof (*ret), flags);if (!ret)return NULL ; ret->element_size = element_size;
@@ -167,7 +167,7 @@ __fa_get_part(struct flex_array *fa, int part_nr, gfp_t flags) {struct flex_array_part *part = fa->parts[part_nr];if (!part) { - part =kmalloc (sizeof (struct flex_array_part ), flags); + part =kmalloc (sizeof (*part), flags);if (!part)return NULL ;if (!(flags & __GFP_ZERO))
lib/genalloc.c +1 -1
@@ -153,7 +153,7 @@ struct gen_pool *gen_pool_create(int min_alloc_order, int nid) {struct gen_pool *pool; - pool =kmalloc_node (sizeof (struct gen_pool ),GFP_KERNEL , nid); + pool =kmalloc_node (sizeof (*pool),GFP_KERNEL , nid);if (pool !=NULL ) {spin_lock_init (&pool->lock);INIT_LIST_HEAD (&pool->chunks);
lib/lru_cache.c +1 -1
@@ -116,7 +116,7 @@ struct lru_cache *lc_create(const char *name, struct kmem_cache *cache,if (e_count >LC_MAX_ACTIVE )return NULL ; - slot =kcalloc (e_count,sizeof (struct hlist_head ),GFP_KERNEL ); + slot =kcalloc (e_count,sizeof (*slot),GFP_KERNEL );if (!slot) goto out_fail; element =kzalloc (e_count *sizeof (struct lc_element *),GFP_KERNEL );
lib/reed_solomon/reed_solomon.c +1 -1
@@ -70,7 +70,7 @@ static struct rs_control *rs_init(int symsize, int gfpoly, int (*gffunc)(int),int i, j, sr, root, iprim;/* Allocate the control structure */ - rs =kmalloc (sizeof (struct rs_control ),GFP_KERNEL ); + rs =kmalloc (sizeof (*rs),GFP_KERNEL );if (rs =NULL )return NULL ;
lib/test_kmod.c +1 -1
@@ -1086,7 +1086,7 @@ static struct kmod_test_device *alloc_test_dev_kmod(int idx)struct kmod_test_device *test_dev;struct miscdevice *misc_dev; - test_dev =vzalloc (sizeof (struct kmod_test_device )); + test_dev =vzalloc (sizeof (*test_dev));if (!test_dev) goto err_out;
Signature · 1 line
2.14.2
Please stop sending this crap. It's a move from one preference to another slightly different one. You are free to apply your preference if you do a major overhaul of some code (subject to maintainer approval), but without that they simply are churn.
NAK for both patches.
Re: [PATCH 2/2] lib: Improve a size determination in seven functions
In reply to SF Markus ElfringQuoted 10 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 7 Oct 2017 19:19:45 +0200Replace the specification of data structures by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Quoted 7 lines · Christoph Hellwig
Please stop sending this crap. It's a move from one preference to another slightly different one. You are free to apply your preference if you do a major overhaul of some code (subject to maintainer approval),
but without that they simply are churn.NAK for both patches.
While patch 1 might have some sense, second one is matter of taste which is dependent to maintainer/trends/weather on Mars.
So, +1 to Christoph's opinion.
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Re: [PATCH 1/2] lib/test: Delete five error messages for a failed memory allocation
In reply to SF Markus ElfringQuoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 7 Oct 2017 17:34:23 +0200Omit extra messages for a memory allocation failure in these functions.
This issue was detected by using the Coccinelle software.
Yes this makes sense. None of those really explain what the allocation failure effect is. The allocation path already tells us about the failure enough.
Quoted 1 line
Signed-off-by Markus Elfring <[email protected]>
Quoted 78 lines
--- lib/test_kasan.c | 5 ++--- lib/test_kmod.c | 8 ++------ lib/test_list_sort.c | 9 +++------ 3 files changed, 7 insertions(+), 15 deletions(-)lib/test_kasan.c +2
-3@@ -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 ); }lib/test_kmod.c +2
-6@@ -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 ; }@@ -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);lib/test_list_sort.c +3
-6@@ -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;Signature · 1 line
2.14.2
Signature · 2 lines
Michal Hocko SUSE Labs