[PATCH] rtc: mt6397: Fix potential NULL dereference in mtk_rtc_probe

Miaoqian Lin linmq006 at gmail.com
Mon Apr 4 06:25:53 PDT 2022


platform_get_resource() may return NULL, add proper check to
avoid potential NULL dereferencing.

Fixes: fc2979118f3f ("rtc: mediatek: Add MT6397 RTC driver")
Signed-off-by: Miaoqian Lin <linmq006 at gmail.com>
---
 drivers/rtc/rtc-mt6397.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index 80dc479a6ff0..07c6679366e0 100644
--- a/drivers/rtc/rtc-mt6397.c
+++ b/drivers/rtc/rtc-mt6397.c
@@ -269,6 +269,9 @@ static int mtk_rtc_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
+
 	rtc->addr_base = res->start;
 
 	rtc->data = of_device_get_match_data(&pdev->dev);
-- 
2.17.1




More information about the Linux-mediatek mailing list