* [PATCH v2] staging: fieldbus: replace snprintf in show functions with sysfs_emit
@ 2022-11-09 5:56 Deepak R Varma
2022-11-09 7:30 ` Greg Kroah-Hartman
0 siblings, 1 reply; 3+ messages in thread
From: Deepak R Varma @ 2022-11-09 5:56 UTC (permalink / raw)
To: outreachy, Sven Van Asbroeck, Greg Kroah-Hartman, linux-staging,
linux-kernel
The show() methods should only use sysfs_emit() when formatting values
to be returned to the user space.
Ref: Documentation/filesystems/sysfs.rst
Issue identified by coccicheck.
Signed-off-by: Deepak R Varma <drv@mailo.com>
---
Changes in v2:
1. Switch to using sysfs_emit instead of scnprintf
2. Update patch subject and log accordingly
Feedback from gregkh@linuxfoundation.org
drivers/staging/fieldbus/dev_core.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/fieldbus/dev_core.c b/drivers/staging/fieldbus/dev_core.c
index 5aab734606ea..d32599f4eb44 100644
--- a/drivers/staging/fieldbus/dev_core.c
+++ b/drivers/staging/fieldbus/dev_core.c
@@ -67,10 +67,10 @@ static ssize_t card_name_show(struct device *dev, struct device_attribute *attr,
struct fieldbus_dev *fb = dev_get_drvdata(dev);
/*
- * card_name was provided by child driver, could potentially be long.
- * protect against buffer overrun.
+ * sysfs provides PAGE_SIZE long buffer to take care of potentially
+ * long card_name provided by child driver.
*/
- return snprintf(buf, PAGE_SIZE, "%s\n", fb->card_name);
+ return sysfs_emit(buf, "%s\n", fb->card_name);
}
static DEVICE_ATTR_RO(card_name);
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] staging: fieldbus: replace snprintf in show functions with sysfs_emit
2022-11-09 5:56 [PATCH v2] staging: fieldbus: replace snprintf in show functions with sysfs_emit Deepak R Varma
@ 2022-11-09 7:30 ` Greg Kroah-Hartman
2022-11-09 7:46 ` Deepak R Varma
0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2022-11-09 7:30 UTC (permalink / raw)
To: Deepak R Varma; +Cc: outreachy, Sven Van Asbroeck, linux-staging, linux-kernel
On Wed, Nov 09, 2022 at 11:26:52AM +0530, Deepak R Varma wrote:
> The show() methods should only use sysfs_emit() when formatting values
> to be returned to the user space.
> Ref: Documentation/filesystems/sysfs.rst
> Issue identified by coccicheck.
>
> Signed-off-by: Deepak R Varma <drv@mailo.com>
> ---
>
> Changes in v2:
> 1. Switch to using sysfs_emit instead of scnprintf
> 2. Update patch subject and log accordingly
> Feedback from gregkh@linuxfoundation.org
>
>
> drivers/staging/fieldbus/dev_core.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/staging/fieldbus/dev_core.c b/drivers/staging/fieldbus/dev_core.c
> index 5aab734606ea..d32599f4eb44 100644
> --- a/drivers/staging/fieldbus/dev_core.c
> +++ b/drivers/staging/fieldbus/dev_core.c
> @@ -67,10 +67,10 @@ static ssize_t card_name_show(struct device *dev, struct device_attribute *attr,
> struct fieldbus_dev *fb = dev_get_drvdata(dev);
>
> /*
> - * card_name was provided by child driver, could potentially be long.
> - * protect against buffer overrun.
> + * sysfs provides PAGE_SIZE long buffer to take care of potentially
No need to ever mention PAGE_SIZE at all, this comment should just be:
/* card_name was provided by child driver */
But the larger question is, why did you only convert one of the sysfs
show functions in this file? Why not do them all?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] staging: fieldbus: replace snprintf in show functions with sysfs_emit
2022-11-09 7:30 ` Greg Kroah-Hartman
@ 2022-11-09 7:46 ` Deepak R Varma
0 siblings, 0 replies; 3+ messages in thread
From: Deepak R Varma @ 2022-11-09 7:46 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: outreachy, Sven Van Asbroeck, linux-staging, linux-kernel
On Wed, Nov 09, 2022 at 08:30:26AM +0100, Greg Kroah-Hartman wrote:
> On Wed, Nov 09, 2022 at 11:26:52AM +0530, Deepak R Varma wrote:
> > The show() methods should only use sysfs_emit() when formatting values
> > to be returned to the user space.
> > Ref: Documentation/filesystems/sysfs.rst
> > Issue identified by coccicheck.
> >
> > Signed-off-by: Deepak R Varma <drv@mailo.com>
> > /*
> > - * card_name was provided by child driver, could potentially be long.
> > - * protect against buffer overrun.
> > + * sysfs provides PAGE_SIZE long buffer to take care of potentially
>
> No need to ever mention PAGE_SIZE at all, this comment should just be:
> /* card_name was provided by child driver */
Sure. I will update the comment in the revision.
>
> But the larger question is, why did you only convert one of the sysfs
> show functions in this file? Why not do them all?
I was limiting it to what is reported by coccicheck. I will review other such
show functions and send a consolidated patch.
Thank you,
./drv
>
> thanks,
>
> greg k-h
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-09 7:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-09 5:56 [PATCH v2] staging: fieldbus: replace snprintf in show functions with sysfs_emit Deepak R Varma
2022-11-09 7:30 ` Greg Kroah-Hartman
2022-11-09 7:46 ` Deepak R Varma
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox