Skip to content

control: ucm: add ioctl to retrieve full card components - #494

Closed
mstrozek wants to merge 1 commit into
alsa-project:masterfrom
mstrozek:components
Closed

mstrozek wants to merge 1 commit into
alsa-project:masterfrom
mstrozek:components

Conversation

@mstrozek

@mstrozek mstrozek commented Jan 22, 2026 •

Copy link
Copy Markdown
Contributor

The fixed-size components field in SNDRV_CTL_IOCTL_CARD_INFO can be too small on systems with many audio devices. The kernel [1] will provide a new ioctl to read the full string while truncating the original in card_info if it grows too big. Make sure alsa-lib can read the full string if the original is truncated.

[1] https://lore.kernel.org/all/20260303145815.9930-1-mstrozek@opensource.cirrus.com/

Signed-off-by: Maciej Strozek mstrozek@opensource.cirrus.com

mstrozek added a commit to mstrozek/alsa-utils that referenced this pull request Jan 22, 2026
Changes added to kernel [1] and alsa-lib [2] allow usage of an extended
components string, amend amixer to allow display of the new string.

[1] https://lore.kernel.org/all/20260122111249.67319-1-mstrozek@opensource.cirrus.com/
[2] alsa-project/alsa-lib#494
Signed-off-by: Maciej Strozek <mstrozek@opensource.cirrus.com>
@mstrozek
mstrozek marked this pull request as ready for review January 22, 2026 11:19
@perexg

perexg commented Jan 22, 2026

Copy link
Copy Markdown
Member

Thanks for your change, but the situation with new components string can be handled using new internal structure in alsa-lib like:

diff --git a/include/local.h b/include/local.h
index a6996759..97701754 100644
--- a/include/local.h
+++ b/include/local.h
@@ -101,7 +101,19 @@
 #define _snd_pcm_sw_params snd_pcm_sw_params
 #define _snd_pcm_status snd_pcm_status
 
-#define _snd_ctl_card_info snd_ctl_card_info
+/* V2 structure - increased components string from 128 bytes to 512 bytes */
+struct _snd_ctl_card_info {
+       int card;                       /* card number */
+       int pad;                        /* reserved for future (was type) */
+       unsigned char id[16];           /* ID of card (user selectable) */
+       unsigned char driver[16];       /* Driver name */
+       unsigned char name[32];         /* Short name of soundcard */
+       unsigned char longname[80];     /* name + info text about soundcard */
+       unsigned char reserved_[16];    /* reserved for future (was ID of mixer) */
+       unsigned char mixername[80];    /* visual mixer identification */
+       unsigned char components[512];  /* card components / fine identification, delimited with one space (AC97 etc..) */
+};
+
 #define _snd_ctl_elem_id snd_ctl_elem_id
 #define _snd_ctl_elem_list snd_ctl_elem_list
 #define _snd_ctl_elem_info snd_ctl_elem_info
diff --git a/src/control/control_hw.c b/src/control/control_hw.c
index 962cd796..30825a80 100644
--- a/src/control/control_hw.c
+++ b/src/control/control_hw.c
@@ -129,10 +129,14 @@ static int snd_ctl_hw_subscribe_events(snd_ctl_t *handle, int subscribe)
 static int snd_ctl_hw_card_info(snd_ctl_t *handle, snd_ctl_card_info_t *info)
 {
        snd_ctl_hw_t *hw = handle->private_data;
-       if (ioctl(hw->fd, SNDRV_CTL_IOCTL_CARD_INFO, info) < 0) {
+       struct snd_ctl_card_info kinfo;
+       if (ioctl(hw->fd, SNDRV_CTL_IOCTL_CARD_INFO, &kinfo) < 0) {
                snd_errornum(CONTROL, "SNDRV_CTL_IOCTL_CARD_INFO failed");
                return -errno;
        }
+       snd_ctl_card_info_clear(info);
+       ... copy data from kinfo to info here..
+       ... if necessary ('>' postfix in the components string) - call SNDRV_CTL_IOCTL_CARD_COMPONENTS ...
        return 0;
 }

Difference for memory allocations should be already covered using snd_ctl_card_info_sizeof(), snd_ctl_card_info_alloca() and snd_ctl_card_info_malloc() functions.

@mstrozek
mstrozek marked this pull request as draft January 29, 2026 10:45
@mstrozek
mstrozek force-pushed the components branch 2 times, most recently from d90ae37 to e1352ee Compare February 19, 2026 13:51
Comment thread src/control/control_hw.c Resolved
Comment thread src/control/control_hw.c Resolved
Comment thread src/control/control_hw.c Resolved
Comment thread src/control/control_hw.c Resolved
Comment thread src/control/control_hw.c Resolved
@mstrozek
mstrozek force-pushed the components branch 3 times, most recently from bdbc0d4 to 1ab0036 Compare February 24, 2026 14:02
@mstrozek
mstrozek requested a review from perexg February 24, 2026 14:03
Comment thread include/local.h Resolved
@mstrozek
mstrozek requested a review from perexg February 24, 2026 16:01
@mstrozek
mstrozek marked this pull request as ready for review March 3, 2026 15:01
externalmirrors-syncer Bot pushed a commit to external-mirrors/linux-next that referenced this pull request Aug 5, 2026
The fixed-size components field in SNDRV_CTL_IOCTL_CARD_INFO can be too
small on systems with many audio devices.

Keep the existing struct snd_ctl_card_info ABI intact and add a new
ioctl SNDRV_CTL_IOCTL_CARD_BYTES that carries a variable-length payload
selected by a type discriminator. The first defined type
SND_CTL_CARD_BTYPE_COMPONENTS returns the full components string. The
ioctl is designed to be reused for other variable-length card payloads
in the future.

The user-space caller may set data_allocated == 0 (or data == NULL) to
query the required length; otherwise the kernel copies the payload into
the user buffer and writes back the actual length in data_len.

When the legacy components field in struct snd_ctl_card_info is
truncated, '>' is written just before the NUL terminator to signal to
user-space that the full string is available via the new ioctl.

card->components is now dynamically allocated and grown in 32 byte
increments via krealloc(), capped at 512 bytes.

Link: alsa-project/alsa-lib#494
Suggested-by: Jaroslav Kysela <perex@perex.cz>
Suggested-by: Takashi Iwai <tiwai@suse.com>
Signed-off-by: Maciej Strozek <mstrozek@opensource.cirrus.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20260720103505.1860399-2-mstrozek@opensource.cirrus.com
@perexg

perexg commented Nov 30, 2026

Copy link
Copy Markdown
Member

@mstrozek : Could you sync with the merged kernel code ? Thank you

@github-actions github-actions Bot added the signed off by Missing Signed-off-by: line. label Nov 30, 2026
@mstrozek
mstrozek marked this pull request as draft November 30, 2026 14:41
The fixed-size components field in SNDRV_CTL_IOCTL_CARD_INFO can be too
small on systems with many audio devices. The kernel [1] will provide a
new ioctl to read the full string while truncating the original in
card_info if it grows too big. Make sure alsa-lib can read the full
string if the original is truncated.

[1] https://lore.kernel.org/all/20260430110302.3745917-2-mstrozek@opensource.cirrus.com/

Signed-off-by: Maciej Strozek <mstrozek@opensource.cirrus.com>
@github-actions github-actions Bot removed the signed off by Missing Signed-off-by: line. label Nov 30, 2026
@mstrozek
mstrozek marked this pull request as ready for review November 30, 2026 16:08
@mstrozek

Copy link
Copy Markdown
Contributor Author

@mstrozek : Could you sync with the merged kernel code ? Thank you

Updated, please have a look. New __u32 fields, also added a check for SNDRV_PROTOCOL_VERSION to be sure and corrected one error return.

@perexg perexg closed this in ef43278 Nov 30, 2026
@perexg

perexg commented Nov 30, 2026

Copy link
Copy Markdown
Member

Thanks. Merged with the updated kernel patch link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants