Skip to contentSkip to conversation

ASoC: tegra: tegra210-mixer: Reject too-short fade durations

PATCH In review Sheetal 2 participants 2 messages May 19 – May 22

Subsystems (3)
lore
Share & tools
lore

Sheetal

author
#0 lore raw

PATCH 1/1 ASoC: tegra: tegra210-mixer: Reject too-short fade durations

DURATION_INV_N3 is computed from BIT_ULL(31 + prescalar) divided by the configured duration, and then written as a 32-bit RAM value.

Durations of 32 samples or less overflow that value, so reject them and advertise the valid range through the fade duration control.

Validate the ALSA integer control value as a long before storing it in the driver's u32 duration field. Use a u32 temporary for duration RAM writes because the largest valid inverse value can still exceed INT_MAX.

Fixes 36645381b864 ("ASoC: tegra: Add per-stream Mixer Fade controls")
---
 sound/soc/tegra/tegra210_mixer.c | 33 +++++++++++++++++++++++++-------
 sound/soc/tegra/tegra210_mixer.h |  4 +++-
 2 files changed, 29 insertions(+), 8 deletions(-)
sound/soc/tegra/tegra210_mixer.c +26 -7
index bfdd457f740c..c237ba7531de 100644
@@ -150,7 +150,7 @@ static int tegra210_mixer_configure_gain(struct snd_soc_component *cmpnt,
 
 	/* Write duration parameters */
 	for (i = 0; i < NUM_DURATION_PARMS; i++) {
-		int val;
+		u32 val;
 
 		if (instant_gain) {
 			val = 1;
@@ -181,6 +181,17 @@ static int tegra210_mixer_configure_gain(struct snd_soc_component *cmpnt,
 	return err;
 }
 
+static int tegra210_mixer_fade_duration_info(struct snd_kcontrol *kcontrol,
+					     struct snd_ctl_elem_info *uinfo)
+{
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+	uinfo->count = 1;
+	uinfo->value.integer.min = TEGRA210_MIXER_FADE_DURATION_MIN;
+	uinfo->value.integer.max = TEGRA210_MIXER_FADE_DURATION_MAX;
+
+	return 0;
+}
+
 static int tegra210_mixer_get_fade_duration(struct snd_kcontrol *kcontrol,
 					    struct snd_ctl_elem_value *ucontrol)
 {
@@ -202,9 +213,10 @@ static int tegra210_mixer_put_fade_duration(struct snd_kcontrol *kcontrol,
 	struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol);
 	struct tegra210_mixer *mixer = snd_soc_component_get_drvdata(cmpnt);
 	unsigned int id = mc->reg;
-	u32 duration = ucontrol->value.integer.value[0];
+	long duration = ucontrol->value.integer.value[0];
 
-	if (duration == 0 || duration > TEGRA210_MIXER_FADE_DURATION_MAX)
+	if (duration < (long)TEGRA210_MIXER_FADE_DURATION_MIN ||
+	    duration > TEGRA210_MIXER_FADE_DURATION_MAX)
 		return -EINVAL;
 
 	if (mixer->duration[id] == duration)
@@ -614,10 +626,17 @@ static int tegra210_mixer_fade_status_info(struct snd_kcontrol *kcontrol,
 }
 
 #define FADE_CTRL(id)							\
-	SOC_SINGLE_EXT("RX" #id " Fade Duration", (id) - 1, 0,		\
-		       TEGRA210_MIXER_FADE_DURATION_MAX, 0,		\
-		       tegra210_mixer_get_fade_duration,			\
-		       tegra210_mixer_put_fade_duration),		\
+	{								\
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,			\
+		.name = "RX" #id " Fade Duration",			\
+		.info = tegra210_mixer_fade_duration_info,		\
+		.get = tegra210_mixer_get_fade_duration,			\
+		.put = tegra210_mixer_put_fade_duration,			\
+		.private_value = SOC_SINGLE_VALUE((id) - 1, 0,		\
+				TEGRA210_MIXER_FADE_DURATION_MIN,	\
+				TEGRA210_MIXER_FADE_DURATION_MAX,	\
+				0, 0),					\
+	},								\
 	SOC_SINGLE_EXT("RX" #id " Fade Gain", (id) - 1, 0,		\
 		       TEGRA210_MIXER_GAIN_MAX, 0,			\
 		       tegra210_mixer_get_fade_gain,			\
sound/soc/tegra/tegra210_mixer.h +3 -1
index bcbad08cbb9d..d9c8fa6124de 100644
@@ -87,9 +87,11 @@
 
 #define NUM_GAIN_POLY_COEFFS 9
 #define TEGRA210_MIXER_GAIN_MAX			0x20000
-#define TEGRA210_MIXER_FADE_DURATION_MAX	0x7fffffff
 
 #define TEGRA210_MIXER_PRESCALAR	    6
+#define TEGRA210_MIXER_FADE_DURATION_MIN	\
+	(BIT(TEGRA210_MIXER_PRESCALAR - 1) + 1)
+#define TEGRA210_MIXER_FADE_DURATION_MAX	0x7fffffff
 #define TEGRA210_MIXER_FADE_IDLE	    0
 #define TEGRA210_MIXER_FADE_ACTIVE	  1
 
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 1 line · Sheetal

ASoC: tegra: tegra210-mixer: Reject too-short fade durations

Applied to

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

Thanks!

[1/1] ASoC: tegra: tegra210-mixer: Reject too-short fade durations

      https://git.kernel.org/broonie/sound/c/75a3e43339a2

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