ALSA: control: tidy up whitespaces
PATCH v3 1/2 ALSA: control: tidy up whitespaces
Clean up trailing whitespaces by the way of changing card components array.
--- sound/core/control_compat.c | 2 +- sound/core/init.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
sound/core/control_compat.c +1 -1
@@ -417,7 +417,7 @@ static int snd_ctl_elem_add_compat(struct snd_ctl_file *file,break ; }return snd_ctl_elem_add (file, data, replace); -} +}enum { SNDRV_CTL_IOCTL_ELEM_LIST32 = _IOWR('U', 0x10, struct snd_ctl_elem_list32),
sound/core/init.c +2 -2
@@ -722,7 +722,7 @@ static void snd_card_set_id_no_lock(struct snd_card *card, const char *src,int len, loops;bool is_default = false;char *id; - +copy_valid_id_string (card, src, nid); id = card->id;
@@ -1031,7 +1031,7 @@ int __init snd_card_info_init(void)* * Return: Zero otherwise a negative error code. */ - +int snd_component_add (struct snd_card *card,const char *component) {char *ptr;
--
2.48.1
PATCH v3 2/2 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 to retrieve the full components string.
When the legacy components field is truncated, append '>' to indicate that the full string is available via the new ioctl.
---
Changes for v3:
- change components field to a dynamic array resizable in 32 byte increments
- removed SNDRV_CTL_COMPONENTS_LEN define
- sanity check if 'components' requests more than 512 bytes
- added a commit to clean up trailing whitespaces
- alsa-utils link no longer needed
Changes for v2:
- do not modify existing card->components field
- add a new ioctl and struct to keep the full components string
- handle the split/trim in snd_ctl_card_info()
--- include/sound/core.h | 4 ++-- include/uapi/sound/asound.h | 14 ++++++++++++- sound/core/control.c | 35 ++++++++++++++++++++++++++++++++- sound/core/control_compat.c | 2 ++ sound/core/init.c | 39 +++++++++++++++++++++++++++++-------- 5 files changed, 82 insertions(+), 12 deletions(-)
include/sound/core.h +2 -2
@@ -87,8 +87,8 @@ struct snd_card {char longname[80 ];/* name of this soundcard */ char irq_descr[32 ];/* Interrupt description */ char mixername[80 ];/* mixer name */ -char components[128 ];/* card components delimited with -space */ +char *components_ptr; +unsigned int components_ptr_alloc_size;// current memory allocation components_ptr. struct module *module;/* top-level module */ void *private_data;/* private data for soundcard */
include/uapi/sound/asound.h +13 -1
@@ -1058,7 +1058,7 @@ struct snd_timer_tread {* * ****************************************************************************/ -#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 9) +#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 10)struct snd_ctl_card_info {int card;/* card number */
@@ -1072,6 +1072,17 @@ struct snd_ctl_card_info {unsigned char components[128 ];/* card components / fine identification, delimited with one space (AC97 etc..) */ }; +/* +* Card components can exceed the fixed 128 bytes in snd_ctl_card_info. +* Use SNDRV_CTL_IOCTL_CARD_COMPONENTS to retrieve the full string. +* +*/ +struct snd_ctl_card_components { +int card; +unsigned int length; +unsigned char *components; +}; +typedef int __bitwise snd_ctl_elem_type_t ;#define SNDRV_CTL_ELEM_TYPE_NONE ((__force snd_ctl_elem_type_t) 0)/* invalid */ #define SNDRV_CTL_ELEM_TYPE_BOOLEAN ((__force snd_ctl_elem_type_t) 1)/* boolean type */
@@ -1198,6 +1209,7 @@ struct snd_ctl_tlv {#define SNDRV_CTL_IOCTL_PVERSION _IOR('U', 0x00, int)#define SNDRV_CTL_IOCTL_CARD_INFO _IOR('U', 0x01, struct snd_ctl_card_info) +#define SNDRV_CTL_IOCTL_CARD_COMPONENTS _IOWR('U', 0x02, struct snd_ctl_card_components)#define SNDRV_CTL_IOCTL_ELEM_LIST _IOWR('U', 0x10, struct snd_ctl_elem_list)#define SNDRV_CTL_IOCTL_ELEM_INFO _IOWR('U', 0x11, struct snd_ctl_elem_info)#define SNDRV_CTL_IOCTL_ELEM_READ _IOWR('U', 0x12, struct snd_ctl_elem_value)
sound/core/control.c +34 -1
@@ -876,9 +876,13 @@ static int snd_ctl_card_info(struct snd_card *card, struct snd_ctl_file * ctl, { struct snd_ctl_card_info *info __free(kfree) =kzalloc (sizeof (*info),GFP_KERNEL ); +ssize_t n;if (! info)return -ENOMEM ; + +static_assert (sizeof (info->components) >=2 ); + scoped_guard(rwsem_read, &snd_ioctl_rwsem) { info->card = card->number;strscpy (info->id, card->id,sizeof (info->id));
@@ -886,13 +890,40 @@ static int snd_ctl_card_info(struct snd_card *card, struct snd_ctl_file * ctl,strscpy (info->name, card->shortname,sizeof (info->name));strscpy (info->longname, card->longname,sizeof (info->longname));strscpy (info->mixername, card->mixername,sizeof (info->mixername)); -strscpy (info->components, card->components,sizeof (info->components)); + n =strscpy (info->components, card->components_ptr,sizeof (info->components)); +if (n <0 )// mark the truncation with '>' before NULL terminator + info->components[sizeof (info->components) -2 ] ='>' ; }if (copy_to_user (arg, info,sizeof (struct snd_ctl_card_info )))return -EFAULT ;return 0 ; } +static int snd_ctl_card_components (struct snd_card *card, +struct snd_ctl_card_components __user *_info) +{ +struct snd_ctl_card_components info; +unsigned int copy_len; + +if (copy_from_user (&info, _info,sizeof (info))) +return -EFAULT ; +if (!info.components) +return -EINVAL ; + + scoped_guard(rwsem_read, &snd_ioctl_rwsem) { + copy_len =strlen (card->components_ptr) +1 ; + info.card = card->number; + info.length = copy_len; +if (copy_to_user (info.components, card->components_ptr, copy_len)) +return -EFAULT ; + } + +if (copy_to_user (_info, &info,sizeof (info))) +return -EFAULT ; + +return 0 ; +} +static int snd_ctl_elem_list (struct snd_card *card,struct snd_ctl_elem_list *list) {
@@ -1988,6 +2019,8 @@ static long snd_ctl_ioctl(struct file *file, unsigned int cmd, unsigned long argreturn put_user (SNDRV_CTL_VERSION , ip) ? -EFAULT :0 ;case SNDRV_CTL_IOCTL_CARD_INFO :return snd_ctl_card_info (card, ctl, cmd, argp); +case SNDRV_CTL_IOCTL_CARD_COMPONENTS : +return snd_ctl_card_components (card, argp);case SNDRV_CTL_IOCTL_ELEM_LIST :return snd_ctl_elem_list_user (card, argp);case SNDRV_CTL_IOCTL_ELEM_INFO :
sound/core/control_compat.c +2 -0
@@ -456,6 +456,8 @@ static inline long snd_ctl_ioctl_compat(struct file *file, unsigned int cmd, unscase SNDRV_CTL_IOCTL_TLV_WRITE :case SNDRV_CTL_IOCTL_TLV_COMMAND :return snd_ctl_ioctl (file, cmd, (unsigned long )argp); +case SNDRV_CTL_IOCTL_CARD_COMPONENTS : +return snd_ctl_card_components (ctl->card, argp);case SNDRV_CTL_IOCTL_ELEM_LIST32 :return snd_ctl_elem_list_compat (ctl->card, argp);case SNDRV_CTL_IOCTL_ELEM_INFO32 :
sound/core/init.c +31 -8
@@ -590,6 +590,8 @@ static int snd_card_do_free(struct snd_card *card)snd_mixer_oss_notify_callback (card,SND_MIXER_OSS_NOTIFY_FREE );#endif snd_device_free_all (card); +kfree (card->components_ptr); + card->components_ptr_alloc_size =0 ;if (card->private_free) card->private_free (card);#ifdef CONFIG_SND_CTL_DEBUG
@@ -1036,19 +1038,40 @@ int snd_component_add(struct snd_card *card, const char *component) {char *ptr;int len =strlen (component); +unsigned int cur_len, need_len; - ptr =strstr (card->components, component); -if (ptr !=NULL ) { -if (ptr[len] =='\0' || ptr[len] ==' ' )/* already there */ -return 1 ; +if (card->components_ptr) { + ptr =strstr (card->components_ptr, component); +if (ptr) { +if (ptr[len] =='\0' || ptr[len] ==' ' )/* already there */ +return 1 ; + } + cur_len =strlen (card->components_ptr) +1 ; + }else { + cur_len =0 ; } -if (strlen (card->components) +1 + len +1 >sizeof (card->components)) { + + need_len = cur_len + len +1 ; +if (need_len >512 ) {snd_BUG ();return -ENOMEM ; } -if (card->components[0 ] !='\0' ) -strcat (card->components," " ); -strcat (card->components, component); + +if (need_len > card->components_ptr_alloc_size) { +unsigned int new_alloc =roundup (need_len,32 ); + + ptr =krealloc (card->components_ptr, new_alloc,GFP_KERNEL ); +if (!ptr) +return -ENOMEM ; +if (!card->components_ptr) + ptr[0 ] ='\0' ; + card->components_ptr = ptr; + card->components_ptr_alloc_size = new_alloc; + } + +if (card->components_ptr[0 ] !='\0' ) +strcat (card->components_ptr," " ); +strcat (card->components_ptr, component);return 0 ; }EXPORT_SYMBOL (snd_component_add);
--
2.48.1
Re: [PATCH v3 2/2] ALSA: control: add ioctl to retrieve full card components
Quoted 65 lines · Maciej Strozek
The fixed-size components field in
SNDRV_CTL_IOCTL_CARD_INFOcan be too small on systems with many audio devices.Keep the existing struct
snd_ctl_card_infoABI intact and add a new ioctl to retrieve the full components string.When the legacy components field is truncated, append '>' to indicate that the full string is available via the new ioctl.
Suggested-by Jaroslav Kysela <[email protected]>Suggested-by Takashi Iwai <[email protected]>Signed-off-by Maciej Strozek <[email protected]>---
Changes for v3:
- change components field to a dynamic array resizable in 32 byte increments
- removedSNDRV_CTL_COMPONENTS_LENdefine
- sanity check if 'components' requests more than 512 bytes
- added a commit to clean up trailing whitespaces
- alsa-utils link no longer needed
Changes for v2:
- do not modify existingcard->componentsfield
- add a new ioctl and struct to keep the full components string
- handle the split/trim insnd_ctl_card_info()--- include/sound/core.h | 4 ++-- include/uapi/sound/asound.h | 14 ++++++++++++- sound/core/control.c | 35 ++++++++++++++++++++++++++++++++- sound/core/control_compat.c | 2 ++ sound/core/init.c | 39 +++++++++++++++++++++++++++++-------- 5 files changed, 82 insertions(+), 12 deletions(-)include/sound/core.h +2
-2@@ -87,8 +87,8 @@ struct snd_card {char longname[80 ];/* name of this soundcard */ char irq_descr[32 ];/* Interrupt description */ char mixername[80 ];/* mixer name */ -char components[128 ];/* card components delimited with -space */ +char *components_ptr; +unsigned int components_ptr_alloc_size;// current memory allocation components_ptr. struct module *module;/* top-level module */ void *private_data;/* private data for soundcard */ include/uapi/sound/asound.h +1
-1@@ -1058,7 +1058,7 @@ struct snd_timer_tread {* * ****************************************************************************/ -#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 9) +#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 10)struct snd_ctl_card_info {int card;/* card number */ @@ -1072,6 +1072,17 @@ struct snd_ctl_card_info {unsigned char components[128 ];/* card components / fine identification, delimited with one space (AC97 etc..) */ };
include/uapi/sound/asound.h struct snd_ctl_card_info { · line 1084
Quoted 10 lines
include/uapi/sound/asound.h +10
-0+/* +* Card components can exceed the fixed 128 bytes in snd_ctl_card_info. +* Use SNDRV_CTL_IOCTL_CARD_COMPONENTS to retrieve the full string. +* +*/ +struct snd_ctl_card_components { +int card; +unsigned int length; +unsigned char *components; +};
Embedding a pointer for ioctl is a nightmare for 32bit compatibility, and you seem to have forgotten it, too ;)
IMO, in this case, it'd be easier to use a flex array instead, e.g.
struct snd_ctl_card_components {
int card;
unsigned int length;
unsigned char components[];
};And the ioctl can serve for two purposes:
- When length=0 is set, the kernel stores the current number of bytes and returns without copying. User-space can use this mode for allocating the buffer.
- When length > 0 is set, the kernel copies the data on components[] up to the given length. The length field is updated again to store the number of bytes (which would be copied).
What this length field specifies is another question: is it a string length or a buffer length including NUL?
Also, we can keep the current string size, too, for returning in the sequence in the above, instead of doing strlen() at each time.
thanks,
Takashi
Jaroslav Kysela
maintainerRe: [PATCH v3 2/2] ALSA: control: add ioctl to retrieve full card components
Quoted 67 lines · Takashi Iwai
Quoted 65 lines · Maciej Strozek
The fixed-size components field in
SNDRV_CTL_IOCTL_CARD_INFOcan be too small on systems with many audio devices.Keep the existing struct
snd_ctl_card_infoABI intact and add a new ioctl to retrieve the full components string.When the legacy components field is truncated, append '>' to indicate that the full string is available via the new ioctl.
Suggested-by Jaroslav Kysela <[email protected]>Suggested-by Takashi Iwai <[email protected]>Signed-off-by Maciej Strozek <[email protected]>---
Changes for v3:
- change components field to a dynamic array resizable in 32 byte increments
- removedSNDRV_CTL_COMPONENTS_LENdefine
- sanity check if 'components' requests more than 512 bytes
- added a commit to clean up trailing whitespaces
- alsa-utils link no longer needed
Changes for v2:
- do not modify existingcard->componentsfield
- add a new ioctl and struct to keep the full components string
- handle the split/trim insnd_ctl_card_info()--- include/sound/core.h | 4 ++-- include/uapi/sound/asound.h | 14 ++++++++++++- sound/core/control.c | 35 ++++++++++++++++++++++++++++++++- sound/core/control_compat.c | 2 ++ sound/core/init.c | 39 +++++++++++++++++++++++++++++-------- 5 files changed, 82 insertions(+), 12 deletions(-)include/sound/core.h +2
-2@@ -87,8 +87,8 @@ struct snd_card {char longname[80 ];/* name of this soundcard */ char irq_descr[32 ];/* Interrupt description */ char mixername[80 ];/* mixer name */ -char components[128 ];/* card components delimited with -space */ +char *components_ptr; +unsigned int components_ptr_alloc_size;// current memory allocation components_ptr. struct module *module;/* top-level module */ void *private_data;/* private data for soundcard */ include/uapi/sound/asound.h +1
-1@@ -1058,7 +1058,7 @@ struct snd_timer_tread {* * ****************************************************************************/ -#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 9) +#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 10)struct snd_ctl_card_info {int card;/* card number */ @@ -1072,6 +1072,17 @@ struct snd_ctl_card_info {unsigned char components[128 ];/* card components / fine identification, delimited with one space (AC97 etc..) */ };
Quoted 13 lines
include/uapi/sound/asound.h struct snd_ctl_card_info { · line 1084
Quoted 10 lines
include/uapi/sound/asound.h +10
-0+/* +* Card components can exceed the fixed 128 bytes in snd_ctl_card_info. +* Use SNDRV_CTL_IOCTL_CARD_COMPONENTS to retrieve the full string. +* +*/ +struct snd_ctl_card_components { +int card; +unsigned int length; +unsigned char *components; +};Embedding a pointer for ioctl is a nightmare for 32bit compatibility, and you seem to have forgotten it, too ;)
It's doable and we have other more important structures like struct snd_xferi using those pointers. But yes, the translation is missing in this patch set. I already gave hint that control_compat.c must be modified, too.
Quoted 7 lines
IMO, in this case, it'd be easier to use a flex array instead, e.g.
struct snd_ctl_card_components { int card; unsigned int length; unsigned char components[]; };
There is an issue that flex arrays will break _IOC_SIZE().
Jaroslav
Signature · 2 lines
Jaroslav Kysela <[email protected]> Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
Re: [PATCH v3 2/2] ALSA: control: add ioctl to retrieve full card components
Quoted 90 lines · Jaroslav Kysela
Quoted 67 lines · Takashi Iwai
Quoted 65 lines · Maciej Strozek
The fixed-size components field in
SNDRV_CTL_IOCTL_CARD_INFOcan be too small on systems with many audio devices.Keep the existing struct
snd_ctl_card_infoABI intact and add a new ioctl to retrieve the full components string.When the legacy components field is truncated, append '>' to indicate that the full string is available via the new ioctl.
Suggested-by Jaroslav Kysela <[email protected]>Suggested-by Takashi Iwai <[email protected]>Signed-off-by Maciej Strozek <[email protected]>---
Changes for v3:
- change components field to a dynamic array resizable in 32 byte increments
- removedSNDRV_CTL_COMPONENTS_LENdefine
- sanity check if 'components' requests more than 512 bytes
- added a commit to clean up trailing whitespaces
- alsa-utils link no longer needed
Changes for v2:
- do not modify existingcard->componentsfield
- add a new ioctl and struct to keep the full components string
- handle the split/trim insnd_ctl_card_info()--- include/sound/core.h | 4 ++-- include/uapi/sound/asound.h | 14 ++++++++++++- sound/core/control.c | 35 ++++++++++++++++++++++++++++++++- sound/core/control_compat.c | 2 ++ sound/core/init.c | 39 +++++++++++++++++++++++++++++-------- 5 files changed, 82 insertions(+), 12 deletions(-)include/sound/core.h +2
-2@@ -87,8 +87,8 @@ struct snd_card {char longname[80 ];/* name of this soundcard */ char irq_descr[32 ];/* Interrupt description */ char mixername[80 ];/* mixer name */ -char components[128 ];/* card components delimited with -space */ +char *components_ptr; +unsigned int components_ptr_alloc_size;// current memory allocation components_ptr. struct module *module;/* top-level module */ void *private_data;/* private data for soundcard */ include/uapi/sound/asound.h +1
-1@@ -1058,7 +1058,7 @@ struct snd_timer_tread {* * ****************************************************************************/ -#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 9) +#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 10)struct snd_ctl_card_info {int card;/* card number */ @@ -1072,6 +1072,17 @@ struct snd_ctl_card_info {unsigned char components[128 ];/* card components / fine identification, delimited with one space (AC97 etc..) */ };Quoted 13 lines
include/uapi/sound/asound.h struct snd_ctl_card_info { · line 1084
Quoted 10 lines
include/uapi/sound/asound.h +10
-0+/* +* Card components can exceed the fixed 128 bytes in snd_ctl_card_info. +* Use SNDRV_CTL_IOCTL_CARD_COMPONENTS to retrieve the full string. +* +*/ +struct snd_ctl_card_components { +int card; +unsigned int length; +unsigned char *components; +};Embedding a pointer for ioctl is a nightmare for 32bit compatibility, and you seem to have forgotten it, too ;)
It's doable and we have other more important structures like struct
snd_xferiusing those pointers. But yes, the translation is missing in this patch set. I already gave hint thatcontrol_compat.cmust be modified, too.Quoted 2 lines
IMO, in this case, it'd be easier to use a flex array instead, e.g.
Quoted 7 lines
Quoted 5 lines
struct snd_ctl_card_components { int card; unsigned int length; unsigned char components[]; };There is an issue that flex arrays will break
_IOC_SIZE().
That's true. OTOH, having a pointer for the external data to be copied means that _IOC_SIZE() doesn't cover the whole size but misses the data, too. So it's a question which implementation is uglier (or easier to handle), after all.
BTW, it might be better to have both length and actual_length fields in srtuct snd_ctl_card_components: the former specifies the allocated buffer length while the latter is stored by kernel pointing to the actual data size. We can overwrite length field in return, but it might be confusing when releasing a resource.
thanks,
Takashi
Re: [PATCH v3 2/2] ALSA: control: add ioctl to retrieve full card components
In reply to Takashi IwaiW dniu wto, 03.03.2026 o godzinie 16∶47 +0100, użytkownik Takashi Iwai
Quoted 10 lines · napisał:
include/uapi/sound/asound.h struct snd_ctl_card_info { · line 1084
Quoted 7 lines
+ */
include/uapi/sound/asound.h +5
-0+struct snd_ctl_card_components { +int card; +unsigned int length; +unsigned char *components; +};And the ioctl can serve for two purposes:
Quoted 4 lines
- When length=0 is set, the kernel stores the current number of bytes and returns without copying. User-space can use this mode for allocating the buffer.
In alsa-lib all data must be allocated beforehand, so this length==0 query is not very useful there, it will just go into a [512] array anyway. Are there any other users that may benefit from this?
Signature · 2 lines
Regards, Maciej
Re: [PATCH v3 2/2] ALSA: control: add ioctl to retrieve full card components
Quoted 13 lines · Maciej Strozek
W dniu wto, 03.03.2026 o godzinie 16∶47 +0100, użytkownik Takashi Iwai
Quoted 10 lines · napisał:
include/uapi/sound/asound.h struct snd_ctl_card_info { · line 1084
Quoted 7 lines
+ */
include/uapi/sound/asound.h +5
-0+struct snd_ctl_card_components { +int card; +unsigned int length; +unsigned char *components; +};And the ioctl can serve for two purposes:
Quoted 7 lines
Quoted 4 lines
- When length=0 is set, the kernel stores the current number of bytes and returns without copying. User-space can use this mode for allocating the buffer.
In alsa-lib all data must be allocated beforehand, so this length==0 query is not very useful there, it will just go into a [512] array anyway. Are there any other users that may benefit from this?
My suggested API can work even with the fixed size 512, too, if 512 is hight enough. It's just more flexible. And there is no restriction about alsa-lib data allocation; the function can query the size then allocate, too.
Takashi
Re: [PATCH v3 2/2] ALSA: control: add ioctl to retrieve full card components
W dniu czw, 05.03.2026 o godzinie 11∶04 +0100, użytkownik Takashi Iwai
Quoted 26 lines · napisał:
Quoted 19 lines · Maciej Strozek
W dniu wto, 03.03.2026 o godzinie 16∶47 +0100, użytkownik Takashi Iwai
Quoted 10 lines · napisał:
include/uapi/sound/asound.h struct snd_ctl_card_info { · line 1084
Quoted 7 lines
+ */
include/uapi/sound/asound.h +5
-0+struct snd_ctl_card_components { +int card; +unsigned int length; +unsigned char *components; +};And the ioctl can serve for two purposes:
Quoted 5 lines
- When length=0 is set, the kernel stores the current number of bytes
and returns without copying. User-space can use this mode for allocating the buffer.Quoted 4 lines
In alsa-lib all data must be allocated beforehand, so this length==0
query is not very useful there, it will just go into a [512] array anyway. Are there any other users that may benefit from this?
Quoted 8 lines
My suggested API can work even with the fixed size 512, too, if 512 is
hight enough. It's just more flexible. And there is no restriction about alsa-lib data allocation; the function can query the size then allocate, too.Takashi
OK, will prepare v4 with this, thanks
Signature · 2 lines
Regards, Maciej
Re: [PATCH v3 2/2] ALSA: control: add ioctl to retrieve full card components
Quoted 36 lines · Maciej Strozek
W dniu czw, 05.03.2026 o godzinie 11∶04 +0100, użytkownik Takashi Iwai
Quoted 33 lines · napisał:
Quoted 19 lines · Maciej Strozek
W dniu wto, 03.03.2026 o godzinie 16∶47 +0100, użytkownik Takashi Iwai
Quoted 10 lines · napisał:
include/uapi/sound/asound.h struct snd_ctl_card_info { · line 1084
Quoted 7 lines
+ */
include/uapi/sound/asound.h +5
-0+struct snd_ctl_card_components { +int card; +unsigned int length; +unsigned char *components; +};And the ioctl can serve for two purposes:
Quoted 5 lines
- When length=0 is set, the kernel stores the current number of bytes
and returns without copying. User-space can use this mode for allocating the buffer.Quoted 4 lines
In alsa-lib all data must be allocated beforehand, so this length==0
query is not very useful there, it will just go into a [512] array anyway. Are there any other users that may benefit from this?My suggested API can work even with the fixed size 512, too, if 512 is
hight enough. It's just more flexible. And there is no restriction about alsa-lib data allocation; the function can query the size then allocate, too.
Quoted 3 lines
Quoted 1 line
Takashi
OK, will prepare v4 with this, thanks
Well, let's see how others think, too. The API design needs more considerations because we can't change it any longer once after defined.
thanks,
Takashi
Jaroslav Kysela
maintainerRe: [PATCH v3 2/2] ALSA: control: add ioctl to retrieve full card components
Quoted 38 lines · Takashi Iwai
Quoted 36 lines · Maciej Strozek
W dniu czw, 05.03.2026 o godzinie 11∶04 +0100, użytkownik Takashi Iwai
Quoted 33 lines · napisał:
Quoted 19 lines · Maciej Strozek
W dniu wto, 03.03.2026 o godzinie 16∶47 +0100, użytkownik Takashi Iwai
Quoted 10 lines · napisał:
include/uapi/sound/asound.h struct snd_ctl_card_info { · line 1084
Quoted 7 lines
+ */
include/uapi/sound/asound.h +5
-0+struct snd_ctl_card_components { +int card; +unsigned int length; +unsigned char *components; +};And the ioctl can serve for two purposes:
Quoted 5 lines
- When length=0 is set, the kernel stores the current number of bytes
and returns without copying. User-space can use this mode for allocating the buffer.Quoted 4 lines
In alsa-lib all data must be allocated beforehand, so this length==0
query is not very useful there, it will just go into a [512] array anyway. Are there any other users that may benefit from this?My suggested API can work even with the fixed size 512, too, if 512 is
hight enough. It's just more flexible. And there is no restriction about alsa-lib data allocation; the function can query the size then allocate, too.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Takashi
OK, will prepare v4 with this, thanks
Well, let's see how others think, too. The API design needs more considerations because we can't change it any longer once after defined.
I think that the indirect pointer in ioctl structure is the best at the moment unless we decide to use the fixed char array. But (for discussion) we may try to be a bit clever and define universal bytes ioctl which may carry also other things in future like:
enum {
SND_CTL_CARD_BTYPE_COMPONENTS = 1
};
struct snd_ctl_card_bytes {
unsigned int card; // this is duplication with info ioctl
// to be removed?
unsigned int type; // e.g. SND_CTL_CARD_BTYPE_COMPONENTS
unsigned int data_allocated; // overall size of data
unsigned int data_len; // actual data len
unsigned char *data; // pointer to data array
};
Scenarios:
data_allocated = 0 or data == NULL -> driver just returns data_len data_allocated < data_len -> driver returns -ENOMEM data_allocated >= data_len -> driver will copy data
Note that data_len will be zero from the user space for read operations (driver knows it). But we can eventually use this ioctl to set some data in future, so data_len/data will be used for the write operation.
Jaroslav
Signature · 2 lines
Jaroslav Kysela <[email protected]> Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
Re: [PATCH v3 2/2] ALSA: control: add ioctl to retrieve full card components
Quoted 42 lines · Jaroslav Kysela
Quoted 40 lines · Takashi Iwai
Quoted 38 lines · Maciej Strozek
W dniu czw, 05.03.2026 o godzinie 11∶04 +0100, użytkownik Takashi Iwai
Quoted 34 lines · napisał:
Quoted 19 lines · Maciej Strozek
W dniu wto, 03.03.2026 o godzinie 16∶47 +0100, użytkownik Takashi Iwai
Quoted 10 lines · napisał:
Review
Quoted 7 lines
+ */
(quoted diff) +5
-0+struct snd_ctl_card_components { + int card; + unsigned int length; + unsigned char *components; +};And the ioctl can serve for two purposes:
Quoted 5 lines
- When length=0 is set, the kernel stores the current number of bytes
and returns without copying. User-space can use this mode for allocating the buffer.Quoted 4 lines
In alsa-lib all data must be allocated beforehand, so this length==0
query is not very useful there, it will just go into a [512] array anyway. Are there any other users that may benefit from this?My suggested API can work even with the fixed size 512, too, if 512 is
hight enough. It's just more flexible. And there is no restriction about alsa-lib data allocation; the function can query the size then allocate, too.Takashi
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
OK, will prepare v4 with this, thanks
Well, let's see how others think, too. The API design needs more considerations because we can't change it any longer once after defined.
I think that the indirect pointer in ioctl structure is the best at the moment unless we decide to use the fixed char array.
OK, it might be indeed better if the user-space API is something like:
int snd_ctl_card_components(snd_ctl_t *ctl, unsigned char *buf, size_t len);
Then it's simpler to pass the pointer as is without copying.
Quoted 7 lines
But (for
discussion) we may try to be a bit clever and define universal bytes ioctl which may carry also other things in future like:enum {
SND_CTL_CARD_BTYPE_COMPONENTS= 1
};
So this is for future extensions?
Quoted 3 lines
struct snd_ctl_card_bytes {
unsigned int card; // this is duplication with info ioctl
// to be removed?Right, it sounds like superfluous. I thought we were to allow extracting a card info for a different card number, but it doesn't look so.
Quoted 8 lines
unsigned int type; // e.g.
SND_CTL_CARD_BTYPE_COMPONENTS
unsigned intdata_allocated; // overall size of data
unsigned intdata_len; // actual data len
unsigned char *data; // pointer to data array
};Scenarios:
Quoted 8 lines
data_allocated= 0 or data == NULL -> driver just returnsdata_lendata_allocated<data_len-> driver returns-ENOMEMdata_allocated>=data_len-> driver will copy dataNote that
data_lenwill be zero from the user space for read operations (driver knows it). But we can eventually use this ioctl to set some data in future, so data_len/data will be used for the write operation.
In all cases, data_len is filled with the expected data size in return, right?
thanks,
Takashi
Jaroslav Kysela
maintainerRe: [PATCH v3 2/2] ALSA: control: add ioctl to retrieve full card components
Quoted 89 lines · Takashi Iwai
Quoted 42 lines · Jaroslav Kysela
Quoted 40 lines · Takashi Iwai
Quoted 38 lines · Maciej Strozek
W dniu czw, 05.03.2026 o godzinie 11∶04 +0100, użytkownik Takashi Iwai
Quoted 34 lines · napisał:
Quoted 19 lines · Maciej Strozek
W dniu wto, 03.03.2026 o godzinie 16∶47 +0100, użytkownik Takashi Iwai
Quoted 10 lines · napisał:
Review
Quoted 7 lines
+ */
(quoted diff) +5
-0+struct snd_ctl_card_components { + int card; + unsigned int length; + unsigned char *components; +};And the ioctl can serve for two purposes:
Quoted 5 lines
- When length=0 is set, the kernel stores the current number of bytes
and returns without copying. User-space can use this mode for allocating the buffer.Quoted 4 lines
In alsa-lib all data must be allocated beforehand, so this length==0
query is not very useful there, it will just go into a [512] array anyway. Are there any other users that may benefit from this?My suggested API can work even with the fixed size 512, too, if 512 is
hight enough. It's just more flexible. And there is no restriction about alsa-lib data allocation; the function can query the size then allocate, too.Takashi
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
OK, will prepare v4 with this, thanks
Well, let's see how others think, too. The API design needs more considerations because we can't change it any longer once after defined.
I think that the indirect pointer in ioctl structure is the best at the moment unless we decide to use the fixed char array.
OK, it might be indeed better if the user-space API is something like:
int
snd_ctl_card_components(snd_ctl_t *ctl, unsigned char *buf, size_t len);Then it's simpler to pass the pointer as is without copying.
Quoted 7 lines
But (for
discussion) we may try to be a bit clever and define universal bytes ioctl which may carry also other things in future like:enum {
SND_CTL_CARD_BTYPE_COMPONENTS= 1
};So this is for future extensions?
Quoted 3 lines
struct snd_ctl_card_bytes { unsigned int card; // this is duplication with info ioctl // to be removed?Right, it sounds like superfluous. I thought we were to allow extracting a card info for a different card number, but it doesn't look so.
Quoted 12 lines
unsigned int type; // e.g.
SND_CTL_CARD_BTYPE_COMPONENTS
unsigned intdata_allocated; // overall size of data
unsigned intdata_len; // actual data len
unsigned char *data; // pointer to data array
};Scenarios:
data_allocated= 0 or data == NULL -> driver just returnsdata_lendata_allocated<data_len-> driver returns-ENOMEMdata_allocated>=data_len-> driver will copy data
Quoted 7 lines
Quoted 4 lines
Note that
data_lenwill be zero from the user space for read operations (driver knows it). But we can eventually use this ioctl to set some data in future, so data_len/data will be used for the write operation.In all cases,
data_lenis filled with the expected data size in return, right?
I would return data_len only when data_allocated == 0 or when the user space array can hold complete data. When ioctl returns an error code (e.g. ENOMEM), the structure should not be modified IMHO.
Eventually, we can extend the structure to be even more universal and add 'data_offset' and 'data_overall_len' to support fully partial transfers. In this case, data_len would mean filled/used chunk size and the "overflow" error won't exist.
Jaroslav
Signature · 2 lines
Jaroslav Kysela <[email protected]> Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
Re: [PATCH v3 2/2] ALSA: control: add ioctl to retrieve full card components
Quoted 96 lines · Jaroslav Kysela
Quoted 94 lines · Takashi Iwai
Quoted 42 lines · Jaroslav Kysela
Quoted 40 lines · Takashi Iwai
Quoted 38 lines · Maciej Strozek
W dniu czw, 05.03.2026 o godzinie 11∶04 +0100, użytkownik Takashi Iwai
Quoted 34 lines · napisał:
Quoted 19 lines · Maciej Strozek
W dniu wto, 03.03.2026 o godzinie 16∶47 +0100, użytkownik Takashi Iwai
Quoted 10 lines · napisał:
Review
Quoted 7 lines
+ */
(quoted diff) +5
-0+struct snd_ctl_card_components { + int card; + unsigned int length; + unsigned char *components; +};And the ioctl can serve for two purposes:
Quoted 5 lines
- When length=0 is set, the kernel stores the current number of bytes
and returns without copying. User-space can use this mode for allocating the buffer.Quoted 4 lines
In alsa-lib all data must be allocated beforehand, so this length==0
query is not very useful there, it will just go into a [512] array anyway. Are there any other users that may benefit from this?My suggested API can work even with the fixed size 512, too, if 512 is
hight enough. It's just more flexible. And there is no restriction about alsa-lib data allocation; the function can query the size then allocate, too.Takashi
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
OK, will prepare v4 with this, thanks
Well, let's see how others think, too. The API design needs more considerations because we can't change it any longer once after defined.
I think that the indirect pointer in ioctl structure is the best at the moment unless we decide to use the fixed char array.
OK, it might be indeed better if the user-space API is something like:
int
snd_ctl_card_components(snd_ctl_t *ctl, unsigned char *buf, size_t len);Then it's simpler to pass the pointer as is without copying.
Quoted 7 lines
But (for
discussion) we may try to be a bit clever and define universal bytes ioctl which may carry also other things in future like:enum {
SND_CTL_CARD_BTYPE_COMPONENTS= 1
};So this is for future extensions?
Quoted 3 lines
struct snd_ctl_card_bytes { unsigned int card; // this is duplication with info ioctl // to be removed?Right, it sounds like superfluous. I thought we were to allow extracting a card info for a different card number, but it doesn't look so.
Quoted 16 lines
unsigned int type; // e.g.
SND_CTL_CARD_BTYPE_COMPONENTS
unsigned intdata_allocated; // overall size of data
unsigned intdata_len; // actual data len
unsigned char *data; // pointer to data array
};Scenarios:
data_allocated= 0 or data == NULL -> driver just returnsdata_lendata_allocated<data_len-> driver returns-ENOMEMdata_allocated>=data_len-> driver will copy dataNote that
data_lenwill be zero from the user space for read operations (driver knows it). But we can eventually use this ioctl to set some data in future, so data_len/data will be used for the write operation.
Quoted 6 lines
Quoted 2 lines
In all cases,
data_lenis filled with the expected data size in return, right?I would return
data_lenonly whendata_allocated== 0 or when the user space array can hold complete data. When ioctl returns an error code (e.g. ENOMEM), the structure should not be modified IMHO.
I find it OK, otherwise you'd need one more ioctl, but it's a kind of bike-shedding topic, and I don't mind much whether it should be so or not.
Quoted 4 lines
Eventually, we can extend the structure to be even more universal and add '
data_offset' and 'data_overall_len' to support fully partial transfers. In this case,data_lenwould mean filled/used chunk size and the "overflow" error won't exist.
Yeah, we can, and I had that in mind, too. But it makes things complex, so let's not step into it yet.
thanks,
Takashi