gpio: aggregator: Fix Smatch warnings
Subsystems (2)
cover gpio: aggregator: Fix Smatch warnings
Fix some static checker warnings from Smatch:
https://github.com/error27/smatch
Dan Carpenter (5):
gpio: aggregator: fix "_sysfs" prefix check in
gpio_aggregator_make_group()
gpio: aggregator: Fix gpio_aggregator_line_alloc() checking
gpio: aggregator: Return an error if there are no GPIOs in
gpio_aggregator_parse()
gpio: aggregator: Fix error code in gpio_aggregator_activate()
gpio: aggregator: Fix leak in gpio_aggregator_parse()
drivers/gpio/gpio-aggregator.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
Signature · 1 line
2.47.2
PATCH 1/5 gpio: aggregator: fix "_sysfs" prefix check in gpio_aggregator_make_group()
This code is intended to reject strings that start with "_sysfs" but the strcmp() limit is wrong so checks the whole string instead of the prefix.
--- drivers/gpio/gpio-aggregator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-aggregator.c +1 -1
@@ -1016,7 +1016,7 @@ gpio_aggregator_make_group(struct config_group *group, const char *name)* for devices create via legacy sysfs interface. */ if (strncmp (name,AGGREGATOR_LEGACY_PREFIX , -sizeof (AGGREGATOR_LEGACY_PREFIX )) ==0 ) +sizeof (AGGREGATOR_LEGACY_PREFIX ) -1 ) ==0 )return ERR_PTR (-EINVAL );/* arg space is unneeded */
Signature · 1 line
2.47.2
PATCH 2/5 gpio: aggregator: Fix gpio_aggregator_line_alloc() checking
In reply to Dan CarpenterThe gpio_aggregator_line_alloc() function returns error pointers, but the callers check for NULL. Update the error checking in the callers.
--- drivers/gpio/gpio-aggregator.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpio/gpio-aggregator.c +6 -6
@@ -984,8 +984,8 @@ gpio_aggregator_device_make_group(struct config_group *group, const char *name)return ERR_PTR (-EINVAL ); line =gpio_aggregator_line_alloc (aggr, idx,NULL ,-1 ); -if (!line) -return ERR_PTR (-ENOMEM ); +if (IS_ERR (line)) +return ERR_CAST (line);config_group_init_type_name (&line->group, name, &gpio_aggregator_line_type);
@@ -1074,8 +1074,8 @@ static int gpio_aggregator_parse(struct gpio_aggregator *aggr)/* Named GPIO line */ scnprintf (name,sizeof (name),"line%u" , n); line =gpio_aggregator_line_alloc (aggr, n, key,-1 ); -if (!line) { - error = -ENOMEM ; +if (IS_ERR (line)) { + error =PTR_ERR (line); goto err; } config_group_init_type_name(&line->group, name,
@@ -1105,8 +1105,8 @@ static int gpio_aggregator_parse(struct gpio_aggregator *aggr)for_each_set_bit (i, bitmap,AGGREGATOR_MAX_GPIOS ) {scnprintf (name,sizeof (name),"line%u" , n); line =gpio_aggregator_line_alloc (aggr, n, key, i); -if (!line) { - error = -ENOMEM ; +if (IS_ERR (line)) { + error =PTR_ERR (line); goto err; } config_group_init_type_name(&line->group, name,
Signature · 1 line
2.47.2
PATCH 3/5 gpio: aggregator: Return an error if there are no GPIOs in gpio_aggregator_parse()
In reply to Dan CarpenterThe error handling in gpio_aggregator_parse() was re-written. It now returns success if there are no GPIOs. Restore the previous behavior and return -EINVAL instead.
--- drivers/gpio/gpio-aggregator.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpio/gpio-aggregator.c +1 -0
@@ -1128,6 +1128,7 @@ static int gpio_aggregator_parse(struct gpio_aggregator *aggr)if (!n) {pr_err ("No GPIOs specified\n" ); + error = -EINVAL ; goto err; }
Signature · 1 line
2.47.2
PATCH 4/5 gpio: aggregator: Fix error code in gpio_aggregator_activate()
In reply to Dan CarpenterPropagate the error code if gpio_aggregator_make_device_sw_node() fails. Don't return success.
--- drivers/gpio/gpio-aggregator.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpio/gpio-aggregator.c +3 -1
@@ -626,8 +626,10 @@ static int gpio_aggregator_activate(struct gpio_aggregator *aggr)return -ENOMEM ; swnode =gpio_aggregator_make_device_sw_node (aggr); -if (IS_ERR (swnode)) +if (IS_ERR (swnode)) { + ret =PTR_ERR (swnode); goto err_remove_lookups; + }memset (&pdevinfo,0 ,sizeof (pdevinfo)); pdevinfo.name =DRV_NAME ;
Signature · 1 line
2.47.2
PATCH 5/5 gpio: aggregator: Fix leak in gpio_aggregator_parse()
In reply to Dan CarpenterCall gpio_aggregator_free_lines() before returning on this error path.
--- drivers/gpio/gpio-aggregator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-aggregator.c +1 -1
@@ -1101,7 +1101,7 @@ static int gpio_aggregator_parse(struct gpio_aggregator *aggr) error =bitmap_parselist (offsets, bitmap,AGGREGATOR_MAX_GPIOS );if (error) {pr_err ("Cannot parse %s: %d\n" , offsets, error); -return error; + goto err; }for_each_set_bit (i, bitmap,AGGREGATOR_MAX_GPIOS ) {
Signature · 1 line
2.47.2
Quoted 12 lines · Dan Carpenter
Fix some static checker warnings from Smatch:
https://github.com/error27/smatchDan Carpenter (5):
gpio: aggregator: fix "_sysfs" prefix check in
gpio_aggregator_make_group()
gpio: aggregator: Fixgpio_aggregator_line_alloc()checking
gpio: aggregator: Return an error if there are no GPIOs in
gpio_aggregator_parse()
gpio: aggregator: Fix error code ingpio_aggregator_activate()
gpio: aggregator: Fix leak ingpio_aggregator_parse()
Quoted 2 lines
drivers/gpio/gpio-aggregator.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
Thank you very much for spotting these issues. I doubt myself for having overlooked these.. And I had actually forgotten to run Smatch (it's really amazing tool). I also tested the patched module by running kselftest (gpio-aggregator.sh), with the addition of a new test case for the issue that your first patch uncovered. I'll submit a patch to add it to selftest later.
Thanks,
Koichiro Den
Quoted 4 lines
Signature · 2 lines
-- 2.47.2
Quoted 13 lines · Koichiro Den
Quoted 12 lines · Dan Carpenter
Fix some static checker warnings from Smatch:
https://github.com/error27/smatchDan Carpenter (5):
gpio: aggregator: fix "_sysfs" prefix check in
gpio_aggregator_make_group()
gpio: aggregator: Fixgpio_aggregator_line_alloc()checking
gpio: aggregator: Return an error if there are no GPIOs in
gpio_aggregator_parse()
gpio: aggregator: Fix error code ingpio_aggregator_activate()
gpio: aggregator: Fix leak ingpio_aggregator_parse()
Quoted 5 lines
Quoted 2 lines
drivers/gpio/gpio-aggregator.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)Thank you very much for spotting these issues. I doubt myself for having overlooked these.
Heh. Don't beat yourself up. Humans can never compete with a computer at being nit-picky.
regards,
dan carpenter
Re: [PATCH 1/5] gpio: aggregator: fix "_sysfs" prefix check in gpio_aggregator_make_group()
In reply to Dan CarpenterHi Dan,
Quoted 5 lines · Dan Carpenter
This code is intended to reject strings that start with "
_sysfs" but thestrcmp()limit is wrong so checks the whole string instead of the prefix.Fixes 83c8e3df642f ("gpio: aggregator: expose aggregator created via legacy sysfs to configfs")Signed-off-by Dan Carpenter <[email protected]>
drivers/gpio/gpio-aggregator.c gpio_aggregator_make_group(struct config_group *group, const char *name) · line 1019
Quoted 8 lines
drivers/gpio/gpio-aggregator.c +1
-1@@ -1016,7 +1016,7 @@ gpio_aggregator_make_group(struct config_group *group, const char *name)* for devices create via legacy sysfs interface. */ if (strncmp (name,AGGREGATOR_LEGACY_PREFIX , -sizeof (AGGREGATOR_LEGACY_PREFIX )) ==0 ) +sizeof (AGGREGATOR_LEGACY_PREFIX ) -1 ) ==0 )
Or perhaps just strlen()? The compiler should optimize that to a constant, too.
drivers/gpio/gpio-aggregator.c gpio_aggregator_make_group(struct config_group *group, const char *name) · line 1022
Quoted 3 lines
drivers/gpio/gpio-aggregator.c +0
-0return ERR_PTR (-EINVAL );/* arg space is unneeded */
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
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
Bartosz Golaszewski
AppliedQuoted 12 lines · Dan Carpenter
Fix some static checker warnings from Smatch:
https://github.com/error27/smatchDan Carpenter (5):
gpio: aggregator: fix "_sysfs" prefix check in
gpio_aggregator_make_group()
gpio: aggregator: Fixgpio_aggregator_line_alloc()checking
gpio: aggregator: Return an error if there are no GPIOs in
gpio_aggregator_parse()
gpio: aggregator: Fix error code ingpio_aggregator_activate()
gpio: aggregator: Fix leak ingpio_aggregator_parse()
Quoted 1 line
[...]
Applied, thanks!
[1/5] gpio: aggregator: fix "_sysfs" prefix check in gpio_aggregator_make_group()
https://git.kernel.org/brgl/linux/c/eebfcb98cdc0228f5e1b7407f9db1c602bd8e545 [2/5] gpio: aggregator: Fix gpio_aggregator_line_alloc() checking https://git.kernel.org/brgl/linux/c/2e8636ca340002f3ac31383622911a1aa75fb086 [3/5] gpio: aggregator: Return an error if there are no GPIOs in gpio_aggregator_parse() https://git.kernel.org/brgl/linux/c/db1baf69e563fc222a75c0add5c76f437c717ac0 [4/5] gpio: aggregator: Fix error code in gpio_aggregator_activate() https://git.kernel.org/brgl/linux/c/05b43de95add3d787a7a88378086bf01c10b3f40 [5/5] gpio: aggregator: Fix leak in gpio_aggregator_parse() https://git.kernel.org/brgl/linux/c/d945ff52642d98eb6fa191f88a9cfde729129395
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>
Re: [PATCH 1/5] gpio: aggregator: fix "_sysfs" prefix check in gpio_aggregator_make_group()
In reply to Dan CarpenterQuoted 2 lines · Dan Carpenter
This code is intended to reject strings that start with "
_sysfs" but thestrcmp()limit is wrong so checks the whole string instead of the prefix.
...
drivers/gpio/gpio-aggregator.c gpio_aggregator_make_group(struct config_group *group, const char *name) · line 1020
Quoted 4 lines
drivers/gpio/gpio-aggregator.c +1
-1if (strncmp (name,AGGREGATOR_LEGACY_PREFIX , -sizeof (AGGREGATOR_LEGACY_PREFIX )) ==0 ) +sizeof (AGGREGATOR_LEGACY_PREFIX ) -1 ) ==0 )return ERR_PTR (-EINVAL );
Wouldn't be better to use strstarts() / str_has_prefix()?
Signature · 2 lines
With Best Regards, Andy Shevchenko