From patchwork Mon Nov 16 18:45:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 545113 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 8407114141A for ; Tue, 17 Nov 2015 05:47:49 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=qmCN5PXF; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZyOmz-0005eP-80; Mon, 16 Nov 2015 18:46:05 +0000 Received: from mail-pa0-x232.google.com ([2607:f8b0:400e:c03::232]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZyOmw-0005Rl-I2 for linux-mtd@lists.infradead.org; Mon, 16 Nov 2015 18:46:03 +0000 Received: by pacdm15 with SMTP id dm15so182977698pac.3 for ; Mon, 16 Nov 2015 10:45:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iUExhCALESRYq0Emv91wVscBWwtGR6XlwLCD7f3IKwA=; b=qmCN5PXFyhFR62InjlN59x41vaau2jWiWUkY28s0BPSKbZtciGMMo31z3EN6+DW9S2 m2in/pLdTg3ZyasQ91J0vA1iosjDm/sBqGR9mXkHl3qOGl5LGRJB6GTLqYyjJINzEQiO 86vXhC44XWEe6Z/bm2MC+wbnt018fwA5Yny5jWEiRFFtKu+26Aga9LINlQlMLRWe86ZY kwyEYxPgz/ySH8DSYXfXDWLY2ajGknDYvRCg+YRsyiicp765k5hn7fh5qu9kuc+4Ls3H neiTniZpozjR0aI6p2aIMJwwc9m0m7453xw5Rzs+kjQnO0ZBr+pSf6oHMiDTg9xKIZ/o jA5A== X-Received: by 10.66.150.5 with SMTP id ue5mr42154703pab.42.1447699541340; Mon, 16 Nov 2015 10:45:41 -0800 (PST) Received: from ban.mtv.corp.google.com ([172.22.64.120]) by smtp.gmail.com with ESMTPSA id yc5sm7129738pbb.47.2015.11.16.10.45.40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Nov 2015 10:45:40 -0800 (PST) From: Brian Norris To: Subject: [PATCH v2] mtd: fsl-quadspi: possible NULL dereference Date: Mon, 16 Nov 2015 10:45:30 -0800 Message-Id: <1447699530-50014-1-git-send-email-computersforpeace@gmail.com> X-Mailer: git-send-email 2.6.0.rc2.230.g3dd15c0 In-Reply-To: <1447699339-43027-1-git-send-email-computersforpeace@gmail.com> References: <1447699339-43027-1-git-send-email-computersforpeace@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151116_104602_653198_498BC7F7 X-CRM114-Status: GOOD ( 12.07 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2607:f8b0:400e:c03:0:0:0:232 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (computersforpeace[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Brian Norris , linux-kernel@vger.kernel.org, Han Xu MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org It is theoretically possible to probe this driver without a matching device tree, so let's guard against this. Also, use the of_device_get_match_data() helper to make this a bit simpler. Coverity complained about this one. Signed-off-by: Brian Norris Cc: Han Xu Acked-by: Han xu --- v2: * missed a 'const' warning * s/reference/dereference in $subject drivers/mtd/spi-nor/fsl-quadspi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/spi-nor/fsl-quadspi.c b/drivers/mtd/spi-nor/fsl-quadspi.c index cc3a70b9b020..916d6dd5b575 100644 --- a/drivers/mtd/spi-nor/fsl-quadspi.c +++ b/drivers/mtd/spi-nor/fsl-quadspi.c @@ -269,7 +269,7 @@ struct fsl_qspi { struct clk *clk, *clk_en; struct device *dev; struct completion c; - struct fsl_qspi_devtype_data *devtype_data; + const struct fsl_qspi_devtype_data *devtype_data; u32 nor_size; u32 nor_num; u32 clk_rate; @@ -933,8 +933,6 @@ static int fsl_qspi_probe(struct platform_device *pdev) struct spi_nor *nor; struct mtd_info *mtd; int ret, i = 0; - const struct of_device_id *of_id = - of_match_device(fsl_qspi_dt_ids, &pdev->dev); q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL); if (!q) @@ -945,7 +943,9 @@ static int fsl_qspi_probe(struct platform_device *pdev) return -ENODEV; q->dev = dev; - q->devtype_data = (struct fsl_qspi_devtype_data *)of_id->data; + q->devtype_data = of_device_get_match_data(dev); + if (!q->devtype_data) + return -ENODEV; platform_set_drvdata(pdev, q); /* find the resources */