All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: fieldbus: convert snprintf to scnprintf
@ 2022-11-02 18:25 Deepak R Varma
  2022-11-08 15:13 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Deepak R Varma @ 2022-11-02 18:25 UTC (permalink / raw)
  To: outreachy, Sven Van Asbroeck, Greg Kroah-Hartman, linux-staging,
	linux-kernel

It is recommended to use scnprintf instead of snprintf to accurately
return the size of the encoded data. Following article [1] has details
on the reason for this kernel level migration. This issue was identified
using coccicheck.

[1] https://lwn.net/Articles/69419/

Signed-off-by: Deepak R Varma <drv@mailo.com>
---
 drivers/staging/fieldbus/dev_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/fieldbus/dev_core.c b/drivers/staging/fieldbus/dev_core.c
index 5aab734606ea..d51f2b02d5e6 100644
--- a/drivers/staging/fieldbus/dev_core.c
+++ b/drivers/staging/fieldbus/dev_core.c
@@ -70,7 +70,7 @@ static ssize_t card_name_show(struct device *dev, struct device_attribute *attr,
 	 * card_name was provided by child driver, could potentially be long.
 	 * protect against buffer overrun.
 	 */
-	return snprintf(buf, PAGE_SIZE, "%s\n", fb->card_name);
+	return scnprintf(buf, PAGE_SIZE, "%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] staging: fieldbus: convert snprintf to scnprintf
  2022-11-02 18:25 [PATCH] staging: fieldbus: convert snprintf to scnprintf Deepak R Varma
@ 2022-11-08 15:13 ` Greg Kroah-Hartman
  2022-11-09  6:05   ` Deepak R Varma
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2022-11-08 15:13 UTC (permalink / raw)
  To: Deepak R Varma; +Cc: outreachy, Sven Van Asbroeck, linux-staging, linux-kernel

On Wed, Nov 02, 2022 at 11:55:52PM +0530, Deepak R Varma wrote:
> It is recommended to use scnprintf instead of snprintf to accurately
> return the size of the encoded data. Following article [1] has details
> on the reason for this kernel level migration. This issue was identified
> using coccicheck.
> 
> [1] https://lwn.net/Articles/69419/
> 
> Signed-off-by: Deepak R Varma <drv@mailo.com>
> ---
>  drivers/staging/fieldbus/dev_core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/fieldbus/dev_core.c b/drivers/staging/fieldbus/dev_core.c
> index 5aab734606ea..d51f2b02d5e6 100644
> --- a/drivers/staging/fieldbus/dev_core.c
> +++ b/drivers/staging/fieldbus/dev_core.c
> @@ -70,7 +70,7 @@ static ssize_t card_name_show(struct device *dev, struct device_attribute *attr,
>  	 * card_name was provided by child driver, could potentially be long.
>  	 * protect against buffer overrun.
>  	 */
> -	return snprintf(buf, PAGE_SIZE, "%s\n", fb->card_name);
> +	return scnprintf(buf, PAGE_SIZE, "%s\n", fb->card_name);

No, neither of these are correct.

Please use sysfs_emit() for sysfs show callbacks.

thanks,

greg k-h

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

* Re: [PATCH] staging: fieldbus: convert snprintf to scnprintf
  2022-11-08 15:13 ` Greg Kroah-Hartman
@ 2022-11-09  6:05   ` Deepak R Varma
  0 siblings, 0 replies; 3+ messages in thread
From: Deepak R Varma @ 2022-11-09  6:05 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: outreachy, Sven Van Asbroeck, linux-staging, linux-kernel

On Tue, Nov 08, 2022 at 04:13:12PM +0100, Greg Kroah-Hartman wrote:
> On Wed, Nov 02, 2022 at 11:55:52PM +0530, Deepak R Varma wrote:
> > It is recommended to use scnprintf instead of snprintf to accurately
> > return the size of the encoded data. Following article [1] has details
> > on the reason for this kernel level migration. This issue was identified
> > using coccicheck.
> >
> > [1] https://lwn.net/Articles/69419/
> >
> > Signed-off-by: Deepak R Varma <drv@mailo.com>
> > ---
> >  drivers/staging/fieldbus/dev_core.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/staging/fieldbus/dev_core.c b/drivers/staging/fieldbus/dev_core.c
> > index 5aab734606ea..d51f2b02d5e6 100644
> > --- a/drivers/staging/fieldbus/dev_core.c
> > +++ b/drivers/staging/fieldbus/dev_core.c
> > @@ -70,7 +70,7 @@ static ssize_t card_name_show(struct device *dev, struct device_attribute *attr,
> >  	 * card_name was provided by child driver, could potentially be long.
> >  	 * protect against buffer overrun.
> >  	 */
> > -	return snprintf(buf, PAGE_SIZE, "%s\n", fb->card_name);
> > +	return scnprintf(buf, PAGE_SIZE, "%s\n", fb->card_name);
>
> No, neither of these are correct.
>
> Please use sysfs_emit() for sysfs show callbacks.

Hello Greg,
Thank you. I corrected and resubmitted the patch as suggested.

Hi Julia,
The device_attr_show.cocci file should have made the recommendation to use
the sysfs_emit(), however, in this case it instead suggested to use scnprintf.
Is it because the method name was not "show" but "xxx_show"?

Thank you,
./drv

>
> thanks,
>
> greg k-h



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

end of thread, other threads:[~2022-11-09  6:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-02 18:25 [PATCH] staging: fieldbus: convert snprintf to scnprintf Deepak R Varma
2022-11-08 15:13 ` Greg Kroah-Hartman
2022-11-09  6:05   ` Deepak R Varma

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.