All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] ALSA: usb-audio: Simplify usb_audio_make_shortname()
@ 2026-10-18 12:41 Thorsten Blum
  2026-10-18 12:41 ` [PATCH 2/2] ALSA: usb-audio: Simplify usb_audio_make_longname() Thorsten Blum
  2026-10-19  8:43 ` [PATCH 1/2] ALSA: usb-audio: Simplify usb_audio_make_shortname() Takashi Iwai
  0 siblings, 2 replies; 3+ messages in thread
From: Thorsten Blum @ 2026-10-18 12:41 UTC (permalink / raw)
  To: Jaroslav Kysela, Takashi Iwai, Cássio Gabriel, Cen Zhang,
	Will Porter
  Cc: Thorsten Blum, Takashi Iwai, linux-sound, linux-kernel

Copy the preset and quirk product names directly and remove the local
char s pointer. Return after trimming the device product name and use
the USB device ID as a fallback.

No functional change.

Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 sound/usb/card.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/sound/usb/card.c b/sound/usb/card.c
index 9307da95efbe..8a62e8e1c6fc 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -618,30 +618,24 @@ static void usb_audio_make_shortname(struct usb_device *dev,
 {
 	struct snd_card *card = chip->card;
 	const struct usb_audio_device_name *preset;
-	const char *s = NULL;
 
+	*card->shortname = 0;
 	preset = lookup_device_name(chip->usb_id);
 	if (preset && preset->product_name)
-		s = preset->product_name;
+		strscpy(card->shortname, preset->product_name);
 	else if (quirk && quirk->product_name)
-		s = quirk->product_name;
-	if (s && *s) {
-		strscpy(card->shortname, s, sizeof(card->shortname));
+		strscpy(card->shortname, quirk->product_name);
+	if (*card->shortname)
 		return;
-	}
 
-	/* retrieve the device string as shortname */
 	if (dev->product && *dev->product) {
 		strscpy(card->shortname, dev->product);
-	} else {
-		/* no name available from anywhere, so use ID */
-		scnprintf(card->shortname, sizeof(card->shortname),
-			  "USB Device %#04x:%#04x",
-			  USB_ID_VENDOR(chip->usb_id),
-			  USB_ID_PRODUCT(chip->usb_id));
+		strim(card->shortname);
+		return;
 	}
 
-	strim(card->shortname);
+	scnprintf(card->shortname, sizeof(card->shortname), "USB Device %#04x:%#04x",
+		  USB_ID_VENDOR(chip->usb_id), USB_ID_PRODUCT(chip->usb_id));
 }
 
 static void usb_audio_make_longname(struct usb_device *dev,

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

* [PATCH 2/2] ALSA: usb-audio: Simplify usb_audio_make_longname()
  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
  2026-10-19  8:43 ` [PATCH 1/2] ALSA: usb-audio: Simplify usb_audio_make_shortname() Takashi Iwai
  1 sibling, 0 replies; 3+ messages in thread
From: Thorsten Blum @ 2026-10-18 12:41 UTC (permalink / raw)
  To: Jaroslav Kysela, Takashi Iwai, Will Porter, Cen Zhang,
	Cássio Gabriel
  Cc: Thorsten Blum, Takashi Iwai, linux-sound, linux-kernel

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)

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

* Re: [PATCH 1/2] ALSA: usb-audio: Simplify usb_audio_make_shortname()
  2026-10-18 12:41 [PATCH 1/2] ALSA: usb-audio: Simplify usb_audio_make_shortname() Thorsten Blum
  2026-10-18 12:41 ` [PATCH 2/2] ALSA: usb-audio: Simplify usb_audio_make_longname() Thorsten Blum
@ 2026-10-19  8:43 ` Takashi Iwai
  1 sibling, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2026-10-19  8:43 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Jaroslav Kysela, Takashi Iwai, Cássio Gabriel, Cen Zhang,
	Will Porter, Takashi Iwai, linux-sound, linux-kernel

On Sun, 18 Oct 2026 14:41:54 +0200,
Thorsten Blum wrote:
> 
> Copy the preset and quirk product names directly and remove the local
> char s pointer. Return after trimming the device product name and use
> the USB device ID as a fallback.
> 
> No functional change.
> 
> Signed-off-by: Thorsten Blum <blum@kernel.org>

Applied both patches now.  Thanks.


Takashi

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

end of thread, other threads:[~2026-10-19  8:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-18 12:41 [PATCH 1/2] ALSA: usb-audio: Simplify usb_audio_make_shortname() Thorsten Blum
2026-10-18 12:41 ` [PATCH 2/2] ALSA: usb-audio: Simplify usb_audio_make_longname() Thorsten Blum
2026-10-19  8:43 ` [PATCH 1/2] ALSA: usb-audio: Simplify usb_audio_make_shortname() Takashi Iwai

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.