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.
Showing the changes to include/uapi (1 of 6 files). Show all
Unified · Split
| @@ -1058,7 +1058,7 @@ struct snd_timer_tread { · 1057 unmodified lines | ||
| 1058 | 1058 | * * |
| 1059 | 1059 | ****************************************************************************/ |
| 1060 | 1060 | |
| 1061 | −#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 9) | |
| 1061 | +#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 10) | |
| 1062 | 1062 | |
| 1063 | 1063 | struct snd_ctl_card_info { |
| 1064 | 1064 | int card; /* card number */ |
| @@ -1072,6 +1072,25 @@ struct snd_ctl_card_info { · 7 unmodified lines | ||
| 1072 | 1072 | unsigned char components[128]; /* card components / fine identification, delimited with one space (AC97 etc..) */ |
| 1073 | 1073 | }; |
| 1074 | 1074 | |
| 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 | + | |
| 1075 | 1094 | typedef int __bitwise snd_ctl_elem_type_t; |
| 1076 | 1095 | #define SNDRV_CTL_ELEM_TYPE_NONE ((__force snd_ctl_elem_type_t) 0) /* invalid */ |
| 1077 | 1096 | #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 | ||
| 1198 | 1217 | |
| 1199 | 1218 | #define SNDRV_CTL_IOCTL_PVERSION _IOR('U', 0x00, int) |
| 1200 | 1219 | #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) | |
| 1201 | 1221 | #define SNDRV_CTL_IOCTL_ELEM_LIST _IOWR('U', 0x10, struct snd_ctl_elem_list) |
| 1202 | 1222 | #define SNDRV_CTL_IOCTL_ELEM_INFO _IOWR('U', 0x11, struct snd_ctl_elem_info) |
| 1203 | 1223 | #define SNDRV_CTL_IOCTL_ELEM_READ _IOWR('U', 0x12, struct snd_ctl_elem_value) |