Thread (13 messages) 13 messages, 3 authors, 2021-05-03
STALE1854d

[PATCH 1/7] Input: mtk-pmic-keys - check for NULL on of_match_device()

From: Mattijs Korpershoek <hidden>
Date: 2021-04-28 16:42:31
Also in: linux-input, linux-mediatek, lkml
Subsystem: input (keyboard, mouse, joystick, touchscreen) drivers, the rest · Maintainers: Dmitry Torokhov, Linus Torvalds

mtk-pmic-keys being a child device of mt6397, it will always get probed
when mt6397_probe() is called.

This also happens when we have no device tree node matching
mediatek,mt6397-keys.

In that case, the mfd core warns us:

  [    0.352175] mtk-pmic-keys: Failed to locate of_node [id: -1]

Check return value from call to of_match_device()
in order to prevent a NULL pointer dereference.

In case of NULL print error message and return -ENODEV

Signed-off-by: Mattijs Korpershoek <redacted>
---
 drivers/input/keyboard/mtk-pmic-keys.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c
index 62391d6c7da6..12c449eed026 100644
--- a/drivers/input/keyboard/mtk-pmic-keys.c
+++ b/drivers/input/keyboard/mtk-pmic-keys.c
@@ -247,6 +247,9 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
 	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)
 		return -ENOMEM;
-- 
2.27.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help