Skip to contentSkip to conversation

gpiolib: initialize return value in gpiochip_set_multiple()

PATCH Applied Ruoyu Wang 3 participants 4 messages Jun 20 – Jun 22 1 message not in the archive GPIO

lore
Share & tools
lore

Ruoyu Wang

author
#0 lore raw

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.

Fixes 9b407312755f ("gpiolib: rework the wrapper around gpio_chip::set_multiple()")
---
 drivers/gpio/gpiolib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib.c +1 -1
index 1e6dce430dca..cd2a619da456 100644
@@ -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);
 
Acked-by on v1 1/1
#1 lore raw
Quoted 18 lines · Ruoyu Wang

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.

Fixes 9b407312755f ("gpiolib: rework the wrapper around gpio_chip::set_multiple()")
---
 drivers/gpio/gpiolib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib.c +0 -0
index 1e6dce430dca..cd2a619da456 100644

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

#3 lore raw

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

#4 lore raw
In reply to Ruoyu Wang
Quoted 8 lines · Ruoyu Wang

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.

[...]

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]>