From: Thorsten Blum <blum@kernel.org>
To: "Jaroslav Kysela" <perex@perex.cz>,
"Takashi Iwai" <tiwai@suse.com>,
"Will Porter" <mrwillporter@gmail.com>,
"Cen Zhang" <zzzccc427@gmail.com>,
"Cássio Gabriel" <cassiogabrielcontato@gmail.com>
Cc: Thorsten Blum <blum@kernel.org>, Takashi Iwai <tiwai@suse.de>,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] ALSA: usb-audio: Simplify usb_audio_make_longname()
Date: Sun, 18 Oct 2026 14:41:55 +0200 [thread overview]
Message-ID: <20261018124155.2081-4-blum@kernel.org> (raw)
In-Reply-To: <20261018124155.2081-3-blum@kernel.org>
To prepare for removing strlcat() from the kernel [1], track the output
length and replace strlcat() with scnprintf() and strscpy().
Replace the speed switch statement with a lookup table.
No functional change.
Link: https://github.com/KSPP/linux/issues/370 [1]
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
sound/usb/card.c | 69 ++++++++++++++++++------------------------------
1 file changed, 26 insertions(+), 43 deletions(-)
diff --git a/sound/usb/card.c b/sound/usb/card.c
index 8a62e8e1c6fc..59979b793fe9 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -642,63 +642,46 @@ static void usb_audio_make_longname(struct usb_device *dev,
struct snd_usb_audio *chip,
const struct snd_usb_audio_quirk *quirk)
{
+ static const char * const speed_suffixes[] = {
+ [USB_SPEED_LOW] = ", low speed",
+ [USB_SPEED_FULL] = ", full speed",
+ [USB_SPEED_HIGH] = ", high speed",
+ [USB_SPEED_SUPER] = ", super speed",
+ [USB_SPEED_SUPER_PLUS] = ", super speed plus",
+ };
struct snd_card *card = chip->card;
const struct usb_audio_device_name *preset;
- const char *s = NULL;
- int len;
+ enum usb_device_speed speed = snd_usb_get_speed(dev);
+ int len, ret;
preset = lookup_device_name(chip->usb_id);
/* shortcut - if any pre-defined string is given, use it */
- if (preset && preset->profile_name)
- s = preset->profile_name;
- if (s && *s) {
- strscpy(card->longname, s, sizeof(card->longname));
+ if (preset && preset->profile_name && *preset->profile_name) {
+ strscpy(card->longname, preset->profile_name);
return;
}
+ *card->longname = 0;
if (preset && preset->vendor_name)
- s = preset->vendor_name;
+ strscpy(card->longname, preset->vendor_name);
else if (quirk && quirk->vendor_name)
- s = quirk->vendor_name;
- *card->longname = 0;
- if (s && *s)
- strscpy(card->longname, s);
- else if (dev->manufacturer && *dev->manufacturer)
- strscpy(card->longname, dev->manufacturer);
-
- if (*card->longname) {
- strim(card->longname);
- if (*card->longname)
- strlcat(card->longname, " ", sizeof(card->longname));
- }
+ strscpy(card->longname, quirk->vendor_name);
+ if (!*card->longname)
+ strscpy(card->longname, dev->manufacturer ?: "");
- strlcat(card->longname, card->shortname, sizeof(card->longname));
+ strim(card->longname);
+ len = strlen(card->longname);
+ len += scnprintf(card->longname + len, sizeof(card->longname) - len,
+ "%s%s at ", len ? " " : "", card->shortname);
- len = strlcat(card->longname, " at ", sizeof(card->longname));
-
- if (len < sizeof(card->longname))
- usb_make_path(dev, card->longname + len, sizeof(card->longname) - len);
+ ret = usb_make_path(dev, card->longname + len, sizeof(card->longname) - len);
+ if (ret < 0)
+ return;
+ len += ret;
- switch (snd_usb_get_speed(dev)) {
- case USB_SPEED_LOW:
- strlcat(card->longname, ", low speed", sizeof(card->longname));
- break;
- case USB_SPEED_FULL:
- strlcat(card->longname, ", full speed", sizeof(card->longname));
- break;
- case USB_SPEED_HIGH:
- strlcat(card->longname, ", high speed", sizeof(card->longname));
- break;
- case USB_SPEED_SUPER:
- strlcat(card->longname, ", super speed", sizeof(card->longname));
- break;
- case USB_SPEED_SUPER_PLUS:
- strlcat(card->longname, ", super speed plus", sizeof(card->longname));
- break;
- default:
- break;
- }
+ if (speed < ARRAY_SIZE(speed_suffixes) && speed_suffixes[speed])
+ strscpy(card->longname + len, speed_suffixes[speed], sizeof(card->longname) - len);
}
static void snd_usb_init_quirk_flags(int idx, struct snd_usb_audio *chip)
next prev parent reply other threads:[~2026-10-18 12:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-18 12:41 [PATCH 1/2] ALSA: usb-audio: Simplify usb_audio_make_shortname() Thorsten Blum
2026-10-18 12:41 ` Thorsten Blum [this message]
2026-10-19 8:43 ` Takashi Iwai
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=20261018124155.2081-4-blum@kernel.org \
--to=blum@kernel.org \
--cc=cassiogabrielcontato@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=mrwillporter@gmail.com \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
--cc=tiwai@suse.de \
--cc=zzzccc427@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.