All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: cdev: avoid uninitialized variable dereference
@ 2024-02-16 12:59 Arnd Bergmann
  2024-02-16 13:19 ` Bartosz Golaszewski
  0 siblings, 1 reply; 6+ messages in thread
From: Arnd Bergmann @ 2024-02-16 12:59 UTC (permalink / raw)
  To: Bartosz Golaszewski, Linus Walleij, Paul E. McKenney
  Cc: Arnd Bergmann, Kent Gibson, Andy Shevchenko, linux-gpio, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

The 'gc' variable is never set before it gets printed:

drivers/gpio/gpiolib-cdev.c:2802:11: error: variable 'gc' is uninitialized when used here [-Werror,-Wuninitialized]
 2802 |         chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id);
      |                  ^~
drivers/gpio/gpiolib.h:277:11: note: expanded from macro 'chip_dbg'
  277 |         dev_dbg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__)
      |                  ^~

Use dev_dbg() directly.

Fixes: 8574b5b47610 ("gpio: cdev: use correct pointer accessors with SRCU")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/gpio/gpiolib-cdev.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index 85037fa4925e..d6e8d2b7ac8f 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -2783,7 +2783,6 @@ static const struct file_operations gpio_fileops = {
 
 int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt)
 {
-	struct gpio_chip *gc;
 	int ret;
 
 	cdev_init(&gdev->chrdev, &gpio_fileops);
@@ -2799,7 +2798,7 @@ int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt)
 	if (!rcu_access_pointer(gdev->chip))
 		return -ENODEV;
 
-	chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id);
+	dev_dbg(&gdev->dev, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id);
 
 	return 0;
 }
-- 
2.39.2


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

* Re: [PATCH] gpio: cdev: avoid uninitialized variable dereference
  2024-02-16 12:59 [PATCH] gpio: cdev: avoid uninitialized variable dereference Arnd Bergmann
@ 2024-02-16 13:19 ` Bartosz Golaszewski
  2024-02-16 14:04   ` Arnd Bergmann
  0 siblings, 1 reply; 6+ messages in thread
From: Bartosz Golaszewski @ 2024-02-16 13:19 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Linus Walleij, Paul E. McKenney, Arnd Bergmann, Kent Gibson,
	Andy Shevchenko, linux-gpio, linux-kernel

On Fri, Feb 16, 2024 at 2:00 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> The 'gc' variable is never set before it gets printed:
>
> drivers/gpio/gpiolib-cdev.c:2802:11: error: variable 'gc' is uninitialized when used here [-Werror,-Wuninitialized]
>  2802 |         chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id);
>       |                  ^~
> drivers/gpio/gpiolib.h:277:11: note: expanded from macro 'chip_dbg'
>   277 |         dev_dbg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__)
>       |                  ^~
>
> Use dev_dbg() directly.
>
> Fixes: 8574b5b47610 ("gpio: cdev: use correct pointer accessors with SRCU")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---

Hi Arnd,

I seem to have beat you to it[1] and my patch doesn't change the log
message so I'll apply it instead of this one.

Thanks,
Bartosz

[1] https://lore.kernel.org/linux-gpio/1542ef65-508b-45be-ad5c-63ad124cb1a2@samsung.com/T/#t

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

* Re: [PATCH] gpio: cdev: avoid uninitialized variable dereference
  2024-02-16 13:19 ` Bartosz Golaszewski
@ 2024-02-16 14:04   ` Arnd Bergmann
  2024-02-16 15:51     ` Paul E. McKenney
  0 siblings, 1 reply; 6+ messages in thread
From: Arnd Bergmann @ 2024-02-16 14:04 UTC (permalink / raw)
  To: Bartosz Golaszewski, Arnd Bergmann
  Cc: Linus Walleij, Paul E. McKenney, Kent Gibson, Andy Shevchenko,
	open list:GPIO SUBSYSTEM, linux-kernel

