Skip to contentSkip to conversation

hwrng: imx-rngc - check return value of clk_prepare_enable()

PATCH In review Ma Yukun 2 participants 2 messages Sep 6 – Sep 11

Subsystems (3)
lore
Share & tools
lore

Ma Yukun

author
#0 lore raw

PATCH v2 1/1 hwrng: imx-rngc - check return value of clk_prepare_enable()

clk_prepare_enable() can fail here and its return value is currently ignored. If the clock fails to enable, the probe continues to read from the hardware registers without a clock, which can cause a bus hang or external abort.

Check the return value and fail probe if the clock cannot be enabled.

Fixes 1d5449445bd0 ("hwrng: mx-rngc - add a driver for Freescale RNGC")

---
v2: fix patch formatting, add missing context line

 drivers/char/hw_random/imx-rngc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/char/hw_random/imx-rngc.c +3 -1
index 7693328f1..58bdc7a6b 100644
@@ -266,7 +266,9 @@ static int __init imx_rngc_probe(struct platform_device *pdev)
 	if (irq < 0)
 		return irq;
 
-	clk_prepare_enable(rngc->clk);
+	ret = clk_prepare_enable(rngc->clk);
+	if (ret)
+		return ret;
 
 	ver_id = readl(rngc->base + RNGC_VER_ID);
 	rng_type = FIELD_GET(RNG_TYPE, ver_id);
Signature · 1 line
2.43.0
#1 lore raw

Thus wrote Ma Yukun ([email protected]):

Quoted 32 lines

clk_prepare_enable() can fail here and its return value is currently ignored. If the clock fails to enable, the probe continues to read from the hardware registers without a clock, which can cause a bus hang or external abort.

Check the return value and fail probe if the clock cannot be enabled.

Fixes 1d5449445bd0 ("hwrng: mx-rngc - add a driver for Freescale RNGC")

---
v2: fix patch formatting, add missing context line

 drivers/char/hw_random/imx-rngc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/char/hw_random/imx-rngc.c +3 -1
index 7693328f1..58bdc7a6b 100644
@@ -266,7 +266,9 @@ static int __init imx_rngc_probe(struct platform_device *pdev)
 	if (irq < 0)
 		return irq;
 
-	clk_prepare_enable(rngc->clk);
+	ret = clk_prepare_enable(rngc->clk);
+	if (ret)
+		return ret;
 
 	ver_id = readl(rngc->base + RNGC_VER_ID);
 	rng_type = FIELD_GET(RNG_TYPE, ver_id);
Signature · 1 line
2.43.0

This has already been fixed.

https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git/commit/?id=8ba2b068e1b3607289ba5778e4c27c167fdbfee6