Skip to content

Commit 326fe81

Browse files
JihedChaibibroonie
authored andcommitted
ASoC: adau1372: Fix unchecked clk_prepare_enable() return value
adau1372_set_power() calls clk_prepare_enable() but discards the return value. If the clock enable fails, the driver proceeds to access registers on unpowered hardware, potentially causing silent corruption. Make adau1372_set_power() return int and propagate the error from clk_prepare_enable(). Update adau1372_set_bias_level() to return the error directly for the STANDBY and OFF cases. Signed-off-by: Jihed Chaibi <[email protected]> Fixes: 6cd4c64 ("ASoC: Add ADAU1372 audio CODEC support") Reviewed-by: Nuno Sá <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent c369299 commit 326fe81

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

sound/soc/codecs/adau1372.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -782,15 +782,18 @@ static void adau1372_enable_pll(struct adau1372 *adau1372)
782782
dev_err(adau1372->dev, "Failed to lock PLL\n");
783783
}
784784

785-
static void adau1372_set_power(struct adau1372 *adau1372, bool enable)
785+
static int adau1372_set_power(struct adau1372 *adau1372, bool enable)
786786
{
787787
if (adau1372->enabled == enable)
788-
return;
788+
return 0;
789789

790790
if (enable) {
791791
unsigned int clk_ctrl = ADAU1372_CLK_CTRL_MCLK_EN;
792+
int ret;
792793

793-
clk_prepare_enable(adau1372->mclk);
794+
ret = clk_prepare_enable(adau1372->mclk);
795+
if (ret)
796+
return ret;
794797
if (adau1372->pd_gpio)
795798
gpiod_set_value(adau1372->pd_gpio, 0);
796799

@@ -829,6 +832,8 @@ static void adau1372_set_power(struct adau1372 *adau1372, bool enable)
829832
}
830833

831834
adau1372->enabled = enable;
835+
836+
return 0;
832837
}
833838

834839
static int adau1372_set_bias_level(struct snd_soc_component *component,
@@ -842,11 +847,9 @@ static int adau1372_set_bias_level(struct snd_soc_component *component,
842847
case SND_SOC_BIAS_PREPARE:
843848
break;
844849
case SND_SOC_BIAS_STANDBY:
845-
adau1372_set_power(adau1372, true);
846-
break;
850+
return adau1372_set_power(adau1372, true);
847851
case SND_SOC_BIAS_OFF:
848-
adau1372_set_power(adau1372, false);
849-
break;
852+
return adau1372_set_power(adau1372, false);
850853
}
851854

852855
return 0;

0 commit comments

Comments
 (0)