From: Joe Perches <joe@perches.com>
To: Chuhong Yuan <hslester96@gmail.com>
Cc: Petr Mladek <pmladek@suse.com>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 08/12] printk: Replace strncmp with str_has_prefix
Date: Thu, 01 Aug 2019 09:19:04 -0700 [thread overview]
Message-ID: <917395fc42633b66abe3f713a9eef8edfdf7ee44.camel@perches.com> (raw)
In-Reply-To: <CANhBUQ2RD065Dn8eGkbzSQxfie5XrR_kgaFQ1QgOS4cKNhAfPA@mail.gmail.com>
On Thu, 2019-08-01 at 23:23 +0800, Chuhong Yuan wrote:
> Joe Perches <joe@perches.com> 于2019年7月30日周二 上午8:16写道:
> > On Mon, 2019-07-29 at 23:15 +0800, Chuhong Yuan wrote:
> > > strncmp(str, const, len) is error-prone.
> > > We had better use newly introduced
> > > str_has_prefix() instead of it.
> > []
> > > diff --git a/kernel/printk/braille.c b/kernel/printk/braille.c
> > []
> > > @@ -11,10 +11,10 @@
> > >
> > > int _braille_console_setup(char **str, char **brl_options)
> > > {
> > > - if (!strncmp(*str, "brl,", 4)) {
> > > + if (str_has_prefix(*str, "brl,")) {
> > > *brl_options = "";
> > > *str += 4;
> > > - } else if (!strncmp(*str, "brl=", 4)) {
> > > + } else if (str_has_prefix(*str, "brl=")) {
> > > *brl_options = *str + 4;
> >
> > Better to get rid of the += 4 uses too by storing the result
> > of str_has_prefix and using that as the addend.
> >
> > Perhaps
> > size_t len;
> >
> > if ((len = str_has_prefix(*str, "brl,"))) {
> > *brl_options = "";
> > *str += len;
> > } else if ((len = str_has_prefix(*str, "brl="))) {
> > etc...
> >
>
> I find that checkpatch.pl forbids assignment in if condition.
> So this seems to be infeasible...
checkpatch is a stupid script and doesn't forbid
anything. It's just a suggestion guide.
Ignore checkpatch when you know better.
next prev parent reply other threads:[~2019-08-01 16:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-29 15:15 Chuhong Yuan
2019-07-30 0:16 ` Joe Perches
2019-08-01 15:23 ` Chuhong Yuan
2019-08-01 16:19 ` Joe Perches [this message]
2019-08-01 16:40 ` Steven Rostedt
2019-08-01 17:51 ` Joe Perches
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=917395fc42633b66abe3f713a9eef8edfdf7ee44.camel@perches.com \
--to=joe@perches.com \
--cc=hslester96@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=sergey.senozhatsky@gmail.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
all inboxes | Powered by JetHome®