On Fri, Feb 16, 2024, at 14:19, Bartosz Golaszewski wrote:
> On Fri, Feb 16, 2024 at 2:00 PM Arnd Bergmann <arnd@kernel.org> wrote:
>>
>> From: Arnd Bergmann <arnd@arndb.de>
>>
>> The 'gc' variable is never set before it gets printed:
>>
>> drivers/gpio/gpiolib-cdev.c:2802:11: error: variable 'gc' is uninitialized when used here [-Werror,-Wuninitialized]
>>  2802 |         chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id);
>>       |                  ^~
>> drivers/gpio/gpiolib.h:277:11: note: expanded from macro 'chip_dbg'
>>   277 |         dev_dbg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__)
>>       |                  ^~
>>
>> Use dev_dbg() directly.
>>
>> Fixes: 8574b5b47610 ("gpio: cdev: use correct pointer accessors with SRCU")
>> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>> ---
>
> I seem to have beat you to it[1] and my patch doesn't change the log
> message so I'll apply it instead of this one.

Ok, thanks. I thought about doing this, but could not
figure out which of the RCU primitives to use.

     Arnd

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

* Re: [PATCH] gpio: cdev: avoid uninitialized variable dereference
  2024-02-16 14:04   ` Arnd Bergmann
@ 2024-02-16 15:51     ` Paul E. McKenney
  2024-02-16 16:17       ` Arnd Bergmann
  0 siblings, 1 reply; 6+ messages in thread
From: Paul E. McKenney @ 2024-02-16 15:51 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Bartosz Golaszewski, Arnd Bergmann, Linus Walleij, Kent Gibson,
	Andy Shevchenko, open list:GPIO SUBSYSTEM, linux-kernel

On Fri, Feb 16, 2024 at 03:04:14PM +0100, Arnd Bergmann wrote:
> On Fri, Feb 16, 2024, at 14:19, Bartosz Golaszewski wrote:
> > On Fri, Feb 16, 2024 at 2:00 PM Arnd Bergmann <arnd@kernel.org> wrote:
> >>
> >> From: Arnd Bergmann <arnd@arndb.de>
> >>
> >> The 'gc' variable is never set before it gets printed:
> >>
> >> drivers/gpio/gpiolib-cdev.c:2802:11: error: variable 'gc' is uninitialized when used here [-Werror,-Wuninitialized]
> >>  2802 |         chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id);
> >>       |                  ^~
> >> drivers/gpio/gpiolib.h:277:11: note: expanded from macro 'chip_dbg'
> >>   277 |         dev_dbg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__)
> >>       |                  ^~
> >>
> >> Use dev_dbg() directly.
> >>
> >> Fixes: 8574b5b47610 ("gpio: cdev: use correct pointer accessors with SRCU")
> >> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> >> ---
> >
> > I seem to have beat you to it[1] and my patch doesn't change the log
> > message so I'll apply it instead of this one.
> 
> Ok, thanks. I thought about doing this, but could not
> figure out which of the RCU primitives to use.

I will count that as a bug against RCU's documentation, but I am not
sure how to fix it.  Thoughts?

							Thanx, Paul

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

* Re: [PATCH] gpio: cdev: avoid uninitialized variable dereference
  2024-02-16 15:51     ` Paul E. McKenney
@ 2024-02-16 16:17       ` Arnd Bergmann
  2024-02-16 16:50         ` Paul E. McKenney
  0 siblings, 1 reply; 6+ messages in thread
From: Arnd Bergmann @ 2024-02-16 16:17 UTC (permalink / raw)
  To: Paul E. McKenney
  Cc: Bartosz Golaszewski, Arnd Bergmann, Linus Walleij, Kent Gibson,
	Andy Shevchenko, open list:GPIO SUBSYSTEM, linux-kernel

