Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH v2] ASoC: ops: Consistently treat platform_max as control value
@ 2025-02-28 15:14 Charles Keepax
  2025-03-05 19:56 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Charles Keepax @ 2025-02-28 15:14 UTC (permalink / raw)
  To: broonie
  Cc: lgirdwood, johan+linaro, srinivas.kandagatla, marex, linux-sound,
	patches

This reverts commit 9bdd10d57a88 ("ASoC: ops: Shift tested values in
snd_soc_put_volsw() by +min"), and makes some additional related
updates.

There are two ways the platform_max could be interpreted; the maximum
register value, or the maximum value the control can be set to. The
patch moved from treating the value as a control value to a register
one. When the patch was applied it was technically correct as
snd_soc_limit_volume() also used the register interpretation. However,
even then most of the other usages treated platform_max as a
control value, and snd_soc_limit_volume() has since been updated to
also do so in commit fb9ad24485087 ("ASoC: ops: add correct range
check for limiting volume"). That patch however, missed updating
snd_soc_put_volsw() back to the control interpretation, and fixing
snd_soc_info_volsw_range(). The control interpretation makes more
sense as limiting is typically done from the machine driver, so it is
appropriate to use the customer facing representation rather than the
internal codec representation. Update all the code to consistently use
this interpretation of platform_max.

Finally, also add some comments to the soc_mixer_control struct to
hopefully avoid further patches switching between the two approaches.

Fixes: fb9ad24485087 ("ASoC: ops: add correct range check for limiting volume")
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---

Note v1 was under the slightly different title of:
 ASoC: ops: Revert addition of min whilst checking platform max

Changes since v1:
 - Also updated the code in snd_soc_info_volsw_range.
 - Minor tweaks to the commit message to reflect there were actually
   2 places still using the incorrect interpretation of platform_max.

Thanks,
Charles

 include/sound/soc.h |  5 ++++-
 sound/soc/soc-ops.c | 15 +++++++--------
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index 6bb2fca044c5e..bd7a0514ad7fa 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -1251,7 +1251,10 @@ void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd);
 
 /* mixer control */
 struct soc_mixer_control {
-	int min, max, platform_max;
+	/* Minimum and maximum specified as written to the hardware */
+	int min, max;
+	/* Limited maximum value specified as presented through the control */
+	int platform_max;
 	int reg, rreg;
 	unsigned int shift, rshift;
 	u32 num_channels;
diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
index 60b33e22ac08c..cd5f927bcd4eb 100644
--- a/sound/soc/soc-ops.c
+++ b/sound/soc/soc-ops.c
@@ -325,7 +325,7 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
 	if (ucontrol->value.integer.value[0] < 0)
 		return -EINVAL;
 	val = ucontrol->value.integer.value[0];
-	if (mc->platform_max && ((int)val + min) > mc->platform_max)
+	if (mc->platform_max && val > mc->platform_max)
 		return -EINVAL;
 	if (val > max - min)
 		return -EINVAL;
@@ -338,7 +338,7 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
 		if (ucontrol->value.integer.value[1] < 0)
 			return -EINVAL;
 		val2 = ucontrol->value.integer.value[1];
-		if (mc->platform_max && ((int)val2 + min) > mc->platform_max)
+		if (mc->platform_max && val2 > mc->platform_max)
 			return -EINVAL;
 		if (val2 > max - min)
 			return -EINVAL;
@@ -491,17 +491,16 @@ int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
 {
 	struct soc_mixer_control *mc =
 		(struct soc_mixer_control *)kcontrol->private_value;
-	int platform_max;
-	int min = mc->min;
+	int max;
 
-	if (!mc->platform_max)
-		mc->platform_max = mc->max;
-	platform_max = mc->platform_max;
+	max = mc->max - mc->min;
+	if (mc->platform_max && mc->platform_max < max)
+		max = mc->platform_max;
 
 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
 	uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
 	uinfo->value.integer.min = 0;
-	uinfo->value.integer.max = platform_max - min;
+	uinfo->value.integer.max = max;
 
 	return 0;
 }
-- 
2.39.5


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

* Re: [PATCH v2] ASoC: ops: Consistently treat platform_max as control value
  2025-02-28 15:14 [PATCH v2] ASoC: ops: Consistently treat platform_max as control value Charles Keepax
@ 2025-03-05 19:56 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2025-03-05 19:56 UTC (permalink / raw)
  To: Charles Keepax
  Cc: lgirdwood, johan+linaro, srinivas.kandagatla, marex, linux-sound,
	patches

On Fri, 28 Feb 2025 15:14:56 +0000, Charles Keepax wrote:
> This reverts commit 9bdd10d57a88 ("ASoC: ops: Shift tested values in
> snd_soc_put_volsw() by +min"), and makes some additional related
> updates.
> 
> There are two ways the platform_max could be interpreted; the maximum
> register value, or the maximum value the control can be set to. The
> patch moved from treating the value as a control value to a register
> one. When the patch was applied it was technically correct as
> snd_soc_limit_volume() also used the register interpretation. However,
> even then most of the other usages treated platform_max as a
> control value, and snd_soc_limit_volume() has since been updated to
> also do so in commit fb9ad24485087 ("ASoC: ops: add correct range
> check for limiting volume"). That patch however, missed updating
> snd_soc_put_volsw() back to the control interpretation, and fixing
> snd_soc_info_volsw_range(). The control interpretation makes more
> sense as limiting is typically done from the machine driver, so it is
> appropriate to use the customer facing representation rather than the
> internal codec representation. Update all the code to consistently use
> this interpretation of platform_max.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: ops: Consistently treat platform_max as control value
      commit: 0eba2a7e858907a746ba69cd002eb9eb4dbd7bf3

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


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

end of thread, other threads:[~2025-03-05 19:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-28 15:14 [PATCH v2] ASoC: ops: Consistently treat platform_max as control value Charles Keepax
2025-03-05 19:56 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox