From: Joe Perches <joe@perches.com>
To: Xiongfeng Wang <wangxiongfeng2@huawei.com>, minyard@acm.org
Cc: arnd@arndb.de, gregkh@linuxfoundation.org,
openipmi-developer@lists.sourceforge.net,
linux-kernel@vger.kernel.org, guohanjun@huawei.com
Subject: Re: [PATCH] ipmi/watchdog: add missing newlines when printing parameters by sysfs
Date: Mon, 20 Jul 2020 19:00:20 -0700 [thread overview]
Message-ID: <b38a439b2bdd1122805aa182da9a1802e673f53e.camel@perches.com> (raw)
In-Reply-To: <908fcbf2-efbb-b3f4-0666-2da79fbe99c4@huawei.com>
On Tue, 2020-07-21 at 09:20 +0800, Xiongfeng Wang wrote:
> On 2020/7/21 3:52, Corey Minyard wrote:
> > On Mon, Jul 20, 2020 at 10:03:25AM +0800, Xiongfeng Wang wrote:
> > > When I cat some ipmi_watchdog parameters by sysfs, it displays as
> > > follows. It's better to add a newline for easy reading.
[]
> > > diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
[]
> > > @@ -232,12 +232,16 @@ static int set_param_str(const char *val, const struct kernel_param *kp)
> > > static int get_param_str(char *buffer, const struct kernel_param *kp)
> > > {
> > > action_fn fn = (action_fn) kp->arg;
> > > - int rv;
> > > + int rv, len;
> > >
> > > rv = fn(NULL, buffer);
> > > if (rv)
> > > return rv;
> > > - return strlen(buffer);
> > > +
> > > + len = strlen(buffer);
> > > + len += sprintf(buffer + len, "\n");
> >
> > sprintf is kind of overkill to stick a \n on the end of a line. How
> > about:
> >
> > buffer[len++] = '\n';
> >
> > Since you are returning the length, you shouldn't need to nil terminate
> > the string.
You never quite know for sure so I suggest making
the string null terminated just in case.
i.e.:
buffer[len++] = '\n';
buffer[len] = 0;
next prev parent reply other threads:[~2020-07-21 2:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-20 2:03 [PATCH] ipmi/watchdog: add missing newlines when printing parameters by sysfs Xiongfeng Wang
2020-07-20 19:52 ` Corey Minyard
2020-07-21 1:20 ` Xiongfeng Wang
2020-07-21 2:00 ` Joe Perches [this message]
2020-07-21 6:17 ` Xiongfeng Wang
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=b38a439b2bdd1122805aa182da9a1802e673f53e.camel@perches.com \
--to=joe@perches.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=guohanjun@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=minyard@acm.org \
--cc=openipmi-developer@lists.sourceforge.net \
--cc=wangxiongfeng2@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).