public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Deepak R Varma <drv@mailo.com>
Cc: outreachy@lists.linux.dev,
	Sven Van Asbroeck <TheSven73@gmail.com>,
	linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: fieldbus: convert snprintf to scnprintf
Date: Tue, 8 Nov 2022 16:13:12 +0100	[thread overview]
Message-ID: <Y2pyCA/tRunNVRQt@kroah.com> (raw)
In-Reply-To: <Y2K2MD7+WBu4QouU@qemulion>

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

  reply	other threads:[~2022-11-08 15:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-02 18:25 [PATCH] staging: fieldbus: convert snprintf to scnprintf Deepak R Varma
2022-11-08 15:13 ` Greg Kroah-Hartman [this message]
2022-11-09  6:05   ` Deepak R Varma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y2pyCA/tRunNVRQt@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=TheSven73@gmail.com \
    --cc=drv@mailo.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=outreachy@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox