From: Takashi Iwai <tiwai@suse.de>
To: Dmitry Antipov <dmantipov@yandex.ru>
Cc: Takashi Iwai <tiwai@suse.de>, Neill Kapron <nkapron@google.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org
Subject: Re: [PATCH] usb: gadget: avoid redundant strlen() in make_name_string()
Date: Tue, 17 Nov 2026 22:10:35 +0100 [thread overview]
Message-ID: <87a4n7xiyc.wl-tiwai@suse.de> (raw)
In-Reply-To: <839e190e-6377-4585-b68a-b672e5b4a13e@yandex.ru>
On Tue, 17 Nov 2026 20:08:01 +0100,
Dmitry Antipov wrote:
>
> On 11/17/26 9:10 PM, Takashi Iwai wrote:
>
> >> Hmm, does it really result in the same? Wouldn't you need to
> >> decrement p at first before the loop?
> >
> > ... and looking again, I think it's a bug in my original code ;)
> >
> >> And I guess this can be better replaced with strim().
> >
> > ... which can be fixed by replacing with strim() gracefully.
> >
> > Care to resubmit as a fix?
>
> strim() implies strlen() which is not actually needed here :-).
> So (assuming I've hit an original intention) I'm voting for:
>
> void make_name_string(char *s)
> {
> char *p;
>
> p = strchrnul(s, '\n');
> if (*p)
> *p = 0;
>
> while (--p > s && isspace(*p))
> *p = 0;
> }
>
> Note this trims " \n" to " " (string of the only space character).
> If this is not what we want here,
>
> while (--p >= s && isspace(*p))
>
> converts " \n" to an empty string.
For that code path, chasing for performance with open-code has no
merit. A simpler code would have much more benefit, instead.
Basically make_name_string() call can be simply replaced strim(), and
you can get rid of buggy (or error-prone) open code.
Takashi
prev parent reply other threads:[~2026-11-17 21:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 17:02 [PATCH] usb: gadget: avoid redundant strlen() in make_name_string() Dmitry Antipov
2026-11-17 17:10 ` sashiko-bot
2026-11-17 17:50 ` Takashi Iwai
2026-11-17 18:10 ` Takashi Iwai
2026-11-17 19:08 ` Dmitry Antipov
2026-11-17 21:10 ` Takashi Iwai [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=87a4n7xiyc.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=dmantipov@yandex.ru \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=nkapron@google.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