* [PATCH] input: mtk-pmic-keys: Fix potential NULL pointer dereference in probe()
@ 2025-12-10 3:00 Haotian Zhang
2025-12-10 4:48 ` Dmitry Torokhov
2025-12-10 14:11 ` Markus Elfring
0 siblings, 2 replies; 3+ messages in thread
From: Haotian Zhang @ 2025-12-10 3:00 UTC (permalink / raw)
To: dmitry.torokhov, matthias.bgg, angelogioacchino.delregno
Cc: louisalexis.eyraud, bisson.gary, julien.massot, linux-input,
linux-kernel, linux-arm-kernel, linux-mediatek, Haotian Zhang
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] input: mtk-pmic-keys: Fix potential NULL pointer dereference in probe()
2025-12-10 3:00 [PATCH] input: mtk-pmic-keys: Fix potential NULL pointer dereference in probe() Haotian Zhang
@ 2025-12-10 4:48 ` Dmitry Torokhov
2025-12-10 14:11 ` Markus Elfring
1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2025-12-10 4:48 UTC (permalink / raw)
To: Haotian Zhang
Cc: matthias.bgg, angelogioacchino.delregno, louisalexis.eyraud,
bisson.gary, julien.massot, linux-input, linux-kernel,
linux-arm-kernel, linux-mediatek
Hi Haotian,
On Wed, Dec 10, 2025 at 11:00:13AM +0800, Haotian Zhang wrote:
> 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.
How are we getting into probe() without matching compatible?
We already had a discussion about this in [1] and patched the MFD
portion to not use generic driver name when instantiating the keypad
sub-device.
[1] http://lore.kernel.org/r/20250630-mtk-pmic-keys-fix-crash-v1-1-e47351fa9d1f@collabora.com
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] input: mtk-pmic-keys: Fix potential NULL pointer dereference in probe()
2025-12-10 3:00 [PATCH] input: mtk-pmic-keys: Fix potential NULL pointer dereference in probe() Haotian Zhang
2025-12-10 4:48 ` Dmitry Torokhov
@ 2025-12-10 14:11 ` Markus Elfring
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2025-12-10 14:11 UTC (permalink / raw)
To: vulab, linux-input, linux-mediatek, linux-arm-kernel
Cc: LKML, Angelo Gioacchino Del Regno, Dmitry Torokhov, Gary Bisson,
Julien Massot, Louis-Alexis Eyraud, Matthias Brugger
> 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.
…
Under which circumstances would you get into the mood to take more desirable
word wrap preferences better into account?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.18#n658
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-10 14:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-10 3:00 [PATCH] input: mtk-pmic-keys: Fix potential NULL pointer dereference in probe() Haotian Zhang
2025-12-10 4:48 ` Dmitry Torokhov
2025-12-10 14:11 ` Markus Elfring
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).