Linux Tegra architecture development
 help / color / mirror / Atom feed
From: Sheetal <sheetal@nvidia.com>
To: Liam Girdwood <lgirdwood@gmail.com>, Mark Brown <broonie@kernel.org>
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	"Thierry Reding" <thierry.reding@kernel.org>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	Mohan Kumar <mkumard@nvidia.com>,
	Sameer Pujar <spujar@nvidia.com>,
	"Rosen Penev" <rosenp@gmail.com>,
	Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>,
	<linux-sound@vger.kernel.org>, <linux-tegra@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH] ASoC: tegra: tegra210-mixer: Reject too-short fade durations
Date: Tue, 19 May 2026 09:48:58 +0000	[thread overview]
Message-ID: <20260519094858.1426057-1-sheetal@nvidia.com> (raw)

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")
Signed-off-by: Sheetal <sheetal@nvidia.com>
---
 sound/soc/tegra/tegra210_mixer.c | 33 +++++++++++++++++++++++++-------
 sound/soc/tegra/tegra210_mixer.h |  4 +++-
 2 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/sound/soc/tegra/tegra210_mixer.c b/sound/soc/tegra/tegra210_mixer.c
index bfdd457f740c..c237ba7531de 100644
--- a/sound/soc/tegra/tegra210_mixer.c
+++ b/sound/soc/tegra/tegra210_mixer.c
@@ -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,			\
diff --git a/sound/soc/tegra/tegra210_mixer.h b/sound/soc/tegra/tegra210_mixer.h
index bcbad08cbb9d..d9c8fa6124de 100644
--- a/sound/soc/tegra/tegra210_mixer.h
+++ b/sound/soc/tegra/tegra210_mixer.h
@@ -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
 
-- 
2.17.1


             reply	other threads:[~2026-05-19  9:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-19  9:48 Sheetal [this message]
2026-05-19 13:31 ` [PATCH] ASoC: tegra: tegra210-mixer: Reject too-short fade durations Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260519094858.1426057-1-sheetal@nvidia.com \
    --to=sheetal@nvidia.com \
    --cc=broonie@kernel.org \
    --cc=jonathanh@nvidia.com \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=mkumard@nvidia.com \
    --cc=perex@perex.cz \
    --cc=rosenp@gmail.com \
    --cc=spujar@nvidia.com \
    --cc=thierry.reding@kernel.org \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox