gpio: sim: Remove intermediate pointer variable and harden function
PATCH 1/1 gpio: sim: Remove intermediate pointer variable and harden function
Remove the *pdev intermediate variable and directly dereference the pointer. While at it, replace sprintf() calls with sysfs_emit() to harden the driver.
--- drivers/gpio/gpio-sim.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/gpio/gpio-sim.c +3 -5
@@ -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);
Signature · 1 line
2.53.0
Bartosz Golaszewski
maintainerQuoted 17 lines · Maxwell Doose
Remove the *pdev intermediate variable and directly dereference the pointer. While at it, replace
sprintf()calls withsysfs_emit()to harden the driver.Signed-off-by Maxwell Doose <[email protected]>--- drivers/gpio/gpio-sim.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)drivers/gpio/gpio-sim.c +0
-0@@ -691,15 +691,13 @@ static ssize_t gpio_sim_device_config_dev_name_show(struct config_item *item, char *page) {
drivers/gpio/gpio-sim.c static ssize_t gpio_sim_device_config_dev_name_show(struct config_item *item, · line 698
Quoted 10 lines
drivers/gpio/gpio-sim.c +2
-4struct 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?
drivers/gpio/gpio-sim.c static ssize_t gpio_sim_device_config_dev_name_show(struct config_item *item, · line 700
Quoted 3 lines
drivers/gpio/gpio-sim.c +1
-1-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
Quoted 6 lines
drivers/gpio/gpio-sim.c +0
-1}CONFIGFS_ATTR_RO (gpio_sim_device_config_, dev_name); --2.53.0
Quoted 3 lines · Bartosz Golaszewski
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.
Quoted 3 lines
sprintf()is safe here as we cannot possibly exceedPAGE_SIZEwith 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
Bartosz Golaszewski
maintainerQuoted 10 lines · Maxwell Doose
Quoted 3 lines · Bartosz Golaszewski
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.
Quoted 10 lines
Quoted 3 lines
sprintf()is safe here as we cannot possibly exceedPAGE_SIZEwith 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 thosesysfs_emitchanges 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
Quoted 17 lines · Bartosz Golaszewski
Quoted 4 lines · Maxwell Doose
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.
Quoted 7 lines
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 thosesysfs_emitchanges for now so that the commit history will be clean for when I come back with this second patch.
Quoted 4 lines
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