* [PATCH] gpio: sim: Remove intermediate pointer variable and harden function
@ 2026-04-23 22:32 Maxwell Doose
2026-04-24 7:54 ` Bartosz Golaszewski
0 siblings, 1 reply; 5+ messages in thread
From: Maxwell Doose @ 2026-04-23 22:32 UTC (permalink / raw)
To: linusw, brgl; +Cc: linux-gpio, linux-kernel
Remove the *pdev intermediate variable and directly dereference the
pointer. While at it, replace sprintf() calls with sysfs_emit() to
harden the driver.
Signed-off-by: Maxwell Doose <m32285159@gmail.com>
---
drivers/gpio/gpio-sim.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
index 13b87c8e6d0c..3c230f94eea2 100644
--- a/drivers/gpio/gpio-sim.c
+++ b/drivers/gpio/gpio-sim.c
@@ -691,15 +691,13 @@ static ssize_t gpio_sim_device_config_dev_name_show(struct config_item *item,
char *page)
{
struct gpio_sim_device *dev = to_gpio_sim_device(item);
- struct platform_device *pdev;
guard(mutex)(&dev->lock);
- pdev = dev->probe_data.pdev;
- if (pdev)
- return sprintf(page, "%s\n", dev_name(&pdev->dev));
+ if (dev->probe_data.pdev)
+ return sysfs_emit(page, "%s\n", dev_name(&dev->probe_data.pdev->dev));
- return sprintf(page, "gpio-sim.%d\n", dev->id);
+ return sysfs_emit(page, "gpio-sim.%d\n", dev->id);
}
CONFIGFS_ATTR_RO(gpio_sim_device_config_, dev_name);
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] gpio: sim: Remove intermediate pointer variable and harden function
2026-04-23 22:32 [PATCH] gpio: sim: Remove intermediate pointer variable and harden function Maxwell Doose
@ 2026-04-24 7:54 ` Bartosz Golaszewski
2026-04-24 13:05 ` Maxwell Doose
0 siblings, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2026-04-24 7:54 UTC (permalink / raw)
To: Maxwell Doose; +Cc: linusw, linux-gpio, linux-kernel
On Fri, Apr 24, 2026 at 12:32 AM Maxwell Doose <m32285159@gmail.com> wrote:
>
> Remove the *pdev intermediate variable and directly dereference the
> pointer. While at it, replace sprintf() calls with sysfs_emit() to
> harden the driver.
>
> Signed-off-by: Maxwell Doose <m32285159@gmail.com>
> ---
> drivers/gpio/gpio-sim.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
> index 13b87c8e6d0c..3c230f94eea2 100644
> --- a/drivers/gpio/gpio-sim.c
> +++ b/drivers/gpio/gpio-sim.c
> @@ -691,15 +691,13 @@ static ssize_t gpio_sim_device_config_dev_name_show(struct config_item *item,
> char *page)
> {
> struct gpio_sim_device *dev = to_gpio_sim_device(item);
> - struct platform_device *pdev;
>
> guard(mutex)(&dev->lock);
>
> - pdev = dev->probe_data.pdev;
> - if (pdev)
> - return sprintf(page, "%s\n", dev_name(&pdev->dev));
> + if (dev->probe_data.pdev)
> + return sysfs_emit(page, "%s\n", dev_name(&dev->probe_data.pdev->dev));
Do you believe the code looks better with more layered dereferences?
>
> - return sprintf(page, "gpio-sim.%d\n", dev->id);
> + return sysfs_emit(page, "gpio-sim.%d\n", dev->id);
sprintf() is safe here as we cannot possibly exceed PAGE_SIZE with
this format but if you really want to do this, than please send a
separate patch converting all configfs show callbacks in the driver.
Bart
> }
>
> CONFIGFS_ATTR_RO(gpio_sim_device_config_, dev_name);
> --
> 2.53.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gpio: sim: Remove intermediate pointer variable and harden function
2026-04-24 7:54 ` Bartosz Golaszewski
@ 2026-04-24 13:05 ` Maxwell Doose
2026-04-24 13:13 ` Bartosz Golaszewski
0 siblings, 1 reply; 5+ messages in thread
From: Maxwell Doose @ 2026-04-24 13:05 UTC (permalink / raw)
To: Bartosz Golaszewski; +Cc: linusw, linux-gpio, linux-kernel
On Fri, Apr 24, 2026 at 2:54 AM Bartosz Golaszewski <brgl@kernel.org> wrote:
>
> Do you believe the code looks better with more layered dereferences?
>
I think some people might value the more explicit dereferencing, and with this
we also won't need to handle the overhead of assigning another pointer, but if
you want this removed thats fine by me.
> sprintf() is safe here as we cannot possibly exceed PAGE_SIZE with
> this format but if you really want to do this, than please send a
> separate patch converting all configfs show callbacks in the driver.
I can do that, but I'd prefer to separate the functional changes with
this one, so
expect another patch that fixes these. I'll remove those sysfs_emit changes for
now so that the commit history will be clean for when I come back with this
second patch.
best regards,
maxwell
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gpio: sim: Remove intermediate pointer variable and harden function
2026-04-24 13:05 ` Maxwell Doose
@ 2026-04-24 13:13 ` Bartosz Golaszewski
2026-04-24 13:22 ` Maxwell Doose
0 siblings, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2026-04-24 13:13 UTC (permalink / raw)
To: Maxwell Doose; +Cc: linusw, linux-gpio, linux-kernel
On Fri, Apr 24, 2026 at 3:05 PM Maxwell Doose <m32285159@gmail.com> wrote:
>
> On Fri, Apr 24, 2026 at 2:54 AM Bartosz Golaszewski <brgl@kernel.org> wrote:
> >
> > Do you believe the code looks better with more layered dereferences?
> >
>
> I think some people might value the more explicit dereferencing, and with this
> we also won't need to handle the overhead of assigning another pointer, but if
> you want this removed thats fine by me.
>
I prefer to keep it as is.
> > sprintf() is safe here as we cannot possibly exceed PAGE_SIZE with
> > this format but if you really want to do this, than please send a
> > separate patch converting all configfs show callbacks in the driver.
>
> I can do that, but I'd prefer to separate the functional changes with
> this one, so
> expect another patch that fixes these. I'll remove those sysfs_emit changes for
> now so that the commit history will be clean for when I come back with this
> second patch.
>
Sure, let's drop the first part and do the conversion of the configfs
show callbacks
Bart
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gpio: sim: Remove intermediate pointer variable and harden function
2026-04-24 13:13 ` Bartosz Golaszewski
@ 2026-04-24 13:22 ` Maxwell Doose
0 siblings, 0 replies; 5+ messages in thread
From: Maxwell Doose @ 2026-04-24 13:22 UTC (permalink / raw)
To: Bartosz Golaszewski; +Cc: linusw, linux-gpio, linux-kernel
On Fri, Apr 24, 2026 at 8:13 AM Bartosz Golaszewski <brgl@kernel.org> wrote:
>
> On Fri, Apr 24, 2026 at 3:05 PM Maxwell Doose <m32285159@gmail.com> wrote:
> > I think some people might value the more explicit dereferencing, and with this
> > we also won't need to handle the overhead of assigning another pointer, but if
> > you want this removed thats fine by me.
> >
>
> I prefer to keep it as is.
>
> >
> > I can do that, but I'd prefer to separate the functional changes with
> > this one, so
> > expect another patch that fixes these. I'll remove those sysfs_emit changes for
> > now so that the commit history will be clean for when I come back with this
> > second patch.
> >
>
> Sure, let's drop the first part and do the conversion of the configfs
> show callbacks
>
> Bart
Sounds good. I'll get that patch out this afternoon, otherwise I'll be
away for most
of the weekend and I'll get it out Sunday evening.
best regards,
maxwell
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-04-24 13:22 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-23 22:32 [PATCH] gpio: sim: Remove intermediate pointer variable and harden function Maxwell Doose
2026-04-24 7:54 ` Bartosz Golaszewski
2026-04-24 13:05 ` Maxwell Doose
2026-04-24 13:13 ` Bartosz Golaszewski
2026-04-24 13:22 ` Maxwell Doose
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox