From: Zhang Shurong <zhang_shurong@foxmail.com>
To: shawnguo@kernel.org
Cc: s.hauer@pengutronix.de, kernel@pengutronix.de,
festevam@gmail.com, linux-imx@nxp.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Zhang Shurong <zhang_shurong@foxmail.com>
Subject: [PATCH] bus: imx-weim: fix to avoid potential NULL pointer dereference
Date: Sat, 15 Jul 2023 23:21:01 +0800 [thread overview]
Message-ID: <tencent_0ED0DF5CD5426F55806D79D028F8A10E490A@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: 3f98b6baad63 ("drivers: bus: imx-weim: Add support for i.MX1/21/25/27/31/35/50/51/53")
Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
---
drivers/bus/imx-weim.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
index 52a5d0447390..65402bb60c18 100644
--- a/drivers/bus/imx-weim.c
+++ b/drivers/bus/imx-weim.c
@@ -202,15 +202,19 @@ static int weim_timing_setup(struct device *dev, struct device_node *np,
static int weim_parse_dt(struct platform_device *pdev)
{
- const struct of_device_id *of_id = of_match_device(weim_id_table,
- &pdev->dev);
- const struct imx_weim_devtype *devtype = of_id->data;
+ const struct of_device_id *of_id;
+ const struct imx_weim_devtype *devtype;
int ret = 0, have_child = 0;
struct device_node *child;
struct weim_priv *priv;
void __iomem *base;
u32 reg;
+ of_id = of_match_device(weim_id_table, &pdev->dev);
+ if (!of_id)
+ return -EINVAL;
+
+ devtype = of_id->data;
if (devtype == &imx50_weim_devtype) {
ret = imx_weim_gpr_setup(pdev);
if (ret)
--
2.30.2
next reply other threads:[~2023-07-15 15:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-15 15:21 Zhang Shurong [this message]
2023-07-15 16:38 ` Fabio Estevam
2023-08-28 15:03 ` Zhang Shurong
2023-08-28 18:41 ` Fabio Estevam
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_0ED0DF5CD5426F55806D79D028F8A10E490A@qq.com \
--to=zhang_shurong@foxmail.com \
--cc=festevam@gmail.com \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
/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
all inboxes | Powered by JetHome®