gpiolib: initialize return value in gpiochip_set_multiple()
PATCH 1/1 gpiolib: initialize return value in gpiochip_set_multiple()
gpiochip_set_multiple() falls back to setting lines one by one when the chip does not provide set_multiple(). If the fallback path receives an empty mask, the loop is skipped and ret is returned without being initialized.
Initialize ret to 0 so an empty mask is treated as a successful no-op.
--- drivers/gpio/gpiolib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib.c +1 -1
@@ -3778,7 +3778,7 @@ static int gpiochip_set_multiple(struct gpio_chip *gc, unsigned long *mask, unsigned long *bits) { unsigned int i; -int ret; +int ret =0 ;lockdep_assert_held (&gc->gpiodev->srcu);
Quoted 18 lines · Ruoyu Wang
gpiochip_set_multiple()falls back to setting lines one by one when the chip does not provideset_multiple(). If the fallback path receives an empty mask, the loop is skipped and ret is returned without being initialized.Initialize ret to 0 so an empty mask is treated as a successful no-op.
Fixes 9b407312755f ("gpiolib: rework the wrapper around gpio_chip::set_multiple()")Signed-off-by Ruoyu Wang <[email protected]>--- drivers/gpio/gpiolib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpio/gpiolib.c +0
-0
drivers/gpio/gpiolib.c static int gpiochip_set_multiple(struct gpio_chip *gc, · line 3783
Quoted 7 lines
drivers/gpio/gpiolib.c +1
-1@@ -3778,7 +3778,7 @@ static int gpiochip_set_multiple(struct gpio_chip *gc, unsigned long *mask, unsigned long *bits) { unsigned int i; -int ret; +int ret =0 ;lockdep_assert_held (&gc->gpiodev->srcu);
While I think it's questionable to call gpiochip_set_multiple with an empty mask, returning a random value isn't the right reaction.
Did you find that by manual code inspection, or using a tool?
Best regards
Uwe
Quoted 1 line
A message that is not in the archive (sent off-list or not yet received): CAK_7xqx_kJneD2=nDPYbefX_Ov0tf5sOwp5BLLLr7VzP9mtC_w@mail.gmail.com
Hello,
Quoted 3 lines · Ruoyu Wang
This was found by a local static analysis checker. The checker flagged the uninitialized return value candidate, and I then confirmed by manual inspection that the fallback loop can be skipped for an empty mask.
That might be worth to point out in the commit log.
Best regards
Uwe
Bartosz Golaszewski
AppliedQuoted 8 lines · Ruoyu Wang
gpiochip_set_multiple()falls back to setting lines one by one when the chip does not provideset_multiple(). If the fallback path receives an empty mask, the loop is skipped and ret is returned without being initialized.Initialize ret to 0 so an empty mask is treated as a successful no-op.
[...]
Applied, thanks!
[1/1] gpiolib: initialize return value in gpiochip_set_multiple()
https://git.kernel.org/brgl/c/99dfa46baba29513d1094c8f30bc86c6ef88543a
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>