diff mbox

Gpio - Fix possible NULL derefrence.

Message ID 1485515642-3310-1-git-send-email-shailendra.v@samsung.com
State New
Headers show

Commit Message

Shailendra Verma Jan. 27, 2017, 11:14 a.m. UTC
of_match_device could return NULL, and so can cause a NULL
pointer dereference later.

Signed-off-by: Shailendra Verma <shailendra.v@samsung.com>
---
 drivers/gpio/gpio-ge.c  |    5 +++++
 drivers/gpio/gpio-mxs.c |    5 +++++
 2 files changed, 10 insertions(+)
diff mbox

Patch

diff --git a/drivers/gpio/gpio-ge.c b/drivers/gpio/gpio-ge.c
index 8650b29..395a85d 100644
--- a/drivers/gpio/gpio-ge.c
+++ b/drivers/gpio/gpio-ge.c
@@ -59,6 +59,11 @@  static int __init gef_gpio_probe(struct platform_device *pdev)
 	void __iomem *regs;
 	int ret;
 
+	if (!of_id) {
+		dev_err(&pdev->dev, "Error: No device match found\n");
+		return -ENODEV;
+	}
+
 	gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
 	if (!gc)
 		return -ENOMEM;
diff --git a/drivers/gpio/gpio-mxs.c b/drivers/gpio/gpio-mxs.c
index ee17248..e28097f 100644
--- a/drivers/gpio/gpio-mxs.c
+++ b/drivers/gpio/gpio-mxs.c
@@ -272,6 +272,11 @@  static int mxs_gpio_probe(struct platform_device *pdev)
 	int irq_base;
 	int err;
 
+	if (!of_id) {
+		dev_err(&pdev->dev, "Error: No device match found\n");
+		return -ENODEV;
+	}
+
 	port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL);
 	if (!port)
 		return -ENOMEM;