[PATCH v4 2/4] ALSA: pcm: Report writable chmap controls as variable
From: Abel Vesa
Date: Tue Nov 24 2026 - 05:57:55 EST
The chmap control TLV always describes the maps as
SNDRV_CTL_TLVT_CHMAP_FIXED, which tells userspace the channel order
cannot be changed.
A chmap control that accepts writes exists precisely so userspace can
reorder the channels. Report such maps as SNDRV_CTL_TLVT_CHMAP_VAR,
so tools like alsa-lib expose the map as freely swappable.
Signed-off-by: Abel Vesa <abel.vesa@xxxxxxxxxxxxxxxx>
---
sound/core/pcm_lib.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 6806b1d258f2..219d506fdac2 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -2539,11 +2539,15 @@ static int pcm_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag,
{
struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
const struct snd_pcm_chmap_elem *map;
+ unsigned int tlv_type = SNDRV_CTL_TLVT_CHMAP_FIXED;
unsigned int __user *dst;
int c, count = 0;
if (!info->chmap)
return -EINVAL;
+ /* A writable control allows userspace to reorder the channels */
+ if (kcontrol->vd[0].access & SNDRV_CTL_ELEM_ACCESS_WRITE)
+ tlv_type = SNDRV_CTL_TLVT_CHMAP_VAR;
if (size < 8)
return -ENOMEM;
if (put_user(SNDRV_CTL_TLVT_CONTAINER, tlv))
@@ -2556,7 +2560,7 @@ static int pcm_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag,
continue;
if (size < 8)
return -ENOMEM;
- if (put_user(SNDRV_CTL_TLVT_CHMAP_FIXED, dst) ||
+ if (put_user(tlv_type, dst) ||
put_user(chs_bytes, dst + 1))
return -EFAULT;
dst += 2;
--
2.54.0