ASoC: rockchip: i2s: Fix crash on missing pinctrl
authorChen-Yu Tsai <wens@csie.org>
Tue, 21 Jun 2022 18:57:47 +0000 (02:57 +0800)
committerMark Brown <broonie@kernel.org>
Wed, 22 Jun 2022 12:39:37 +0000 (13:39 +0100)
Commit 44f362c2cc6d ("ASoC: rockchip: i2s: switch BCLK to GPIO") added
pinctrl lookups, but did not skip the lookup if there was no pinctrl
device tied to the I2S controller. As a result, the lookup was done
on an invalid pointer in such cases, causing a kernel panic.

Only do the subsequent pinctrl state lookups and switch if a pinctrl
device was found.

i2s_pinctrl_select_bclk_{on,off} already guard against missing pinctrl
device or pinctrl state, so those two functions aren't touched.

Fixes: 44f362c2cc6d ("ASoC: rockchip: i2s: switch BCLK to GPIO")
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Link: https://lore.kernel.org/r/20220621185747.2782-1-wens@kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/rockchip/rockchip_i2s.c

index be051e48b97bbc86a64b37d916d30005450be523..9fa8ffd712ea00fecdef7f584723b669df7d0d8a 100644 (file)
@@ -808,24 +808,23 @@ static int rockchip_i2s_probe(struct platform_device *pdev)
 
        i2s->bclk_ratio = 64;
        i2s->pinctrl = devm_pinctrl_get(&pdev->dev);
-       if (IS_ERR(i2s->pinctrl))
+       if (IS_ERR(i2s->pinctrl)) {
                dev_err(&pdev->dev, "failed to find i2s pinctrl\n");
+       } else {
+               i2s->bclk_on = pinctrl_lookup_state(i2s->pinctrl, "bclk_on");
+               if (IS_ERR_OR_NULL(i2s->bclk_on))
+                       dev_err(&pdev->dev, "failed to find i2s default state\n");
+               else
+                       dev_dbg(&pdev->dev, "find i2s bclk state\n");
 
-       i2s->bclk_on = pinctrl_lookup_state(i2s->pinctrl,
-                                  "bclk_on");
-       if (IS_ERR_OR_NULL(i2s->bclk_on))
-               dev_err(&pdev->dev, "failed to find i2s default state\n");
-       else
-               dev_dbg(&pdev->dev, "find i2s bclk state\n");
-
-       i2s->bclk_off = pinctrl_lookup_state(i2s->pinctrl,
-                                 "bclk_off");
-       if (IS_ERR_OR_NULL(i2s->bclk_off))
-               dev_err(&pdev->dev, "failed to find i2s gpio state\n");
-       else
-               dev_dbg(&pdev->dev, "find i2s bclk_off state\n");
+               i2s->bclk_off = pinctrl_lookup_state(i2s->pinctrl, "bclk_off");
+               if (IS_ERR_OR_NULL(i2s->bclk_off))
+                       dev_err(&pdev->dev, "failed to find i2s gpio state\n");
+               else
+                       dev_dbg(&pdev->dev, "find i2s bclk_off state\n");
 
-       i2s_pinctrl_select_bclk_off(i2s);
+               i2s_pinctrl_select_bclk_off(i2s);
+       }
 
        i2s->playback_dma_data.addr = res->start + I2S_TXDR;
        i2s->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;