From patchwork Thu Nov 15 04:54:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 1746951 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 6C24B3FCA5 for ; Thu, 15 Nov 2012 04:56:22 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TYrTK-0003lx-Fg; Thu, 15 Nov 2012 04:54:38 +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 1TYrTG-0003kn-AM for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2012 04:54:34 +0000 Received: by mail-da0-f49.google.com with SMTP id q27so473675daj.36 for ; Wed, 14 Nov 2012 20:54:33 -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=IskmLIQVas9aLeJYeMP0LPGxxTLdqX5LnAtmXiA2RXg=; b=kQNQ8BTHIpsAIjqBSnHOWJzWXW0QIkYvGTI9I7Qqht6nDCMgV0W1pD0aMcONLsPcVv sF+zl2FskQgFNC2ZNe0vl3aOoFYtq/rLbxxyP/JhGEGZnj8HKzKPUJI9ziUaw7wU+94t fN/4RxNSyLvDyUO3HBe+PDCpVKPUbkcXr5aTNkYolV8Dz4ZPbcSkKF5HIL/96qg89tTT 0JgsKoEU3Zge2qwu7QoRKW/g3QhfZmimZQTKjQ2ZtsFL+6oQHa7NJrqcb4F6RsmgQrfw l3+zFL0BMjHqjkHI5PCNQJehMtWeh88wtwKzT+JJxspqHHgiA1NTJHv42PGjwPEWnLya bIUg== Received: by 10.66.76.39 with SMTP id h7mr12799758paw.61.1352955273365; Wed, 14 Nov 2012 20:54:33 -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 hc4sm8874417pbc.30.2012.11.14.20.54.30 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 14 Nov 2012 20:54:32 -0800 (PST) Message-ID: <1352955266.6793.4.camel@phoenix> Subject: [PATCH 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:54:26 +0800 In-Reply-To: <1352955096.6793.1.camel@phoenix> References: <1352955096.6793.1.camel@phoenix> X-Mailer: Evolution 3.2.3-0ubuntu6 Mime-Version: 1.0 X-Gm-Message-State: ALoCoQn7Z+HBk8qU6wNh4pOA29+t02R/ete6m0cJiv5pAMxa6MzbrXd58TX2i+0QP2ew7y9nv+aC X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121114_235434_480920_DBCEBCCC X-CRM114-Status: GOOD ( 12.89 ) 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: Patrice Chotard , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Srinidhi Kasagar 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 --- 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;