From: Haotian Zhang <vulab@iscas.ac.cn>
To: dmitry.torokhov@gmail.com, matthias.bgg@gmail.com,
angelogioacchino.delregno@collabora.com
Cc: louisalexis.eyraud@collabora.com, bisson.gary@gmail.com,
julien.massot@collabora.com, linux-input@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
Haotian Zhang <vulab@iscas.ac.cn>
Subject: [PATCH] input: mtk-pmic-keys: Fix potential NULL pointer dereference in probe()
Date: Wed, 10 Dec 2025 11:00:13 +0800 [thread overview]
Message-ID: <20251210030013.913-1-vulab@iscas.ac.cn> (raw)
of_match_device() may return NULL when the device node
does not match any entry in the driver's match table.
The current code dereferences of_id->data unconditionally,
which can lead to a NULL pointer dereference.
Add a NULL check for the return value of of_match_device()
and return -ENODEV upon failure.
Fixes: 3e9f0b3e2b27 ("input: Add MediaTek PMIC keys support")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
drivers/input/keyboard/mtk-pmic-keys.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c
index c78d9f6d97c4..474ef36605dc 100644
--- a/drivers/input/keyboard/mtk-pmic-keys.c
+++ b/drivers/input/keyboard/mtk-pmic-keys.c
@@ -335,6 +335,8 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
struct input_dev *input_dev;
const struct of_device_id *of_id =
of_match_device(of_mtk_pmic_keys_match_tbl, &pdev->dev);
+ if (!of_id)
+ return -ENODEV;
keys = devm_kzalloc(&pdev->dev, sizeof(*keys), GFP_KERNEL);
if (!keys)
--
2.50.1.windows.1
next reply other threads:[~2025-12-10 3:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-10 3:00 Haotian Zhang [this message]
2025-12-10 4:48 ` [PATCH] input: mtk-pmic-keys: Fix potential NULL pointer dereference in probe() Dmitry Torokhov
2025-12-10 14:11 ` Markus Elfring
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=20251210030013.913-1-vulab@iscas.ac.cn \
--to=vulab@iscas.ac.cn \
--cc=angelogioacchino.delregno@collabora.com \
--cc=bisson.gary@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=julien.massot@collabora.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=louisalexis.eyraud@collabora.com \
--cc=matthias.bgg@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;
as well as URLs for NNTP newsgroup(s).