mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] gpiolib: initialize return value in gpiochip_set_multiple()
@ 2026-06-20 15:53 Ruoyu Wang
  2026-06-20 16:45 ` Uwe Kleine-König
  2026-06-22  8:14 ` Bartosz Golaszewski
  0 siblings, 2 replies; 4+ messages in thread
From: Ruoyu Wang @ 2026-06-20 15:53 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Uwe Kleine-König
  Cc: linux-gpio, linux-kernel, 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()")
Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
 drivers/gpio/gpiolib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 1e6dce430dca..cd2a619da456 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -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);
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] gpiolib: initialize return value in gpiochip_set_multiple()
  2026-06-20 15:53 [PATCH] gpiolib: initialize return value in gpiochip_set_multiple() Ruoyu Wang
@ 2026-06-20 16:45 ` Uwe Kleine-König
       [not found]   ` <CAK_7xqx_kJneD2=nDPYbefX_Ov0tf5sOwp5BLLLr7VzP9mtC_w@mail.gmail.com>
  2026-06-22  8:14 ` Bartosz Golaszewski
  1 sibling, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2026-06-20 16:45 UTC (permalink / raw)
  To: Ruoyu Wang; +Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1312 bytes --]

On Sat, Jun 20, 2026 at 11:53:19PM +0800, Ruoyu Wang wrote:
> 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()")
> Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
> ---
>  drivers/gpio/gpiolib.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 1e6dce430dca..cd2a619da456 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -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.

Acked-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>

Did you find that by manual code inspection, or using a tool?

Best regards
Uwe
>  

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] gpiolib: initialize return value in gpiochip_set_multiple()
  2026-06-20 15:53 [PATCH] gpiolib: initialize return value in gpiochip_set_multiple() Ruoyu Wang
  2026-06-20 16:45 ` Uwe Kleine-König
@ 2026-06-22  8:14 ` Bartosz Golaszewski
  1 sibling, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2026-06-22  8:14 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Uwe Kleine-König, Ruoyu Wang
  Cc: Bartosz Golaszewski, linux-gpio, linux-kernel


On Sat, 20 Jun 2026 23:53:19 +0800, Ruoyu Wang wrote:
> 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,
-- 
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] gpiolib: initialize return value in gpiochip_set_multiple()
       [not found]   ` <CAK_7xqx_kJneD2=nDPYbefX_Ov0tf5sOwp5BLLLr7VzP9mtC_w@mail.gmail.com>
@ 2026-06-22  9:35     ` Uwe Kleine-König
  0 siblings, 0 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2026-06-22  9:35 UTC (permalink / raw)
  To: Ruoyu Wang; +Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 357 bytes --]

Hello,

On Sun, Jun 21, 2026 at 11:08:09PM +0800, Ruoyu Wang wrote:
> 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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-06-22  9:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-20 15:53 [PATCH] gpiolib: initialize return value in gpiochip_set_multiple() Ruoyu Wang
2026-06-20 16:45 ` Uwe Kleine-König
     [not found]   ` <CAK_7xqx_kJneD2=nDPYbefX_Ov0tf5sOwp5BLLLr7VzP9mtC_w@mail.gmail.com>
2026-06-22  9:35     ` Uwe Kleine-König
2026-06-22  8:14 ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox