From: Greg KH <gregkh@linuxfoundation.org>
To: "Ksenija Stanojević" <ksenija.stanojevic@gmail.com>
Cc: outreachy-kernel@googlegroups.com
Subject: Re: [Outreachy kernel] [PATCH] Staging: fbtbt: show() methods should use scnprintf()
Date: Tue, 29 Sep 2015 22:12:38 +0200 [thread overview]
Message-ID: <20150929201238.GA27265@kroah.com> (raw)
In-Reply-To: <CAL7P5jLdWFvBs9Bmc=YukTNnA=0A77LWB=PcdFxp4yN0neq5kg@mail.gmail.com>
On Tue, Sep 29, 2015 at 09:50:58PM +0200, Ksenija Stanojević wrote:
> Hi,
>
> On Tue, Sep 29, 2015 at 9:38 PM, Greg KH <gregkh@linuxfoundation.org> wrote:
> > On Tue, Sep 29, 2015 at 09:15:23PM +0200, Ksenija Stanojevic wrote:
> >> snprintf() may return a value that exceeds its second argument,
> >> show() methods should use scnprintf() instead of snprintf().
> >>
> >> Signed-off-by: Ksenija Stanojevic <ksenija.stanojevic@gmail.com>
> >> ---
> >> drivers/staging/fbtft/fbtft-sysfs.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/staging/fbtft/fbtft-sysfs.c b/drivers/staging/fbtft/fbtft-sysfs.c
> >> index 8d8bd12..36a1f4e 100644
> >> --- a/drivers/staging/fbtft/fbtft-sysfs.c
> >> +++ b/drivers/staging/fbtft/fbtft-sysfs.c
> >> @@ -198,7 +198,7 @@ static ssize_t show_debug(struct device *device,
> >> struct fb_info *fb_info = dev_get_drvdata(device);
> >> struct fbtft_par *par = fb_info->par;
> >>
> >> - return snprintf(buf, PAGE_SIZE, "%lu\n", par->debug);
> >> + return scnprintf(buf, PAGE_SIZE, "%lu\n", par->debug);
> >
> > They should? Why? This shouldn't be needed at all, and really, a
> > simple sprintf() is all that is necessary. I would just leave this
> > alone, it's fine as-is.
>
> In kernel documentation :
> https://www.kernel.org/doc/Documentation/filesystems/sysfs.txt
> it states:
>
> show() must not use snprintf() when formatting the value to be
> returned to user space. If you can guarantee that an overflow
> will never happen you can use sprintf() otherwise you must use
> scnprintf()
>
> Should I just use sprintf instead?
If you are writing new code for sysfs attributes like these, yes, use
sprintf(). Don't modify existing code that is working just fine with no
errors at all by trying to convert snprintf() to scnprintf() please.
thanks,
greg k-h
prev parent reply other threads:[~2015-09-29 20:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-29 19:15 [PATCH] Staging: fbtbt: show() methods should use scnprintf() Ksenija Stanojevic
2015-09-29 19:38 ` [Outreachy kernel] " Greg KH
2015-09-29 19:50 ` Ksenija Stanojević
2015-09-29 20:12 ` 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=20150929201238.GA27265@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=ksenija.stanojevic@gmail.com \
--cc=outreachy-kernel@googlegroups.com \
/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 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.