From: Greg KH <gregkh@linuxfoundation.org>
To: Jules Irenge <jbi.octave@gmail.com>
Cc: hsweeten@visionengravers.com, abbotti@mev.co.uk,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] comedi: Convert snprintf() to sysfs_emit()
Date: Fri, 30 Sep 2022 14:24:48 +0200 [thread overview]
Message-ID: <YzbgEOA8mC0MmRY8@kroah.com> (raw)
In-Reply-To: <YzRK3Ye3FKTe8p4y@octinomon>
On Wed, Sep 28, 2022 at 02:23:41PM +0100, Jules Irenge wrote:
> Coccinnelle reports a warning
> Warning: Use scnprintf or sprintf
>
> Adding to that, there has been a slow migration from snprintf to scnprintf.
> This LWN article explains the rationale for this change
>
> https: //lwn.net/Articles/69419/
> ie. snprintf() returns what *would* be the resulting length,
> while scnprintf() returns the actual length.
None of this is needed or relevant for this change.
>
> However following the advice on
> https://www.kernel.org/doc/html/latest/filesystems/sysfs.html
>
> For show(device *...) functions we should only use sysfs_emit() or sysfs_emit_at()
> especially when formatting the value to be returned to user space.
>
> Hence here
> We convert to sysfs_emit() that even does better and shorten the code
> using the same rationale of scnprintf()
>
> Signed-off-by: Jules Irenge <jules.irenge@postgrad.manchester.ac.uk>
> ---
>
> v2: Replace scnprintf() with sysfs_emit()
>
> drivers/comedi/comedi_fops.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/comedi/comedi_fops.c b/drivers/comedi/comedi_fops.c
> index 55a0cae04b8d..a6017fafcb2a 100644
> --- a/drivers/comedi/comedi_fops.c
> +++ b/drivers/comedi/comedi_fops.c
> @@ -396,7 +396,7 @@ static ssize_t max_read_buffer_kb_show(struct device *csdev,
> mutex_unlock(&dev->mutex);
>
> comedi_dev_put(dev);
> - return snprintf(buf, PAGE_SIZE, "%u\n", size);
> + return sysfs_emit(buf, "%u\n", size);
> }
>
> static ssize_t max_read_buffer_kb_store(struct device *csdev,
Does not apply to my tree :(
thanks,
greg k-h
prev parent reply other threads:[~2022-09-30 12:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-28 13:23 [PATCH v2] comedi: Convert snprintf() to sysfs_emit() Jules Irenge
2022-09-30 12:24 ` Greg KH [this message]
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=YzbgEOA8mC0MmRY8@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=abbotti@mev.co.uk \
--cc=hsweeten@visionengravers.com \
--cc=jbi.octave@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/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