mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Luca Rodenhäuser" <otzelot2021@outlook.de>
To: perex@perex.cz, tiwai@suse.com
Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Luca Rodenhäuser" <otzelot2021@outlook.de>
Subject: [RFC PATCH 1/8] ALSA: core: keep non-ASCII bytes out of the card id
Date: Tue, 15 Sep 2026 17:59:01 +0200	[thread overview]
Message-ID: <AMBP191MB28863B6CE1C116E63E043CFECEBA2@AMBP191MB2886.EURP191.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <AMBP191MB2886193B1F896974A7CE23E1CEBA2@AMBP191MB2886.EURP191.PROD.OUTLOOK.COM>

copy_valid_id_string() filters the source string through safe_ascii_char()
everywhere but one place.  When the name it derives the id from starts with
a digit, it prepends a letter taken from the original string, guarded only
by isalpha():

	if (isdigit(*nid))
		*id++ = isalpha(*src) ? *src : 'D';

The kernel ctype table classifies the Latin-1 high bytes as letters, so
isalpha(0xc3) is true, and that byte is copied into card->id unchanged.

A USB device is enough to trigger it: usb_audio_make_shortname() copies
dev->product into card->shortname, so a product name whose first
ASCII-alphanumeric byte is a digit, such as "\xc3\x84" "3000", leaves
card->id starting with 0xc3.

That matters because card->id is an identifier, not a display name.  It
becomes a directory name under /proc/asound, it is handed to user space in
snd_ctl_card_info::id, and it is the handle in alsa-lib's hw:CARD=<id>.
The sysfs id_store() path rejects anything outside
safe_ascii_char() || '_' || '-', so the kernel currently produces ids that
it refuses to accept from user space.

Guard the byte with isascii() as well.  A non-ASCII first byte then falls
back to 'D', which is what the same line already does for anything that is
not a letter.

Assisted-by: LLM
Signed-off-by: Luca Rodenhäuser <otzelot2021@outlook.de>
---
 sound/core/init.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/sound/core/init.c b/sound/core/init.c
index 9693e646b3..2b33dd7b42 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -707,8 +707,13 @@ static void copy_valid_id_string(struct snd_card *card, const char *src,
 
 	while (*nid && !safe_ascii_char(*nid))
 		nid++;
-	if (isdigit(*nid))
-		*id++ = isalpha(*src) ? *src : 'D';
+	if (isdigit(*nid)) {
+		/* isalpha() alone is not enough: the ctype table classifies the
+		 * Latin-1 high bytes as letters, so a non-ASCII first byte would
+		 * end up in the id, which must stay alphanumeric ASCII.
+		 */
+		*id++ = isascii(*src) && isalpha(*src) ? *src : 'D';
+	}
 	while (*nid && (size_t)(id - card->id) < sizeof(card->id) - 1) {
 		if (safe_ascii_char(*nid))
 			*id++ = *nid;
-- 
2.43.0


  reply	other threads:[~2026-09-15 15:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-15 15:59 [RFC PATCH 0/8] ALSA: untruncated card names Luca Rodenhäuser
2026-09-15 15:59 ` Luca Rodenhäuser [this message]
2026-09-15 15:59 ` [RFC PATCH 2/8] ALSA: control: copy the card bytes outside snd_ioctl_rwsem Luca Rodenhäuser
2026-09-15 15:59 ` [RFC PATCH 3/8] ALSA: usb-audio: don't cut the card name inside a UTF-8 character Luca Rodenhäuser
2026-09-15 15:59 ` [RFC PATCH 4/8] ALSA: core: carry the untruncated form of the card names Luca Rodenhäuser
2026-09-15 15:59 ` [RFC PATCH 5/8] ALSA: control: return the untruncated card names via CARD_BYTES Luca Rodenhäuser
2026-09-15 15:59 ` [RFC PATCH 6/8] ALSA: core: add KUnit coverage for the card names Luca Rodenhäuser
2026-09-15 15:59 ` [RFC PATCH 7/8] ALSA: usb-audio: offer the untruncated " Luca Rodenhäuser
2026-09-15 15:59 ` [RFC PATCH 8/8] ALSA: Documentation: describe the card name fields Luca Rodenhäuser

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=AMBP191MB28863B6CE1C116E63E043CFECEBA2@AMBP191MB2886.EURP191.PROD.OUTLOOK.COM \
    --to=otzelot2021@outlook.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.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

all inboxes | Powered by JetHome®