On Fri, Feb 16, 2024, at 16:51, Paul E. McKenney wrote:
> On Fri, Feb 16, 2024 at 03:04:14PM +0100, Arnd Bergmann wrote:
>> On Fri, Feb 16, 2024, at 14:19, Bartosz Golaszewski wrote:
>> > On Fri, Feb 16, 2024 at 2:00 PM Arnd Bergmann <arnd@kernel.org> wrote:
>> >>
>> >> From: Arnd Bergmann <arnd@arndb.de>
>> >>
>> >> The 'gc' variable is never set before it gets printed:
>> >>
>> >> drivers/gpio/gpiolib-cdev.c:2802:11: error: variable 'gc' is uninitialized when used here [-Werror,-Wuninitialized]
>> >>  2802 |         chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id);
>> >>       |                  ^~
>> >> drivers/gpio/gpiolib.h:277:11: note: expanded from macro 'chip_dbg'
>> >>   277 |         dev_dbg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__)
>> >>       |                  ^~
>> >>
>> >> Use dev_dbg() directly.
>> >>
>> >> Fixes: 8574b5b47610 ("gpio: cdev: use correct pointer accessors with SRCU")
>> >> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>> >> ---
>> >
>> > I seem to have beat you to it[1] and my patch doesn't change the log
>> > message so I'll apply it instead of this one.
>> 
>> Ok, thanks. I thought about doing this, but could not
>> figure out which of the RCU primitives to use.
>
> I will count that as a bug against RCU's documentation, but I am not
> sure how to fix it.  Thoughts?

I didn't really try at all, I just figured I could avoid
thinking about it by using the device pointer at hand.

I'm sure the docs would have told me if I had bothered to look.

     Arnd

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

* Re: [PATCH] gpio: cdev: avoid uninitialized variable dereference
  2024-02-16 16:17       ` Arnd Bergmann
@ 2024-02-16 16:50         ` Paul E. McKenney
  0 siblings, 0 replies; 6+ messages in thread
From: Paul E. McKenney @ 2024-02-16 16:50 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Bartosz Golaszewski, Arnd Bergmann, Linus Walleij, Kent Gibson,
	Andy Shevchenko, open list:GPIO SUBSYSTEM, linux-kernel

On Fri, Feb 16, 2024 at 05:17:06PM +0100, Arnd Bergmann wrote:
> On Fri, Feb 16, 2024, at 16:51, Paul E. McKenney wrote:
> > On Fri, Feb 16, 2024 at 03:04:14PM +0100, Arnd Bergmann wrote:
> >> On Fri, Feb 16, 2024, at 14:19, Bartosz Golaszewski wrote:
> >> > On Fri, Feb 16, 2024 at 2:00 PM Arnd Bergmann <arnd@kernel.org> wrote:
> >> >>
> >> >> From: Arnd Bergmann <arnd@arndb.de>
> >> >>
> >> >> The 'gc' variable is never set before it gets printed:
> >> >>
> >> >> drivers/gpio/gpiolib-cdev.c:2802:11: error: variable 'gc' is uninitialized when used here [-Werror,-Wuninitialized]
> >> >>  2802 |         chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id);
> >> >>       |                  ^~
> >> >> drivers/gpio/gpiolib.h:277:11: note: expanded from macro 'chip_dbg'
> >> >>   277 |         dev_dbg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__)
> >> >>       |                  ^~
> >> >>
> >> >> Use dev_dbg() directly.
> >> >>
> >> >> Fixes: 8574b5b47610 ("gpio: cdev: use correct pointer accessors with SRCU")
> >> >> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> >> >> ---
> >> >
> >> > I seem to have beat you to it[1] and my patch doesn't change the log
> >> > message so I'll apply it instead of this one.
> >> 
> >> Ok, thanks. I thought about doing this, but could not
> >> figure out which of the RCU primitives to use.
> >
> > I will count that as a bug against RCU's documentation, but I am not
> > sure how to fix it.  Thoughts?
> 
> I didn't really try at all, I just figured I could avoid
> thinking about it by using the device pointer at hand.
> 
> I'm sure the docs would have told me if I had bothered to look.

OK, a low-priority bug against RCU's documentation, then.  ;-)

							Thanx, paul

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

end of thread, other threads:[~2024-02-16 16:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-16 12:59 [PATCH] gpio: cdev: avoid uninitialized variable dereference Arnd Bergmann
2024-02-16 13:19 ` Bartosz Golaszewski
2024-02-16 14:04   ` Arnd Bergmann
2024-02-16 15:51     ` Paul E. McKenney
2024-02-16 16:17       ` Arnd Bergmann
2024-02-16 16:50         ` Paul E. McKenney

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.