ASoC: ops: fix signedness bug in snd_soc_put_volsw()
Subsystems (3)
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.
--- sound/soc/soc-ops.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
sound/soc/soc-ops.c +3 -2
@@ -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
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.
--- sound/soc/soc-ops.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
sound/soc/soc-ops.c +2 -1
@@ -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
Mark Brown
maintainerQuoted 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.
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
Mark Brown
maintainerQuoted 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->minis negative the math gets tricky.
No, it *is* valid if weird to have negative values for some controls.
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