Skip to contentSkip to conversation

gpiolib: of: reset name variable in of_gpiochip_add_hog

PATCH In review [email protected] 3 participants 3 messages Jul 28, 2020 – Aug 5, 2020 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpiolib: of: reset name variable in of_gpiochip_add_hog

From: Tom Rix <[email protected]>

Clang static analysis reports this error

gpiolib-of.c:664:9: warning: 2nd function call argument
is an uninitialized value [core.CallAndMessage]

        ret = gpiod_hog(desc, name, lflags, dflags);

name is sometimes set by of_parse_own_gpio
name is always used by gpiod_hog

So it is necessary to reset name so an old value is not mistakenly used by gpiod_hog.

Fixes bc21077e084b ("gpio: of: Extract of_gpiochip_add_hog()")
---
 drivers/gpio/gpiolib-of.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpio/gpiolib-of.c +1 -0
index bd31dd3b6a75..277ada41d04a 100644
@@ -657,6 +657,7 @@ static int of_gpiochip_add_hog(struct gpio_chip *chip, struct device_node *hog)
 	int ret;
 
 	for (i = 0;; i++) {
+		name = NULL;
 		desc = of_parse_own_gpio(hog, chip, i, &name, &lflags, &dflags);
 		if (IS_ERR(desc))
 			break;
Signature · 1 line
2.18.1
#1 lore raw
Quoted 5 lines · On Tue, Jul 28, 2020 at 4:44 PM <[email protected]> wrote:

From: Tom Rix <[email protected]>

Clang static analysis reports this error

Quoted 7 lines

gpiolib-of.c:664:9: warning: 2nd function call argument
is an uninitialized value [core.CallAndMessage]

        ret = gpiod_hog(desc, name, lflags, dflags);

name is sometimes set by of_parse_own_gpio
name is always used by gpiod_hog

It's not clear if it's the output of the analyser.
If so, try to file a bug and fix there how it prints out functions, should be func().
Otherwise fix in the commit message.

Quoted 1 line

So it is necessary to reset name so an old value is

the name

Quoted 1 line

not mistakenly used by gpiod_hog.

gpiod_hog()

Quoted 3 lines
Fixes bc21077e084b ("gpio: of: Extract of_gpiochip_add_hog()")

Should be no blank line in between.

Quoted 19 lines
---
 drivers/gpio/gpiolib-of.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpio/gpiolib-of.c +1 -1
index bd31dd3b6a75..277ada41d04a 100644
@@ -657,6 +657,7 @@ static int of_gpiochip_add_hog(struct gpio_chip *chip, struct device_node *hog)
        int ret;
 
        for (i = 0;; i++) {
+               name = NULL;
                desc = of_parse_own_gpio(hog, chip, i, &name, &lflags, &dflags);
                if (IS_ERR(desc))
                        break;
--

2.18.1

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
In reply to [email protected]

Hi Tom,

Thanks for your patch!

Quoted 10 lines · On Tue, Jul 28, 2020 at 3:42 PM <[email protected]> wrote:

From: Tom Rix <[email protected]>

Clang static analysis reports this error

gpiolib-of.c:664:9: warning: 2nd function call argument
is an uninitialized value [core.CallAndMessage]

        ret = gpiod_hog(desc, name, lflags, dflags);

name is sometimes set by of_parse_own_gpio
name is always used by gpiod_hog

This is a false-positive: gpiod_hog() is only called if of_parse_own_gpio() returned success, in which case it has filled in the name output parameter.

Quoted 2 lines

So it is necessary to reset name so an old value is not mistakenly used by gpiod_hog.

Hence this is not needed.

Quoted 1 line
Fixes bc21077e084b ("gpio: of: Extract of_gpiochip_add_hog()")

This is not the commit that introduced the "bug".

drivers/gpio/gpiolib-of.c static int of_gpiochip_add_hog(struct gpio_chip *chip, struct device_node *hog) · line 663

Quoted 12 lines
drivers/gpio/gpiolib-of.c +1 -0
@@ -657,6 +657,7 @@ static int of_gpiochip_add_hog(struct gpio_chip *chip, struct device_node *hog)
        int ret;
 
        for (i = 0;; i++) {
+               name = NULL;
                desc = of_parse_own_gpio(hog, chip, i, &name, &lflags, &dflags);
                if (IS_ERR(desc))
                        break;

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