All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] ALSA: how should a card name that is not ASCII be exposed?
@ 2026-09-14 16:46 otzelot2021
  2026-09-14 16:59 ` Jaroslav Kysela
  0 siblings, 1 reply; 4+ messages in thread
From: otzelot2021 @ 2026-09-14 16:46 UTC (permalink / raw)
  To: perex, tiwai; +Cc: linux-sound

Hi,

before writing more code I would like to ask whether the problem below
is worth solving in the kernel at all, and if so, which of the possible
shapes you would prefer.

The problem
-----------

struct snd_card has three strings that exist only to be shown to a
human: shortname, longname and mixername.  They are fixed-size byte
arrays with no defined character encoding, so everything treats them as
ASCII.

That assumption does not hold on USB.  usb_string() converts the
UTF-16LE string descriptors of a device into UTF-8, so dev->product and
dev->manufacturer can already contain multi-byte characters today.
usb_audio_make_shortname() then does:

     strscpy(card->shortname, dev->product);

into a 32-byte array.  If the name is longer, strscpy() cuts it at a
byte boundary, which for a multi-byte character means the last sequence
in shortname is truncated.  What user space receives through
SNDRV_CTL_IOCTL_CARD_INFO is then not valid UTF-8, and it has no way to
repair it: the missing bytes are gone.  longname has the same issue with
its 80 bytes, and it is the string that ends up in /proc/asound/cards.

So this is not about adding a feature to a working field; the current
field can already produce a broken string, silently.

Who is affected
---------------

Users whose devices are named in their own language: a USB interface
sold in Japan, China, Korea or Russia, or a European product with an
umlaut or an accent in the vendor name.  32 bytes is 8 CJK characters,
and a vendor name plus a product name rarely fits in that.

What they see today is either a cut-off name or a name with a broken
character at the end, depending on the length.  Desktop stacks
(PipeWire, GNOME, KDE) show the string as-is, so the damage is visible
in the device picker.

I have not found an existing bug report for this, which I take as a
sign that it is a real but low-frequency annoyance rather than a fire.
That is part of what I am asking about.

The cheap option, which may well be the right one
-------------------------------------------------

Declare the existing fields UTF-8 and make the truncation stop cutting
inside a sequence.  No new fields, no new UAPI, one helper in the copy
path.  It fixes the "broken character" half of the problem immediately.

What it does not fix is the size: 32 bytes stays 8 CJK characters, so
the name is still cut, just cleanly.  And it retroactively gives an
encoding to a field that has been encoding-agnostic for 25 years, which
may or may not be acceptable to you.

If you think this is enough, I am happy to send just that.

The larger option
-----------------

Add UTF-8 successors of the three fields, kept alongside the ASCII ones
rather than replacing them, allocated on demand like card->components
now is.  Either side may be empty, so nothing may assume a name is
present and every reader keeps a fallback.  Drivers fill both and keep
them semantically in sync.

For user space this needs no new ioctl: SNDRV_CTL_IOCTL_CARD_BYTES
already carries a variable-length card string with a type discriminator
that was added for exactly this kind of extension, so three more type
values would do.  Nothing existing changes, and an old kernel returns
-EINVAL for an unknown type, which a reader can treat as "use the ASCII
field".

id, driver and components would deliberately keep no UTF-8 counterpart
for the time being. They are not display names: id is the unique handle 
and part of path
names, driver is what alsa-lib matches configuration against, and
components is a token list.

Questions
---------

1. Is this worth solving in the kernel, or should a desktop stack carry
    a name database and leave the kernel fields as they are?

2. If it is: cheap option, larger option, or both (the cheap one as a
    fix, the larger one as the long-term path)?

3. On limits.  For card->components you asked to drop the artificial
    size cap.  The same question applies here: a per-field byte limit
    (I used four times the ASCII field size, so the same number of
    characters always fits), or no limit at all with the ioctl reporting
    the length?

4. On validation.  The kernel cannot normalise to NFC without depending
    on CONFIG_UNICODE, and it cannot detect homoglyphs at all, so both
    stay recommendations.  It can cheaply reject malformed UTF-8, control
    characters, non-characters and the invisible/bidi formatting
    characters that are the spoofing vector one actually can catch.  Is
    that the right line, or should the kernel pass bytes through and
    leave all of it to user space?

5. Who would consume this?  A kernel-side field with no user is not
    worth your review time.  Should I take this to the alsa-lib and
    PipeWire people first and come back with their answer?

6. If the fields exist, does exposing them as read-only sysfs
    attributes on the card device make sense in addition to the ioctl
    (udev rules, inspecting a card before opening it), or is the ioctl
    alone the right surface?

Disclosure
----------

I have a working implementation of the larger option (core fields plus
validation, the CARD_BYTES types, KUnit coverage, usb-audio as the
first user, documentation).  I am deliberately not posting it yet
because the questions above decide its shape.  Say the word and I will
send it as an RFC series.

That implementation was written with the help of an LLM coding
assistant; per Documentation/process/coding-assistants.rst it will
carry an Assisted-by tag, and I will of course carry the
Signed-off-by and the responsibility for it.

Thanks,


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

end of thread, other threads:[~2026-09-15 12:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-14 16:46 [RFC] ALSA: how should a card name that is not ASCII be exposed? otzelot2021
2026-09-14 16:59 ` Jaroslav Kysela
2026-09-15 10:53   ` Takashi Iwai
2026-09-15 12:04     ` Jaroslav Kysela

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.