From: Joe Perches <joe@perches.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Namhyung Kim <namhyung@kernel.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Tom Zanussi <zanussi@kernel.org>
Subject: Re: [PATCH v3] string.h: Add str_has_prefix() helper
Date: Fri, 21 Dec 2018 15:44:41 -0800 [thread overview]
Message-ID: <75e15c5d66ecd6964231be0f5b3cf702ac242bc1.camel@perches.com> (raw)
In-Reply-To: <20181221182507.2fdc756f@gandalf.local.home>
On Fri, 2018-12-21 at 18:25 -0500, Steven Rostedt wrote:
> On Fri, 21 Dec 2018 15:19:33 -0800
> Joe Perches <joe@perches.com> wrote:
>
> > I believe this should be bool.
> >
> > I don't find a use for non-zero assigned len value in the kernel
> > for strncmp and I believe the function should simply be:
> >
> > static inline bool str_has_prefix(const char *str, const char prefix[])
> > {
> > return !strncmp(str, prefix, strlen(prefix));
> > }
>
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
[]
> @@ -172,8 +172,8 @@ cache_type_store(struct device *dev, struct device_attribute *attr,
> * it's not worth the risk */
> return -EINVAL;
>
> - if (strncmp(buf, temp, sizeof(temp) - 1) == 0) {
> - buf += sizeof(temp) - 1;
> + if ((len = str_has_prefix(buf, temp))) {
> + buf += len;
That's not really a use of the non-zero strncmp return value.
You are attempting an optimization not already done.
I also wonder if it's actually an optimization as the
return value may not be precomputed.
Also the assignment in the test isn't preferred style.
> And there's more places like this.
Any where the non-zero return value is actually used?
> > It's hard to believe __always_inline vs inline matters
> > for any single line function.
>
> I've been burnt by gcc deciding to not inline single functions before.
Complex single functions sure, but single line inlines?
I haven't seen that externed anywhere.
Today no inline function is marked __always_inline in
string.h
I don't doubt there should be some standardization
of inline vs __always_inline in the kernel, but this
right now seems different just for difference sake.
cheers, Joe
next prev parent reply other threads:[~2018-12-21 23:44 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-21 23:13 [PATCH v3] string.h: Add str_has_prefix() helper Steven Rostedt
2018-12-21 23:19 ` Joe Perches
2018-12-21 23:25 ` Steven Rostedt
2018-12-21 23:38 ` Steven Rostedt
2018-12-22 9:28 ` Namhyung Kim
2018-12-22 12:22 ` Steven Rostedt
2018-12-23 3:23 ` Namhyung Kim
2018-12-21 23:44 ` Joe Perches [this message]
2018-12-22 0:00 ` Steven Rostedt
2018-12-22 0:06 ` Steven Rostedt
2018-12-22 0:22 ` Joe Perches
[not found] ` <CAHk-=wgfSR9qhEWf--Do11jUFHyVM+VEmwm5LBS2JsV0F5yakw@mail.gmail.com>
2018-12-22 0:37 ` Steven Rostedt
2018-12-22 10:58 ` Ingo Molnar
2018-12-22 13:16 ` Steven Rostedt
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=75e15c5d66ecd6964231be0f5b3cf702ac242bc1.camel@perches.com \
--to=joe@perches.com \
--cc=akpm@linux-foundation.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=rostedt@goodmis.org \
--cc=torvalds@linux-foundation.org \
--cc=zanussi@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