Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: avoid redundant strlen() in make_name_string()
@ 2026-11-17 17:02 Dmitry Antipov
  2026-11-17 17:10 ` sashiko-bot
  2026-11-17 17:50 ` Takashi Iwai
  0 siblings, 2 replies; 4+ messages in thread
From: Dmitry Antipov @ 2026-11-17 17:02 UTC (permalink / raw)
  To: Neill Kapron, Greg Kroah-Hartman; +Cc: Takashi Iwai, linux-usb, Dmitry Antipov

In make_name_string(), prefer strchrnul() over strchr() to
avoid redundant call to strlen().

Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
 drivers/usb/gadget/function/f_midi2.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/function/f_midi2.c b/drivers/usb/gadget/function/f_midi2.c
index d693de427641..76738ea55dba 100644
--- a/drivers/usb/gadget/function/f_midi2.c
+++ b/drivers/usb/gadget/function/f_midi2.c
@@ -2101,11 +2101,10 @@ static void make_name_string(char *s)
 {
 	char *p;
 
-	p = strchr(s, '\n');
-	if (p)
+	p = strchrnul(s, '\n');
+	if (*p)
 		*p = 0;
 
-	p = s + strlen(s);
 	for (; p > s && isspace(*p); p--)
 		*p = 0;
 }
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-17 18:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox