For a control defined like this: -- SOC_SINGLE_S8_TLV("IIR0 INP0 Volume", WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B1_CTL, -84, 40, digital_gain) -- This is what the snd_soc_info_volsw_sx reports: $mc->platform_max:40, $mc->max:40, $mc->min:-84, $uinfo->value.integer.max:40, $uinfo->value.integer.min:0
Now this is obviously wrong which is another issue which I'll explain a bit later but the mixer control($mc) limits are exactly the same inside the snd_soc_put_volsw_sx function. So the min and max fields inside the $mc are the same in snd_soc_put_volsw_sx so this means that the code without my patch has an incorrect check.
Here's an example, this is the check before the patch: -- if (mc->platform_max && val > mc->platform_max) -- Let's say the userspace passes 50 as $val which should be within the range of 0 to 124 so it is a valid value. The check is done before the val is re-scaled, so it checks whether the val is bigger than 40 which is the value of platform_max at that point.
Is the $mc->platform_max supposed to be set to the number of steps as opposed to the maximum value?
Back to the first issue that I've mentioned in this message, the snd_soc_info_volsw_sx reports the wrong value because it adds the $mc->min to the value which not necessary. Curiously enough, there are actually two commits from 6 years ago on the Qualcomm's fork of Linux that fix this one. Neither of these commits exist on the upstream Linux kernel at the moment. I've linked them below.
For the sake of integrity, all of the values that I've gathered from debugging were the same before and after applying these patches. What I mean by that is that the only thing that changes when the patches below are applied is that the snd_soc_info_volsw_sx reports the correct range to the userspace which should be 0 to 124. Also the snd_soc_put_volsw_sx still checks the value from userspace which has a range of 0 to 124 against the maximum of the signed range which is from -84 to 40 regardless of the patches below.
65c7d020fbee8 ("ASoC: Update the Max value of integer controls.") https://git.codelinaro.org/clo/la/kernel/msm-4.9/-/commit/65c7d020fbee8070f3...
0d873de90eb16 ("ASoC: sound: soc: fix incorrect max value") https://git.codelinaro.org/clo/la/kernel/msm-4.9/-/commit/0d873de90eb16e3af4...