Skip to contentSkip to conversation

ASoC: ops: fix signedness bug in snd_soc_put_volsw()

PATCH In review Dan Carpenter 2 participants 6 messages Jan 28, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ASoC: ops: fix signedness bug in snd_soc_put_volsw()

The "val" and "val2" variables need to signed for the checking to work as intended.

Fixes 817f7c9335ec ("ASoC: ops: Reject out of bounds values in snd_soc_put_volsw()")
---
 sound/soc/soc-ops.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
sound/soc/soc-ops.c +3 -2
index dc0e7c8d31f3..0091fa96eb48 100644
@@ -310,8 +310,9 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
 	unsigned int invert = mc->invert;
 	int err;
 	bool type_2r = false;
-	unsigned int val2 = 0;
-	unsigned int val, val_mask;
+	unsigned int val_mask;
+	int val2 = 0;
+	int val;
 
 	if (sign_bit)
 		mask = BIT(sign_bit + 1) - 1;
Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/2 ASoC: ops: Fix signedness bug in snd_soc_put_volsw_sx()

The "val" variable needs to be signed for the checking to work correctly.

Fixes 4f1e50d6a9cf ("ASoC: ops: Reject out of bounds values in snd_soc_put_volsw_sx()")
---
 sound/soc/soc-ops.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
sound/soc/soc-ops.c +2 -1
index 0091fa96eb48..a615316a06ff 100644
@@ -422,7 +422,8 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
 	int min = mc->min;
 	unsigned int mask = (1U << (fls(min + max) - 1)) - 1;
 	int err = 0;
-	unsigned int val, val_mask;
+	unsigned int val_mask;
+	int val;
 
 	val = ucontrol->value.integer.value[0];
 	if (mc->platform_max && val > mc->platform_max)
Signature · 1 line
2.20.1
maintainer
#2 lore raw
In reply to Dan Carpenter
Quoted 2 lines · Dan Carpenter

The "val" and "val2" variables need to signed for the checking to work as intended.

This means that the helpers won't support controls that use the top bit of a 32 bit register.

#3 lore raw
Quoted 6 lines · Mark Brown
Quoted 2 lines · Dan Carpenter

The "val" and "val2" variables need to signed for the checking to work as intended.

This means that the helpers won't support controls that use the top bit of a 32 bit register.

Fine, I can delete the checks for negative instead (I'm surprised you haven't already received a dozen bot emails about this).

I haven't been able to figure out where mc->min/max are set. In snd_soc_get_xr_sx() it checks whether "mc->min" is negative.

	if (min < 0 && val > max)
		val |= ~mask;

Is that a bug? If mc->min is negative the math gets tricky.

regards,
dan carpenter

maintainer
#4 lore raw
Quoted 7 lines · Dan Carpenter
Quoted 2 lines · Mark Brown

This means that the helpers won't support controls that use the top bit of a 32 bit register.

Fine, I can delete the checks for negative instead (I'm surprised you haven't already received a dozen bot emails about this).

No, we need the checks for negatives since userspace supplies a signed value. The check needs to be done on the value in the input structure before we pull it out for mangling. I probably got bot emails but frankly these days almost all of them are some combination of barely legible and misdirected and there's plenty of people who like to fix these things if they're real.

Quoted 1 line

I haven't been able to figure out where mc->min/max are set. In

They're the big tables of static assignments via macros in the drivers.

Quoted 6 lines

snd_soc_get_xr_sx() it checks whether "mc->min" is negative.

	if (min < 0 && val > max)
		val |= ~mask;

Is that a bug? If mc->min is negative the math gets tricky.

No, it *is* valid if weird to have negative values for some controls.

#5 lore raw
Quoted 9 lines · Mark Brown
Quoted 7 lines · Dan Carpenter
Quoted 2 lines · Mark Brown

This means that the helpers won't support controls that use the top bit of a 32 bit register.

Fine, I can delete the checks for negative instead (I'm surprised you haven't already received a dozen bot emails about this).

Quoted 7 lines

No, we need the checks for negatives since userspace supplies a signed value. The check needs to be done on the value in the input structure before we pull it out for mangling. I probably got bot emails but frankly these days almost all of them are some combination of barely legible and misdirected and there's plenty of people who like to fix these things if they're real.

That's a bit trickier than I initially imagined so I'm going to leave this for smarter people than me...

regards,
dan carpenter