lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 15 Nov 2012 12:54:26 +0800
From:	Axel Lin <axel.lin@...ics.com>
To:	Linus Walleij <linus.walleij@...aro.org>
Cc:	Patrice Chotard <patrice.chotard@...ricsson.com>,
	Srinidhi Kasagar <srinidhi.kasagar@...ricsson.com>,
	linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org
Subject: [PATCH 3/4] pinctrl: at91: Prevent NULL dereference if
 of_match_device returns NULL

of_match_device() may return NULL.

Signed-off-by: Axel Lin <axel.lin@...ics.com>
---
 drivers/pinctrl/pinctrl-at91.c |   17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c
index 8490a55..32006c8 100644
--- a/drivers/pinctrl/pinctrl-at91.c
+++ b/drivers/pinctrl/pinctrl-at91.c
@@ -829,13 +829,18 @@ static int __devinit at91_pinctrl_probe_dt(struct platform_device *pdev,
 	uint32_t *tmp;
 	struct device_node *np = pdev->dev.of_node;
 	struct device_node *child;
+	const struct of_device_id *match;
 
 	if (!np)
 		return -ENODEV;
 
+	match = of_match_device(at91_pinctrl_of_match, &pdev->dev)->data;
+	if (!match)
+		return -ENODEV;
+
 	info->dev = &pdev->dev;
-	info->ops = (struct at91_pinctrl_mux_ops*)
-		of_match_device(at91_pinctrl_of_match, &pdev->dev)->data;
+	info->ops = (struct at91_pinctrl_mux_ops *) match->data;
+
 	at91_pinctrl_child_count(info, np);
 
 	if (info->nbanks < 1) {
@@ -1359,6 +1364,7 @@ static struct of_device_id at91_gpio_of_match[] __devinitdata = {
 static int __devinit at91_gpio_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
+	const struct of_device_id *match;
 	struct resource *res;
 	struct at91_gpio_chip *at91_chip = NULL;
 	struct gpio_chip *chip;
@@ -1399,8 +1405,11 @@ static int __devinit at91_gpio_probe(struct platform_device *pdev)
 		goto err;
 	}
 
-	at91_chip->ops = (struct at91_pinctrl_mux_ops*)
-		of_match_device(at91_gpio_of_match, &pdev->dev)->data;
+	match = of_match_device(at91_gpio_of_match, &pdev->dev);
+	if (!match)
+		return -ENODEV;
+
+	at91_chip->ops = (struct at91_pinctrl_mux_ops *) match->data;
 	at91_chip->pioc_virq = irq;
 	at91_chip->pioc_idx = alias_idx;
 
-- 
1.7.9.5



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