From patchwork Thu Nov 15 04:58:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 1747011 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id AACF93FCA5 for ; Thu, 15 Nov 2012 04:59:59 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TYrWn-0004it-0B; Thu, 15 Nov 2012 04:58:13 +0000 Received: from mail-da0-f49.google.com ([209.85.210.49]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TYrWh-0004hc-PV for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2012 04:58:08 +0000 Received: by mail-da0-f49.google.com with SMTP id q27so474810daj.36 for ; Wed, 14 Nov 2012 20:58:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:subject:from:to:cc:date:in-reply-to:references :content-type:x-mailer:content-transfer-encoding:mime-version :x-gm-message-state; bh=TUQxWlD2k/X5HsIpWtqv098MFWfpu9glI7DX1nYsujw=; b=JpDkj/A/pC+cCFVpsk3iqRhzbHnFm843d1KwkRab1PU3WduRnvLApCvGHvsa1xiGEC bQ5XSFexYU3NgLc946tu0eeJCQaPYXzhbftjdo+UuKh3tt7h0UIQoZppHQ+jOY5ltk5l 3AxVBAFHz48mcqh5KihwBqytLRXBDFdnKWBEWqAtvPxYsjSo7xrcHp6Pf4l4eks/ZZsy fFAssk6d3NUOCr2C8ASv0FW4O1nbH069+Zs2mT92dW5cRrzAF0Lf381dAVERCYQF8jxl c2qc7SmEhXV8BT4tA3lfQiGUC1Bwhcb4vXaawVhAk3QEjuOtQOBiMiXKBJmIbFlA8QJo gf/g== Received: by 10.68.231.97 with SMTP id tf1mr892778pbc.149.1352955486347; Wed, 14 Nov 2012 20:58:06 -0800 (PST) Received: from [192.168.0.100] (114-39-103-166.dynamic.hinet.net. [114.39.103.166]) by mx.google.com with ESMTPS id c7sm9084130pay.10.2012.11.14.20.58.03 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 14 Nov 2012 20:58:05 -0800 (PST) Message-ID: <1352955480.6793.8.camel@phoenix> Subject: [PATCH RESEND 3/4] pinctrl: at91: Prevent NULL dereference if of_match_device returns NULL From: Axel Lin To: Linus Walleij Date: Thu, 15 Nov 2012 12:58:00 +0800 In-Reply-To: <1352955266.6793.4.camel@phoenix> References: <1352955096.6793.1.camel@phoenix> <1352955266.6793.4.camel@phoenix> X-Mailer: Evolution 3.2.3-0ubuntu6 Mime-Version: 1.0 X-Gm-Message-State: ALoCoQkmKZvdV1+gGgBSfF1fNBX5GBwa26CazZG9Eyn7tI2g80wJbaPUfwmnwx9wHh3Z7JuCCZHS X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121114_235808_314051_E9D162FC X-CRM114-Status: GOOD ( 12.65 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.210.49 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Jean-Christophe PLAGNIOL-VILLARD , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org of_match_device() may return NULL. Signed-off-by: Axel Lin Acked-by: Nicolas Ferre --- This resend CC Jean-Christophe. 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;