diff mbox series

[v8,01/20] gpiolib: cdev: desc_to_lineinfo should set info offset

Message ID 20200909102640.1657622-2-warthog618@gmail.com
State Superseded
Headers show
Series gpio: cdev: add uAPI v2 | expand

Commit Message

Kent Gibson Sept. 9, 2020, 10:26 a.m. UTC
Set the value of the line info offset in desc_to_lineinfo, rather than
relying on it being passed in the info.  This makes the function behave
as you would expect from the name - it generates the line info
corresponding to a given GPIO desc.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
---

There are some instances where this results in the offset being set when
it is already set in the info, but this is clearer especially considering
that, as part of the replacement of strncpy with strscpy and to ensure
kernel stack cannot be leaked to userspace, the info is initially zeroed
in a subsequent patch.

 drivers/gpio/gpiolib-cdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andy Shevchenko Sept. 15, 2020, 10:08 a.m. UTC | #1
On Wed, Sep 9, 2020 at 1:28 PM Kent Gibson <warthog618@gmail.com> wrote:
>

> Set the value of the line info offset in desc_to_lineinfo, rather than


desc_to_lineinfo()

> relying on it being passed in the info.  This makes the function behave

> as you would expect from the name - it generates the line info

> corresponding to a given GPIO desc.


One nit-pick below.
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>


>

> Signed-off-by: Kent Gibson <warthog618@gmail.com>

> ---

>

> There are some instances where this results in the offset being set when

> it is already set in the info, but this is clearer especially considering

> that, as part of the replacement of strncpy with strscpy and to ensure

> kernel stack cannot be leaked to userspace, the info is initially zeroed

> in a subsequent patch.

>

>  drivers/gpio/gpiolib-cdev.c | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

>

> diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c

> index e6c9b78adfc2..e95e3eab9867 100644

> --- a/drivers/gpio/gpiolib-cdev.c

> +++ b/drivers/gpio/gpiolib-cdev.c

> @@ -752,6 +752,7 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc,

>         bool ok_for_pinctrl;

>         unsigned long flags;

>

> +       info->line_offset = gpio_chip_hwgpio(desc);


+ blank line?

>         /*

>          * This function takes a mutex so we must check this before taking

>          * the spinlock.

> @@ -933,7 +934,6 @@ static int lineinfo_changed_notify(struct notifier_block *nb,

>                 return NOTIFY_DONE;

>

>         memset(&chg, 0, sizeof(chg));

> -       chg.info.line_offset = gpio_chip_hwgpio(desc);

>         chg.event_type = action;

>         chg.timestamp = ktime_get_ns();

>         gpio_desc_to_lineinfo(desc, &chg.info);

> --

> 2.28.0

>



-- 
With Best Regards,
Andy Shevchenko
diff mbox series

Patch

diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index e6c9b78adfc2..e95e3eab9867 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -752,6 +752,7 @@  static void gpio_desc_to_lineinfo(struct gpio_desc *desc,
 	bool ok_for_pinctrl;
 	unsigned long flags;
 
+	info->line_offset = gpio_chip_hwgpio(desc);
 	/*
 	 * This function takes a mutex so we must check this before taking
 	 * the spinlock.
@@ -933,7 +934,6 @@  static int lineinfo_changed_notify(struct notifier_block *nb,
 		return NOTIFY_DONE;
 
 	memset(&chg, 0, sizeof(chg));
-	chg.info.line_offset = gpio_chip_hwgpio(desc);
 	chg.event_type = action;
 	chg.timestamp = ktime_get_ns();
 	gpio_desc_to_lineinfo(desc, &chg.info);