All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: usb-audio: Fix missing 64bit conversions for 64 channel enhancement
@ 2026-12-02 14:16 Takashi Iwai
  2026-12-02 14:26 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Takashi Iwai @ 2026-12-02 14:16 UTC (permalink / raw)
  To: linux-sound

The previous fix to support up to 64 channels on mixer misses a few
places and some remain still as 32bit int, which would lead to
misbehavior like unexpected writable elements.

Cover the missing conversion to 64bit.

While we're at it, change usb_mixer_elem_info.master_readonly to bool
for clarity, too.

Fixes: 16ee07bfa935 ("ALSA: usb-audio: Extend max number of channels to 64")
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/usb/mixer.c | 30 +++++++++++++++---------------
 sound/usb/mixer.h |  4 ++--
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index 95209ec006b3..7371c8babe3a 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -588,9 +588,9 @@ int snd_usb_set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel,
 			     int index, int value)
 {
 	int err;
-	unsigned int read_only = (channel == 0) ?
+	bool read_only = (channel == 0) ?
 		cval->master_readonly :
-		cval->ch_readonly & BIT(channel - 1);
+		!!(cval->ch_readonly & BIT_U64(channel - 1));
 
 	if (read_only) {
 		usb_audio_dbg(cval->head.mixer->chip,
@@ -1416,7 +1416,7 @@ static int get_min_max_with_quirks(struct usb_mixer_elem_info *cval,
 		int minchn = 0;
 		if (cval->cmask) {
 			for (i = 0; i < MAX_CHANNELS; i++)
-				if (cval->cmask & BIT(i)) {
+				if (cval->cmask & BIT_U64(i)) {
 					minchn = i + 1;
 					break;
 				}
@@ -1496,7 +1496,7 @@ static int get_min_max_with_quirks(struct usb_mixer_elem_info *cval,
 	} else {
 		idx = 0;
 		for (i = 0; i < MAX_CHANNELS; i++) {
-			if (cval->cmask & BIT(i)) {
+			if (cval->cmask & BIT_U64(i)) {
 				init_cur_mix_raw(cval, i + 1, idx);
 				idx++;
 			}
@@ -1576,7 +1576,7 @@ static int mixer_ctl_feature_get(struct snd_kcontrol *kcontrol,
 	if (cval->cmask) {
 		cnt = 0;
 		for (c = 0; c < MAX_CHANNELS; c++) {
-			if (!(cval->cmask & BIT(c)))
+			if (!(cval->cmask & BIT_U64(c)))
 				continue;
 			err = snd_usb_get_cur_mix_value(cval, c + 1, cnt, &val);
 			if (err < 0)
@@ -1611,7 +1611,7 @@ static int mixer_ctl_feature_put(struct snd_kcontrol *kcontrol,
 	if (cval->cmask) {
 		cnt = 0;
 		for (c = 0; c < MAX_CHANNELS; c++) {
-			if (!(cval->cmask & BIT(c)))
+			if (!(cval->cmask & BIT_U64(c)))
 				continue;
 			err = snd_usb_get_cur_mix_value(cval, c + 1, cnt, &oval);
 			if (err < 0)
@@ -1895,7 +1895,7 @@ static void __build_feature_ctl(struct usb_mixer_interface *mixer,
 				u64 ctl_mask, int control,
 				struct usb_audio_term *iterm,
 				struct usb_audio_term *oterm,
-				int unitid, int nameid, int readonly_mask)
+				int unitid, int nameid, u64 readonly_mask)
 {
 	const struct usb_feature_control_info *ctl_info;
 	unsigned int len = 0;
@@ -1934,11 +1934,11 @@ static void __build_feature_ctl(struct usb_mixer_interface *mixer,
 
 	if (ctl_mask == 0) {
 		cval->channels = 1;	/* master channel */
-		cval->master_readonly = readonly_mask;
+		cval->master_readonly = !!readonly_mask;
 	} else {
 		int i, c = 0;
 		for (i = 0; i < MAX_CHANNELS; i++)
-			if (ctl_mask & BIT(i))
+			if (ctl_mask & BIT_U64(i))
 				c++;
 		cval->channels = c;
 		cval->ch_readonly = readonly_mask;
@@ -2057,7 +2057,7 @@ static void __build_feature_ctl(struct usb_mixer_interface *mixer,
 static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
 			      u64 ctl_mask, int control,
 			      struct usb_audio_term *iterm, int unitid,
-			      int readonly_mask)
+			      u64 readonly_mask)
 {
 	struct uac_feature_unit_descriptor *desc = raw_desc;
 	int nameid = uac_feature_unit_iFeature(desc);
@@ -2310,7 +2310,7 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid,
 	} else { /* UAC_VERSION_2/3 */
 		for (i = 0; i < ARRAY_SIZE(audio_feature_info); i++) {
 			u64 ch_bits = 0;
-			unsigned int ch_read_only = 0;
+			u64 ch_read_only = 0;
 			int control = audio_feature_info[i].control;
 
 			for (j = 0; j < channels; j++) {
@@ -2319,9 +2319,9 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid,
 				mask = snd_usb_combine_bytes(bmaControls +
 							     csize * (j+1), csize);
 				if (uac_v2v3_control_is_readable(mask, control)) {
-					ch_bits |= BIT(j);
+					ch_bits |= BIT_U64(j);
 					if (!uac_v2v3_control_is_writeable(mask, control))
-						ch_read_only |= BIT(j);
+						ch_read_only |= BIT_U64(j);
 				}
 			}
 
@@ -2417,7 +2417,7 @@ static void build_mixer_unit_ctl(struct mixer_build *state,
 		__u8 *c = uac_mixer_unit_bmControls(desc, state->mixer->protocol);
 
 		if (check_matrix_bitmap(c, in_ch, i, num_outs)) {
-			cval->cmask |= BIT(i);
+			cval->cmask |= BIT_U64(i);
 			cval->channels++;
 		}
 	}
@@ -4013,7 +4013,7 @@ static int restore_mixer_value(struct usb_mixer_elem_list *list)
 	if (cval->cmask) {
 		idx = 0;
 		for (c = 0; c < MAX_CHANNELS; c++) {
-			if (!(cval->cmask & BIT(c)))
+			if (!(cval->cmask & BIT_U64(c)))
 				continue;
 			if (test_bit(c + 1, cval->cached)) {
 				err = snd_usb_set_cur_mix_value(cval, c + 1, idx,
diff --git a/sound/usb/mixer.h b/sound/usb/mixer.h
index c40f832852be..559e3a48267b 100644
--- a/sound/usb/mixer.h
+++ b/sound/usb/mixer.h
@@ -86,8 +86,8 @@ struct usb_mixer_elem_info {
 	unsigned int control;	/* CS or ICN (high byte) */
 	u64 cmask; /* channel mask bitmap: 0 = master */
 	unsigned int idx_off; /* Control index offset */
-	unsigned int ch_readonly;
-	unsigned int master_readonly;
+	u64 ch_readonly;
+	bool master_readonly;
 	int channels;
 	int val_type;
 	int min, max, res;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ALSA: usb-audio: Fix missing 64bit conversions for 64 channel enhancement
  2026-12-02 14:16 [PATCH] ALSA: usb-audio: Fix missing 64bit conversions for 64 channel enhancement Takashi Iwai
@ 2026-12-02 14:26 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-02 14:26 UTC (permalink / raw)
  To: Takashi Iwai, linux-sound

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ALSA: usb-audio: unconverted 32-bit BIT(j) in
  parse_audio_feature_unit()
--

commit c7574dcbffc09488f93abce794f2df8e79705058
Author: Takashi Iwai <tiwai@suse.de>

ALSA: usb-audio: Fix missing 64bit conversions for 64 channel enhancement

This commit converts channel bitmasks and BIT() usages in the USB audio
mixer to 64-bit types and BIT_U64() to support up to 64 mixer channels.

> diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
> index 37850f34caaea..a16c11a7b79fb 100644
> --- a/sound/usb/mixer.c
> +++ b/sound/usb/mixer.c

[ ... ]

> @@ -2317,7 +2317,7 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid,
>  	} else { /* UAC_VERSION_2/3 */
>  		for (i = 0; i < ARRAY_SIZE(audio_feature_info); i++) {
>  			u64 ch_bits = 0;
> -			unsigned int ch_read_only = 0;
> +			u64 ch_read_only = 0;
>  			int control = audio_feature_info[i].control;
>  
>  			for (j = 0; j < channels; j++) {
> @@ -2326,9 +2326,9 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid,
>  				mask = snd_usb_combine_bytes(bmaControls +
>  							     csize * (j+1), csize);
>  				if (uac_v2v3_control_is_readable(mask, control)) {
> -					ch_bits |= BIT(j);
> +					ch_bits |= BIT_U64(j);
>  					if (!uac_v2v3_control_is_writeable(mask, control))
> -						ch_read_only |= BIT(j);
> +						ch_read_only |= BIT_U64(j);
>  				}
>  			}
>  

[Severity: Medium]
Should the UAC_VERSION_1 branch right above this in
parse_audio_feature_unit() also use BIT_U64(j) when setting ch_bits?

sound/usb/mixer.c:parse_audio_feature_unit() {
    ...
			for (j = 0; j < channels; j++) {
				unsigned int mask;

				mask = snd_usb_combine_bytes(bmaControls +
							     csize * (j+1), csize);
				if (mask & BIT(i))
					ch_bits |= BIT(j);
			}
    ...
}

On 32-bit architectures, BIT(j) shifts a 32-bit unsigned long, so UAC1
feature units with more than 32 channels hit a shift-out-of-bounds for
j >= 32 and fail to populate the upper 32 bits of ch_bits.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202141631.688337-1-tiwai@suse.de?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-02 14:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 14:16 [PATCH] ALSA: usb-audio: Fix missing 64bit conversions for 64 channel enhancement Takashi Iwai
2026-12-02 14:26 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.