diff mbox series

[01/20] hwmon: (abituguru) check return value after calling platform_get_resource()

Message ID 20220422091207.4034406-2-yangyingliang@huawei.com (mailing list archive)
State Accepted
Headers show
Series hwmon: check return value after calling platform_get_resource() | expand

Commit Message

Yang Yingliang April 22, 2022, 9:11 a.m. UTC
It will cause null-ptr-deref if platform_get_resource() returns NULL,
we need check the return value.

Fixes: f2b84bbcebfd ("[PATCH] abituguru: New hardware monitoring driver")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/hwmon/abituguru.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/hwmon/abituguru.c b/drivers/hwmon/abituguru.c
index 681f0623868f..58595567440c 100644
--- a/drivers/hwmon/abituguru.c
+++ b/drivers/hwmon/abituguru.c
@@ -1259,6 +1259,7 @@  static int abituguru_probe(struct platform_device *pdev)
 	struct abituguru_data *data;
 	int i, j, used, sysfs_names_free, sysfs_attr_i, res = -ENODEV;
 	char *sysfs_filename;
+	struct resource *r;
 
 	/*
 	 * El weirdo probe order, to keep the sysfs order identical to the
@@ -1273,7 +1274,10 @@  static int abituguru_probe(struct platform_device *pdev)
 	if (!data)
 		return -ENOMEM;
 
-	data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start;
+	r = platform_get_resource(pdev, IORESOURCE_IO, 0);
+	if (!r)
+		return -EINVAL;
+	data->addr = r->start;
 	mutex_init(&data->update_lock);
 	platform_set_drvdata(pdev, data);