From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Zhang Shurong <zhang_shurong@foxmail.com>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
Sasha Levin <sashal@kernel.org>,
jic23@kernel.org, mcoquelin.stm32@gmail.com,
alexandre.torgue@foss.st.com, robh@kernel.org,
u.kleine-koenig@pengutronix.de, frank.li@vivo.com,
heiko@sntech.de, olivier.moysan@foss.st.com,
linux-iio@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH AUTOSEL 6.6 01/18] iio: adc: stm32-adc: harden against NULL pointer deref in stm32_adc_probe()
Date: Tue, 7 Nov 2023 18:21:55 -0500 [thread overview]
Message-ID: <20231107232231.3775605-1-sashal@kernel.org> (raw)
From: Zhang Shurong <zhang_shurong@foxmail.com>
[ Upstream commit 3a23b384e7e3d64d5587ad10729a34d4f761517e ]
of_match_device() may fail and returns a NULL pointer.
In practice there is no known reasonable way to trigger this, but
in case one is added in future, harden the code by adding the check
Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
Link: https://lore.kernel.org/r/tencent_994DA85912C937E3B5405BA960B31ED90A08@qq.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
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 2f082006550fd..bbd5bdd732f01 100644
--- a/drivers/iio/adc/stm32-adc-core.c
+++ b/drivers/iio/adc/stm32-adc-core.c
@@ -708,6 +708,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;
@@ -720,8 +722,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.42.0
next reply other threads:[~2023-11-07 23:22 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-07 23:21 Sasha Levin [this message]
2023-11-07 23:21 ` [PATCH AUTOSEL 6.6 02/18] thunderbolt: Apply USB 3.x bandwidth quirk only in software connection manager Sasha Levin
2023-11-07 23:21 ` [PATCH AUTOSEL 6.6 03/18] tty: vcc: Add check for kstrdup() in vcc_probe() Sasha Levin
2023-11-07 23:21 ` [PATCH AUTOSEL 6.6 04/18] dt-bindings: phy: qcom,snps-eusb2-repeater: Add magic tuning overrides Sasha Levin
2023-11-07 23:21 ` [PATCH AUTOSEL 6.6 05/18] phy: qualcomm: phy-qcom-eusb2-repeater: Use regmap_fields Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 06/18] phy: qualcomm: phy-qcom-eusb2-repeater: Zero out untouched tuning regs Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 07/18] usb: dwc3: core: configure TX/RX threshold for DWC3_IP Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 08/18] usb: pci-quirks: group AMD specific quirk code together Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 09/18] usb: pci-quirks: handle HAS_IOPORT dependency for AMD quirk Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 10/18] usb: pci-quirks: handle HAS_IOPORT dependency for UHCI handoff Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 11/18] usb: ucsi: glink: use the connector orientation GPIO to provide switch events Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 12/18] soundwire: dmi-quirks: update HP Omen match Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 13/18] f2fs: fix error path of __f2fs_build_free_nids Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 14/18] f2fs: fix error handling of __get_node_page Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 15/18] usb: host: xhci: Avoid XHCI resume delay if SSUSB device is not present Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 16/18] usb: gadget: f_ncm: Always set current gadget in ncm_bind() Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 17/18] 9p/trans_fd: Annotate data-racy writes to file::f_flags Sasha Levin
2023-11-07 23:22 ` [PATCH AUTOSEL 6.6 18/18] 9p: v9fs_listxattr: fix %s null argument warning Sasha Levin
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=20231107232231.3775605-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=alexandre.torgue@foss.st.com \
--cc=frank.li@vivo.com \
--cc=heiko@sntech.de \
--cc=jic23@kernel.org \
--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 \
--cc=olivier.moysan@foss.st.com \
--cc=robh@kernel.org \
--cc=stable@vger.kernel.org \
--cc=u.kleine-koenig@pengutronix.de \
--cc=zhang_shurong@foxmail.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
Powered by JetHome