* [PATCH 1/5] gpio: aggregator: fix "_sysfs" prefix check in gpio_aggregator_make_group()
2025-04-12 10:14 [PATCH 0/5] gpio: aggregator: Fix Smatch warnings Dan Carpenter
@ 2025-04-12 10:15 ` Dan Carpenter
2025-04-14 7:52 ` Geert Uytterhoeven
2026-01-21 14:04 ` Andy Shevchenko
2025-04-12 10:15 ` [PATCH 2/5] gpio: aggregator: Fix gpio_aggregator_line_alloc() checking Dan Carpenter
` (5 subsequent siblings)
6 siblings, 2 replies; 11+ messages in thread
From: Dan Carpenter @ 2025-04-12 10:15 UTC (permalink / raw)
To: Koichiro Den
Cc: Geert Uytterhoeven, Linus Walleij, Bartosz Golaszewski,
linux-gpio, linux-kernel
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.
Fixes: 83c8e3df642f ("gpio: aggregator: expose aggregator created via legacy sysfs to configfs")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
drivers/gpio/gpio-aggregator.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c
index dde969f29ee2..b4c9e373a6ec 100644
--- a/drivers/gpio/gpio-aggregator.c
+++ b/drivers/gpio/gpio-aggregator.c
@@ -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 */
--
2.47.2
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 1/5] gpio: aggregator: fix "_sysfs" prefix check in gpio_aggregator_make_group()
2025-04-12 10:15 ` [PATCH 1/5] gpio: aggregator: fix "_sysfs" prefix check in gpio_aggregator_make_group() Dan Carpenter
@ 2025-04-14 7:52 ` Geert Uytterhoeven
2026-01-21 14:04 ` Andy Shevchenko
1 sibling, 0 replies; 11+ messages in thread
From: Geert Uytterhoeven @ 2025-04-14 7:52 UTC (permalink / raw)
To: Dan Carpenter
Cc: Koichiro Den, Geert Uytterhoeven, Linus Walleij,
Bartosz Golaszewski, linux-gpio, linux-kernel
Hi Dan,
On Sat, 12 Apr 2025 at 12:15, Dan Carpenter <dan.carpenter@linaro.org> wrote:
> 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.
>
> Fixes: 83c8e3df642f ("gpio: aggregator: expose aggregator created via legacy sysfs to configfs")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
> --- a/drivers/gpio/gpio-aggregator.c
> +++ b/drivers/gpio/gpio-aggregator.c
> @@ -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.
> return ERR_PTR(-EINVAL);
>
> /* arg space is unneeded */
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
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
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH 1/5] gpio: aggregator: fix "_sysfs" prefix check in gpio_aggregator_make_group()
2025-04-12 10:15 ` [PATCH 1/5] gpio: aggregator: fix "_sysfs" prefix check in gpio_aggregator_make_group() Dan Carpenter
2025-04-14 7:52 ` Geert Uytterhoeven
@ 2026-01-21 14:04 ` Andy Shevchenko
1 sibling, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2026-01-21 14:04 UTC (permalink / raw)
To: Dan Carpenter
Cc: Koichiro Den, Geert Uytterhoeven, Linus Walleij,
Bartosz Golaszewski, linux-gpio, linux-kernel
On Sat, Apr 12, 2025 at 01:15:00PM +0300, Dan Carpenter wrote:
> 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.
...
> if (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()?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 2/5] gpio: aggregator: Fix gpio_aggregator_line_alloc() checking
2025-04-12 10:14 [PATCH 0/5] gpio: aggregator: Fix Smatch warnings Dan Carpenter
2025-04-12 10:15 ` [PATCH 1/5] gpio: aggregator: fix "_sysfs" prefix check in gpio_aggregator_make_group() Dan Carpenter
@ 2025-04-12 10:15 ` Dan Carpenter
2025-04-12 10:15 ` [PATCH 3/5] gpio: aggregator: Return an error if there are no GPIOs in gpio_aggregator_parse() Dan Carpenter
` (4 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Dan Carpenter @ 2025-04-12 10:15 UTC (permalink / raw)
To: Koichiro Den
Cc: Geert Uytterhoeven, Linus Walleij, Bartosz Golaszewski,
linux-gpio, linux-kernel
The gpio_aggregator_line_alloc() function returns error pointers, but
the callers check for NULL. Update the error checking in the callers.
Fixes: 83c8e3df642f ("gpio: aggregator: expose aggregator created via legacy sysfs to configfs")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
drivers/gpio/gpio-aggregator.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c
index b4c9e373a6ec..e1b2efc0df99 100644
--- a/drivers/gpio/gpio-aggregator.c
+++ b/drivers/gpio/gpio-aggregator.c
@@ -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,
--
2.47.2
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 3/5] gpio: aggregator: Return an error if there are no GPIOs in gpio_aggregator_parse()
2025-04-12 10:14 [PATCH 0/5] gpio: aggregator: Fix Smatch warnings Dan Carpenter
2025-04-12 10:15 ` [PATCH 1/5] gpio: aggregator: fix "_sysfs" prefix check in gpio_aggregator_make_group() Dan Carpenter
2025-04-12 10:15 ` [PATCH 2/5] gpio: aggregator: Fix gpio_aggregator_line_alloc() checking Dan Carpenter
@ 2025-04-12 10:15 ` Dan Carpenter
2025-04-12 10:15 ` [PATCH 4/5] gpio: aggregator: Fix error code in gpio_aggregator_activate() Dan Carpenter
` (3 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Dan Carpenter @ 2025-04-12 10:15 UTC (permalink / raw)
To: Koichiro Den
Cc: Geert Uytterhoeven, Linus Walleij, Bartosz Golaszewski,
linux-gpio, linux-kernel
The 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.
Fixes: 83c8e3df642f ("gpio: aggregator: expose aggregator created via legacy sysfs to configfs")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
drivers/gpio/gpio-aggregator.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c
index e1b2efc0df99..62bb50af7cda 100644
--- a/drivers/gpio/gpio-aggregator.c
+++ b/drivers/gpio/gpio-aggregator.c
@@ -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;
}
--
2.47.2
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 4/5] gpio: aggregator: Fix error code in gpio_aggregator_activate()
2025-04-12 10:14 [PATCH 0/5] gpio: aggregator: Fix Smatch warnings Dan Carpenter
` (2 preceding siblings ...)
2025-04-12 10:15 ` [PATCH 3/5] gpio: aggregator: Return an error if there are no GPIOs in gpio_aggregator_parse() Dan Carpenter
@ 2025-04-12 10:15 ` Dan Carpenter
2025-04-12 10:15 ` [PATCH 5/5] gpio: aggregator: Fix leak in gpio_aggregator_parse() Dan Carpenter
` (2 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Dan Carpenter @ 2025-04-12 10:15 UTC (permalink / raw)
To: Koichiro Den
Cc: Geert Uytterhoeven, Linus Walleij, Bartosz Golaszewski,
linux-gpio, linux-kernel
Propagate the error code if gpio_aggregator_make_device_sw_node() fails.
Don't return success.
Fixes: 86f162e73d2d ("gpio: aggregator: introduce basic configfs interface")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
drivers/gpio/gpio-aggregator.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c
index 62bb50af7cda..071d76dbfcec 100644
--- a/drivers/gpio/gpio-aggregator.c
+++ b/drivers/gpio/gpio-aggregator.c
@@ -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;
--
2.47.2
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 5/5] gpio: aggregator: Fix leak in gpio_aggregator_parse()
2025-04-12 10:14 [PATCH 0/5] gpio: aggregator: Fix Smatch warnings Dan Carpenter
` (3 preceding siblings ...)
2025-04-12 10:15 ` [PATCH 4/5] gpio: aggregator: Fix error code in gpio_aggregator_activate() Dan Carpenter
@ 2025-04-12 10:15 ` Dan Carpenter
2025-04-12 14:45 ` [PATCH 0/5] gpio: aggregator: Fix Smatch warnings Koichiro Den
2025-04-14 20:26 ` Bartosz Golaszewski
6 siblings, 0 replies; 11+ messages in thread
From: Dan Carpenter @ 2025-04-12 10:15 UTC (permalink / raw)
To: Koichiro Den
Cc: Geert Uytterhoeven, Linus Walleij, Bartosz Golaszewski,
linux-gpio, linux-kernel
Call gpio_aggregator_free_lines() before returning on this error path.
Fixes: 83c8e3df642f ("gpio: aggregator: expose aggregator created via legacy sysfs to configfs")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
drivers/gpio/gpio-aggregator.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c
index 071d76dbfcec..6f941db02c04 100644
--- a/drivers/gpio/gpio-aggregator.c
+++ b/drivers/gpio/gpio-aggregator.c
@@ -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) {
--
2.47.2
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 0/5] gpio: aggregator: Fix Smatch warnings
2025-04-12 10:14 [PATCH 0/5] gpio: aggregator: Fix Smatch warnings Dan Carpenter
` (4 preceding siblings ...)
2025-04-12 10:15 ` [PATCH 5/5] gpio: aggregator: Fix leak in gpio_aggregator_parse() Dan Carpenter
@ 2025-04-12 14:45 ` Koichiro Den
2025-04-12 16:43 ` Dan Carpenter
2025-04-14 20:26 ` Bartosz Golaszewski
6 siblings, 1 reply; 11+ messages in thread
From: Koichiro Den @ 2025-04-12 14:45 UTC (permalink / raw)
To: Dan Carpenter
Cc: Bartosz Golaszewski, Geert Uytterhoeven, Linus Walleij,
linux-gpio, linux-kernel
On Sat, Apr 12, 2025 at 01:14:53PM GMT, Dan Carpenter wrote:
> 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(-)
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.
Acked-by: Koichiro Den <koichiro.den@canonical.com>
Thanks,
Koichiro Den
>
> --
> 2.47.2
>
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH 0/5] gpio: aggregator: Fix Smatch warnings
2025-04-12 14:45 ` [PATCH 0/5] gpio: aggregator: Fix Smatch warnings Koichiro Den
@ 2025-04-12 16:43 ` Dan Carpenter
0 siblings, 0 replies; 11+ messages in thread
From: Dan Carpenter @ 2025-04-12 16:43 UTC (permalink / raw)
To: Koichiro Den
Cc: Bartosz Golaszewski, Geert Uytterhoeven, Linus Walleij,
linux-gpio, linux-kernel
On Sat, Apr 12, 2025 at 11:45:08PM +0900, Koichiro Den wrote:
> On Sat, Apr 12, 2025 at 01:14:53PM GMT, Dan Carpenter wrote:
> > 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(-)
>
> 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
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/5] gpio: aggregator: Fix Smatch warnings
2025-04-12 10:14 [PATCH 0/5] gpio: aggregator: Fix Smatch warnings Dan Carpenter
` (5 preceding siblings ...)
2025-04-12 14:45 ` [PATCH 0/5] gpio: aggregator: Fix Smatch warnings Koichiro Den
@ 2025-04-14 20:26 ` Bartosz Golaszewski
6 siblings, 0 replies; 11+ messages in thread
From: Bartosz Golaszewski @ 2025-04-14 20:26 UTC (permalink / raw)
To: Koichiro Den, Dan Carpenter
Cc: Bartosz Golaszewski, Geert Uytterhoeven, Linus Walleij,
linux-gpio, linux-kernel
On Sat, 12 Apr 2025 13:14:53 +0300, Dan Carpenter wrote:
> 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()
>
> [...]
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,
--
Bartosz Golaszewski <brgl@bgdev.pl>
^ permalink raw reply [flat|nested] 11+ messages in thread