ASoC: tlv320aic31xx: Check clock and divider before division
authorAndrew F. Davis <afd@ti.com>
Wed, 29 Nov 2017 21:32:52 +0000 (15:32 -0600)
committerMark Brown <broonie@kernel.org>
Fri, 1 Dec 2017 13:30:48 +0000 (13:30 +0000)
If our set_sysclk DAI callback has not been called yet p_div will be 0
and dividing by this will cause an error. Print an error message and
leave before this.

Signed-off-by: Andrew F. Davis <afd@ti.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/tlv320aic31xx.c

index ab03a19f6aaa593ba5d53280eae43e7bba51d000..05e6d194d6a9bad216489444ee3d2ab9abf940ff 100644 (file)
@@ -754,11 +754,17 @@ static int aic31xx_setup_pll(struct snd_soc_codec *codec,
 {
        struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec);
        int bclk_score = snd_soc_params_to_frame_size(params);
-       int mclk_p = aic31xx->sysclk / aic31xx->p_div;
+       int mclk_p;
        int bclk_n = 0;
        int match = -1;
        int i;
 
+       if (!aic31xx->sysclk || !aic31xx->p_div) {
+               dev_err(codec->dev, "Master clock not supplied\n");
+               return -EINVAL;
+       }
+       mclk_p = aic31xx->sysclk / aic31xx->p_div;
+
        /* Use PLL as CODEC_CLKIN and DAC_CLK as BDIV_CLKIN */
        snd_soc_update_bits(codec, AIC31XX_CLKMUX,
                            AIC31XX_CODEC_CLKIN_MASK, AIC31XX_CODEC_CLKIN_PLL);