Skip to content

Commit 75a3e43

Browse files
Sheetalbroonie
authored andcommitted
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: 3664538 ("ASoC: tegra: Add per-stream Mixer Fade controls") Signed-off-by: Sheetal <sheetal@nvidia.com> Link: https://patch.msgid.link/20260519094858.1426057-1-sheetal@nvidia.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent e76ccf1 commit 75a3e43

2 files changed

Lines changed: 29 additions & 8 deletions

File tree

sound/soc/tegra/tegra210_mixer.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static int tegra210_mixer_configure_gain(struct snd_soc_component *cmpnt,
150150

151151
/* Write duration parameters */
152152
for (i = 0; i < NUM_DURATION_PARMS; i++) {
153-
int val;
153+
u32 val;
154154

155155
if (instant_gain) {
156156
val = 1;
@@ -181,6 +181,17 @@ static int tegra210_mixer_configure_gain(struct snd_soc_component *cmpnt,
181181
return err;
182182
}
183183

184+
static int tegra210_mixer_fade_duration_info(struct snd_kcontrol *kcontrol,
185+
struct snd_ctl_elem_info *uinfo)
186+
{
187+
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
188+
uinfo->count = 1;
189+
uinfo->value.integer.min = TEGRA210_MIXER_FADE_DURATION_MIN;
190+
uinfo->value.integer.max = TEGRA210_MIXER_FADE_DURATION_MAX;
191+
192+
return 0;
193+
}
194+
184195
static int tegra210_mixer_get_fade_duration(struct snd_kcontrol *kcontrol,
185196
struct snd_ctl_elem_value *ucontrol)
186197
{
@@ -202,9 +213,10 @@ static int tegra210_mixer_put_fade_duration(struct snd_kcontrol *kcontrol,
202213
struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol);
203214
struct tegra210_mixer *mixer = snd_soc_component_get_drvdata(cmpnt);
204215
unsigned int id = mc->reg;
205-
u32 duration = ucontrol->value.integer.value[0];
216+
long duration = ucontrol->value.integer.value[0];
206217

207-
if (duration == 0 || duration > TEGRA210_MIXER_FADE_DURATION_MAX)
218+
if (duration < (long)TEGRA210_MIXER_FADE_DURATION_MIN ||
219+
duration > TEGRA210_MIXER_FADE_DURATION_MAX)
208220
return -EINVAL;
209221

210222
if (mixer->duration[id] == duration)
@@ -614,10 +626,17 @@ static int tegra210_mixer_fade_status_info(struct snd_kcontrol *kcontrol,
614626
}
615627

616628
#define FADE_CTRL(id) \
617-
SOC_SINGLE_EXT("RX" #id " Fade Duration", (id) - 1, 0, \
618-
TEGRA210_MIXER_FADE_DURATION_MAX, 0, \
619-
tegra210_mixer_get_fade_duration, \
620-
tegra210_mixer_put_fade_duration), \
629+
{ \
630+
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
631+
.name = "RX" #id " Fade Duration", \
632+
.info = tegra210_mixer_fade_duration_info, \
633+
.get = tegra210_mixer_get_fade_duration, \
634+
.put = tegra210_mixer_put_fade_duration, \
635+
.private_value = SOC_SINGLE_VALUE((id) - 1, 0, \
636+
TEGRA210_MIXER_FADE_DURATION_MIN, \
637+
TEGRA210_MIXER_FADE_DURATION_MAX, \
638+
0, 0), \
639+
}, \
621640
SOC_SINGLE_EXT("RX" #id " Fade Gain", (id) - 1, 0, \
622641
TEGRA210_MIXER_GAIN_MAX, 0, \
623642
tegra210_mixer_get_fade_gain, \

sound/soc/tegra/tegra210_mixer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@
8787

8888
#define NUM_GAIN_POLY_COEFFS 9
8989
#define TEGRA210_MIXER_GAIN_MAX 0x20000
90-
#define TEGRA210_MIXER_FADE_DURATION_MAX 0x7fffffff
9190

9291
#define TEGRA210_MIXER_PRESCALAR 6
92+
#define TEGRA210_MIXER_FADE_DURATION_MIN \
93+
(BIT(TEGRA210_MIXER_PRESCALAR - 1) + 1)
94+
#define TEGRA210_MIXER_FADE_DURATION_MAX 0x7fffffff
9395
#define TEGRA210_MIXER_FADE_IDLE 0
9496
#define TEGRA210_MIXER_FADE_ACTIVE 1
9597

0 commit comments

Comments
 (0)