All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yang Yingliang <yangyingliang@huawei.com>
To: <linux-kernel@vger.kernel.org>, <linux-hwmon@vger.kernel.org>
Cc: <linux@roeck-us.net>, <jdelvare@suse.com>
Subject: [PATCH 10/20] hwmon: (sch5627) check return value after calling platform_get_resource()
Date: Fri, 22 Apr 2022 17:11:57 +0800	[thread overview]
Message-ID: <20220422091207.4034406-11-yangyingliang@huawei.com> (raw)
In-Reply-To: <20220422091207.4034406-1-yangyingliang@huawei.com>

It will cause null-ptr-deref if platform_get_resource() returns NULL,
we need check the return value.

Fixes: a98d506c08ff ("hwmon: New driver for SMSC SCH5627")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/hwmon/sch5627.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/sch5627.c b/drivers/hwmon/sch5627.c
index 25fbbd4c9a2b..1294624a3ed7 100644
--- a/drivers/hwmon/sch5627.c
+++ b/drivers/hwmon/sch5627.c
@@ -423,13 +423,17 @@ static int sch5627_probe(struct platform_device *pdev)
 	struct sch5627_data *data;
 	struct device *hwmon_dev;
 	int err, build_code, build_id, hwmon_rev, val;
+	struct resource *res;
 
 	data = devm_kzalloc(&pdev->dev, sizeof(struct sch5627_data),
 			    GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
-	data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start;
+	res = platform_get_resource(pdev, IORESOURCE_IO, 0);
+	if (!res)
+		return -EINVAL;
+	data->addr = res->start;
 	mutex_init(&data->update_lock);
 	platform_set_drvdata(pdev, data);
 
-- 
2.25.1


  parent reply	other threads:[~2022-04-22  9:00 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-22  9:11 [PATCH 00/20] hwmon: check return value after calling platform_get_resource() Yang Yingliang
2022-04-22  9:11 ` [PATCH 01/20] hwmon: (abituguru) " Yang Yingliang
2022-04-22  9:11 ` [PATCH 02/20] hwmon: (abituguru3) " Yang Yingliang
2022-04-22  9:11 ` [PATCH 03/20] hwmon: (dme1737) " Yang Yingliang
2022-04-22  9:11 ` [PATCH 04/20] hwmon: (f71805f) " Yang Yingliang
2022-04-22  9:11 ` [PATCH 05/20] hwmon: (f71882fg) " Yang Yingliang
2022-04-22  9:11 ` [PATCH 06/20] hwmon: (it87) " Yang Yingliang
2022-04-22  9:11 ` [PATCH 07/20] hwmon: (lm78) " Yang Yingliang
2022-04-22  9:11 ` [PATCH 08/20] hwmon: (nct6683) " Yang Yingliang
2022-04-22  9:11 ` [PATCH 09/20] hwmon: (nct6775) " Yang Yingliang
2022-04-22  9:11 ` Yang Yingliang [this message]
2022-04-22  9:11 ` [PATCH 11/20] hwmon: (sch5636) " Yang Yingliang
2022-04-22  9:11 ` [PATCH 12/20] hwmon: (sis5595) " Yang Yingliang
2022-04-22  9:12 ` [PATCH 13/20] hwmon: (smsc47b397) " Yang Yingliang
2022-04-22  9:12 ` [PATCH 14/20] hwmon: (smsc47m1) " Yang Yingliang
2022-04-22  9:12 ` [PATCH 15/20] hwmon: (via686a) " Yang Yingliang
2022-04-22  9:12 ` [PATCH 16/20] hwmon: (vt1211) " Yang Yingliang
2022-04-22  9:12 ` [PATCH 17/20] hwmon: (vt8231) " Yang Yingliang
2022-04-22  9:12 ` [PATCH 18/20] hwmon: (w83627ehf) " Yang Yingliang
2022-04-22  9:12 ` [PATCH 19/20] hwmon: (w83627hf) " Yang Yingliang
2022-04-22  9:12 ` [PATCH 20/20] hwmon: (w83781d) " Yang Yingliang
2022-04-22 13:27 ` [PATCH 00/20] hwmon: " Guenter Roeck
2022-04-24  3:35   ` Yang Yingliang
2022-04-24  4:54     ` Guenter Roeck
2022-04-24  6:20       ` Yang Yingliang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220422091207.4034406-11-yangyingliang@huawei.com \
    --to=yangyingliang@huawei.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.