[PATCH] clk: Check clk_enable return in bandgap CPU notifier

Zhaoyang Yu posted 1 patch 1 month, 2 weeks ago
drivers/thermal/ti-soc-thermal/ti-bandgap.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
[PATCH] clk: Check clk_enable return in bandgap CPU notifier
Posted by Zhaoyang Yu 1 month, 2 weeks ago
In bandgap_omap_cpu_notifier(), clk_enable() was called without
checking its return value. If the clock fails to enable, accessing
bandgap registers could hang the system.

This patch checks the return value of clk_enable(), logs an error,
releases the spinlock, and returns NOTIFY_BAD to prevent further
access.

Signed-off-by: Zhaoyang Yu <2426767509@qq.com>
---
 drivers/thermal/ti-soc-thermal/ti-bandgap.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.c b/drivers/thermal/ti-soc-thermal/ti-bandgap.c
index ba43399d0b38..04158df104f3 100644
--- a/drivers/thermal/ti-soc-thermal/ti-bandgap.c
+++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.c
@@ -1206,8 +1206,15 @@ static int bandgap_omap_cpu_notifier(struct notifier_block *nb,
 	case CPU_CLUSTER_PM_EXIT:
 		if (bgp->is_suspended)
 			break;
-		if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
-			clk_enable(bgp->fclock);
+		if (TI_BANDGAP_HAS(bgp, CLK_CTRL)) {
+			int ret = clk_enable(bgp->fclock);
+
+			if (ret) {
+				dev_err(bgp->dev, "Failed to enable clock on PM exit: %d\n", ret);
+				spin_unlock(&bgp->lock);
+				return NOTIFY_BAD;
+			}
+		}
 		ti_bandgap_power(bgp, true);
 		ti_bandgap_restore_ctxt(bgp);
 		break;
-- 
2.34.1