Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751981AbdGGG7a (ORCPT ); Fri, 7 Jul 2017 02:59:30 -0400 Received: from gateway33.websitewelcome.com ([192.185.145.82]:42183 "EHLO gateway33.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751001AbdGGG73 (ORCPT ); Fri, 7 Jul 2017 02:59:29 -0400 Date: Fri, 7 Jul 2017 01:59:26 -0500 From: "Gustavo A. R. Silva" To: Stefan Agner , Boris Brezillon , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , Cyrille Pitchen Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] mtd: nand: vf610_nfc: add NULL check on of_match_device() return value Message-ID: <20170707065926.GA25776@embeddedgus> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.152.152.176 X-Exim-ID: 1dTNEc-002OVS-T5 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedgus) [189.152.152.176]:60220 X-Source-Auth: garsilva@embeddedor.com X-Email-Count: 63 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 831 Lines: 28 Check return value from call to of_match_device() in order to prevent a NULL pointer dereference. In case of NULL print error message and return -ENODEV Signed-off-by: Gustavo A. R. Silva --- drivers/mtd/nand/vf610_nfc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c index 744ab10..ca0ab96 100644 --- a/drivers/mtd/nand/vf610_nfc.c +++ b/drivers/mtd/nand/vf610_nfc.c @@ -674,6 +674,11 @@ static int vf610_nfc_probe(struct platform_device *pdev) } of_id = of_match_device(vf610_nfc_dt_ids, &pdev->dev); + if (!of_id) { + dev_err(&pdev->dev, "Failed to match device!\n"); + return -ENODEV; + } + nfc->variant = (enum vf610_nfc_variant)of_id->data; for_each_available_child_of_node(nfc->dev->of_node, child) { -- 2.5.0