linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: sgtl5000: avoid division by zero if lo_vag is zero
@ 2018-09-06 10:41 Colin King
  2018-09-06 11:09 ` Applied "ASoC: sgtl5000: avoid division by zero if lo_vag is zero" to the asoc tree Mark Brown
  2018-09-06 11:58 ` [PATCH] ASoC: sgtl5000: avoid division by zero if lo_vag is zero Dan Carpenter
  0 siblings, 2 replies; 4+ messages in thread
From: Colin King @ 2018-09-06 10:41 UTC (permalink / raw)
  To: Fabio Estevam, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, alsa-devel
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

In the case where lo_vag <= SGTL5000_LINE_OUT_GND_BASE, lo_vag
is set to zero and later vol_quot is computed by dividing by
lo_vag causing a division by zero error.  Fix this by avoiding
a zero division and set vol_quot to zero in this specific case
so that the lowest setting for i is correctly set.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 sound/soc/codecs/sgtl5000.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c
index 60764f6201b1..add18d6d77da 100644
--- a/sound/soc/codecs/sgtl5000.c
+++ b/sound/soc/codecs/sgtl5000.c
@@ -1218,7 +1218,7 @@ static int sgtl5000_set_power_regs(struct snd_soc_component *component)
 	 * Searching for a suitable index solving this formula:
 	 * idx = 40 * log10(vag_val / lo_cagcntrl) + 15
 	 */
-	vol_quot = (vag * 100) / lo_vag;
+	vol_quot = lo_vag ? (vag * 100) / lo_vag : 0;
 	lo_vol = 0;
 	for (i = 0; i < ARRAY_SIZE(vol_quot_table); i++) {
 		if (vol_quot >= vol_quot_table[i])
-- 
2.17.1


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

end of thread, other threads:[~2018-09-06 12:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-06 10:41 [PATCH] ASoC: sgtl5000: avoid division by zero if lo_vag is zero Colin King
2018-09-06 11:09 ` Applied "ASoC: sgtl5000: avoid division by zero if lo_vag is zero" to the asoc tree Mark Brown
2018-09-06 11:58 ` [PATCH] ASoC: sgtl5000: avoid division by zero if lo_vag is zero Dan Carpenter
2018-09-06 12:01   ` Colin Ian King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).