[PATCH 1/1] drivers:rtc: fix return value check in mpfs_rtc_probe()

Yuanjun Gong ruc_gongyuanjun at 163.com
Mon Jul 17 07:47:05 PDT 2023


in mpfs_rtc_probe, devm_clk_get may fail, and its return value
should be checked before passing to clk_get_rate().

Signed-off-by: Yuanjun Gong <ruc_gongyuanjun at 163.com>
---
 drivers/rtc/rtc-mpfs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-mpfs.c b/drivers/rtc/rtc-mpfs.c
index 5b96a6d39210..c126df40c343 100644
--- a/drivers/rtc/rtc-mpfs.c
+++ b/drivers/rtc/rtc-mpfs.c
@@ -257,7 +257,11 @@ static int mpfs_rtc_probe(struct platform_device *pdev)
 	}
 
 	/* prescaler hardware adds 1 to reg value */
-	prescaler = clk_get_rate(devm_clk_get(&pdev->dev, "rtcref")) - 1;
+	clk = devm_clk_get(&pdev->dev, "rtcref");
+	if (IS_ERR(clk))
+		return PTR_ERR(clk);
+	prescaler = clk_get_rate(clk) - 1;
+
 	if (prescaler > MAX_PRESCALER_COUNT) {
 		dev_dbg(&pdev->dev, "invalid prescaler %lu\n", prescaler);
 		return -EINVAL;
-- 
2.17.1




More information about the linux-riscv mailing list