From: Zhang Shurong <zhang_shurong@foxmail.com>
To: jic23@kernel.org
Cc: lars@metafoo.de, mcoquelin.stm32@gmail.com,
alexandre.torgue@foss.st.com, lgirdwood@gmail.com,
broonie@kernel.org, linux-iio@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Zhang Shurong <zhang_shurong@foxmail.com>
Subject: [PATCH] io: adc: stm32-adc: fix potential NULL pointer dereference in stm32_adc_probe()
Date: Sat, 15 Jul 2023 23:55:50 +0800 [thread overview]
Message-ID: <tencent_994DA85912C937E3B5405BA960B31ED90A08@qq.com> (raw)
of_match_device() may fail and returns a NULL pointer.
Fix this by checking the return value of of_match_device().
Fixes: 64ad7f6438f3 ("iio: adc: stm32: introduce compatible data cfg")
Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
---
drivers/iio/adc/stm32-adc-core.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/adc/stm32-adc-core.c b/drivers/iio/adc/stm32-adc-core.c
index 48f02dcc81c1..70011fdbf5f6 100644
--- a/drivers/iio/adc/stm32-adc-core.c
+++ b/drivers/iio/adc/stm32-adc-core.c
@@ -706,6 +706,8 @@ static int stm32_adc_probe(struct platform_device *pdev)
struct stm32_adc_priv *priv;
struct device *dev = &pdev->dev;
struct device_node *np = pdev->dev.of_node;
+ const struct of_device_id *of_id;
+
struct resource *res;
u32 max_rate;
int ret;
@@ -718,8 +720,11 @@ static int stm32_adc_probe(struct platform_device *pdev)
return -ENOMEM;
platform_set_drvdata(pdev, &priv->common);
- priv->cfg = (const struct stm32_adc_priv_cfg *)
- of_match_device(dev->driver->of_match_table, dev)->data;
+ of_id = of_match_device(dev->driver->of_match_table, dev);
+ if (!of_id)
+ return -ENODEV;
+
+ priv->cfg = (const struct stm32_adc_priv_cfg *)of_id->data;
priv->nb_adc_max = priv->cfg->num_adcs;
spin_lock_init(&priv->common.lock);
--
2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next reply other threads:[~2023-07-15 15:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-15 15:55 Zhang Shurong [this message]
2023-07-16 16:08 ` [PATCH] io: adc: stm32-adc: fix potential NULL pointer dereference in stm32_adc_probe() Jonathan Cameron
2023-08-28 15:02 ` Zhang Shurong
2023-08-28 16:16 ` Jonathan Cameron
2023-08-28 16:35 ` Zhang Shurong
2023-09-03 10:41 ` Jonathan Cameron
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=tencent_994DA85912C937E3B5405BA960B31ED90A08@qq.com \
--to=zhang_shurong@foxmail.com \
--cc=alexandre.torgue@foss.st.com \
--cc=broonie@kernel.org \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox