[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251210030013.913-1-vulab@iscas.ac.cn>
Date: Wed, 10 Dec 2025 11:00:13 +0800
From: Haotian Zhang <vulab@...as.ac.cn>
To: dmitry.torokhov@...il.com,
matthias.bgg@...il.com,
angelogioacchino.delregno@...labora.com
Cc: louisalexis.eyraud@...labora.com,
bisson.gary@...il.com,
julien.massot@...labora.com,
linux-input@...r.kernel.org,
linux-kernel@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org,
linux-mediatek@...ts.infradead.org,
Haotian Zhang <vulab@...as.ac.cn>
Subject: [PATCH] input: mtk-pmic-keys: Fix potential NULL pointer dereference in probe()
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@...as.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
Powered by blists - more mailing lists