History

ALSA: control: add ioctl to retrieve full card components

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.

Maciej Strozek committed 3 months ago

Commit 86cac981 parent eaf46ee6 files · +120 −10Browse files

Showing the changes to include/uapi (1 of 6 files). Show all

Unified · Split

include/uapi/sound/asound.h+21−1
@@ -1058,7 +1058,7 @@ struct snd_timer_tread { · 1057 unmodified lines
10581058 * *
10591059 ****************************************************************************/
10601060
1061−#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 9)
1061+#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 10)
10621062
10631063 struct snd_ctl_card_info {
10641064 int card; /* card number */
@@ -1072,6 +1072,25 @@ struct snd_ctl_card_info { · 7 unmodified lines
10721072 unsigned char components[128]; /* card components / fine identification, delimited with one space (AC97 etc..) */
10731073 };
10741074
1075+/*
1076+ * Card components can exceed the fixed 128 bytes in snd_ctl_card_info.
1077+ * Use SNDRV_CTL_IOCTL_CARD_BYTES with type SND_CTL_CARD_BTYPE_COMPONENTS
1078+ * to retrieve the full string.
1079+ */
1080+
1081+/* Type values for struct snd_ctl_card_bytes::type */
1082+enum {
1083+ SND_CTL_CARD_BTYPE_COMPONENTS = 1, /* full card components string */
1084+};
1085+
1086+struct snd_ctl_card_bytes {
1087+ __u32 type; /* SND_CTL_CARD_BTYPE_* */
1088+ __u32 data_allocated; /* size of @data buffer in bytes */
1089+ __u32 data_len; /* in/out: actual data length in bytes */
1090+ __u32 reserved; /* explicit pad */
1091+ __u64 data; /* user buffer (pointer stored as __u64) */
1092+};
1093+
10751094 typedef int __bitwise snd_ctl_elem_type_t;
10761095 #define SNDRV_CTL_ELEM_TYPE_NONE ((__force snd_ctl_elem_type_t) 0) /* invalid */
10771096 #define SNDRV_CTL_ELEM_TYPE_BOOLEAN ((__force snd_ctl_elem_type_t) 1) /* boolean type */
@@ -1198,6 +1217,7 @@ struct snd_ctl_tlv { · 120 unmodified lines
11981217
11991218 #define SNDRV_CTL_IOCTL_PVERSION _IOR('U', 0x00, int)
12001219 #define SNDRV_CTL_IOCTL_CARD_INFO _IOR('U', 0x01, struct snd_ctl_card_info)
1220+#define SNDRV_CTL_IOCTL_CARD_BYTES _IOWR('U', 0x02, struct snd_ctl_card_bytes)
12011221 #define SNDRV_CTL_IOCTL_ELEM_LIST _IOWR('U', 0x10, struct snd_ctl_elem_list)
12021222 #define SNDRV_CTL_IOCTL_ELEM_INFO _IOWR('U', 0x11, struct snd_ctl_elem_info)
12031223 #define SNDRV_CTL_IOCTL_ELEM_READ _IOWR('U', 0x12, struct snd_ctl_elem_value)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t