Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cfe559b9 authored by Takashi Iwai's avatar Takashi Iwai Committed by Sasha Levin
Browse files

ALSA: hdspm: Fix zero-division



[ Upstream commit c1099c3294c2344110085a38c50e478a5992b368 ]

HDSPM driver contains a code issuing zero-division potentially in
system sample rate ctl code.  This patch fixes it by not processing
a zero or invalid rate value as a divisor, as well as excluding the
invalid value to be passed via the given ctl element.

Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Signed-off-by: default avatarSasha Levin <sasha.levin@oracle.com>
parent 4a4aa423
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -1602,6 +1602,9 @@ static void hdspm_set_dds_value(struct hdspm *hdspm, int rate)
{
{
	u64 n;
	u64 n;


	if (snd_BUG_ON(rate <= 0))
		return;

	if (rate >= 112000)
	if (rate >= 112000)
		rate /= 4;
		rate /= 4;
	else if (rate >= 56000)
	else if (rate >= 56000)
@@ -2220,6 +2223,8 @@ static int hdspm_get_system_sample_rate(struct hdspm *hdspm)
		} else {
		} else {
			/* slave mode, return external sample rate */
			/* slave mode, return external sample rate */
			rate = hdspm_external_sample_rate(hdspm);
			rate = hdspm_external_sample_rate(hdspm);
			if (!rate)
				rate = hdspm->system_sample_rate;
		}
		}
	}
	}


@@ -2265,7 +2270,10 @@ static int snd_hdspm_put_system_sample_rate(struct snd_kcontrol *kcontrol,
					    ucontrol)
					    ucontrol)
{
{
	struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
	struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
	int rate = ucontrol->value.integer.value[0];


	if (rate < 27000 || rate > 207000)
		return -EINVAL;
	hdspm_set_dds_value(hdspm, ucontrol->value.integer.value[0]);
	hdspm_set_dds_value(hdspm, ucontrol->value.integer.value[0]);
	return 0;
	return 0;
}
}