Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5265223imm; Tue, 18 Sep 2018 06:57:54 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbUOASPrJjytxRlXpKJ+KuNVZ7dENVIdRK9cjP98I6v7PMRtxjnKcZY+WnXeuC4Qd46XlzI X-Received: by 2002:a17:902:724c:: with SMTP id c12-v6mr29250656pll.326.1537279074709; Tue, 18 Sep 2018 06:57:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537279074; cv=none; d=google.com; s=arc-20160816; b=Ax/7dKYkb8kum3vywvgEx+Uvy5Jhs3W8PYOnwLUXGnaUOJLAhSxJMgiY30TbfbHVMy sXp4Jd8Oso1PfUvJZgRyygksqzJwACWvRBqWyD+js9JuS7MQ+kJg+g/UMWWtapmdHgU4 qYNw2aCpl9TrYHQePod8HjY9M5nc5GMgyCOrLSPZr10p1hnIzMapTkHrq2oOPzBJPN/p 9YQ8SXbwHx712b+trskyA0CemeLfqf1iaCbzYGlTsjUnu3PBGlphWn0/ed7QHnhspuUa lt8W3H+uBYzuBz+jx3Qbr8EPsfTg4oAgpVI+Se3L6WuGdzZHoWpRCbExUABusoiuK4nZ qVYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=MyTxeNgwnefIEggmLXpx6M4zOu/ifQGUCzYXahEUT7k=; b=aD/P/ryXO0tXfXgubfMQV5NN54UrMXNh105JndMXSCbQgiDoNxVO2iG10qTgO/p/MG 7TD6z+Mc4KJhnIvfKM3zZoNBO1CEK7BNQA6McC3P0GT9UeIc44e94ojErQsChQk++Cjk ojXp9kutLc1IdZiJtXGPeaIeL1TML0inSLOQH9Y7LU1wizq/iJu7HrgNp1CHXJnFA7BX AS7YAWw/A/XOPXHw07mV0ZHtR40XmZ7OzvU3/b683gia9yqkHwG3EW5DDudnrqflrIqx /uBXh1iBXf8OuXdOnm85zOu9diEmG6eeMNSGv1Gmb3N9Q4ZlN3O3bhCS+VqNT2WjaA45 p2qw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i126-v6si18967259pgd.332.2018.09.18.06.57.39; Tue, 18 Sep 2018 06:57:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729749AbeIRT3B (ORCPT + 99 others); Tue, 18 Sep 2018 15:29:01 -0400 Received: from gateway23.websitewelcome.com ([192.185.49.179]:22163 "EHLO gateway23.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727846AbeIRT3B (ORCPT ); Tue, 18 Sep 2018 15:29:01 -0400 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway23.websitewelcome.com (Postfix) with ESMTP id 9BF08B1D0 for ; Tue, 18 Sep 2018 08:56:17 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id 2GTugRdRbBcCX2GU5gqQNR; Tue, 18 Sep 2018 08:56:16 -0500 X-Authority-Reason: nr=8 Received: from [189.250.49.176] (port=39462 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1g2GTt-001Kce-9E; Tue, 18 Sep 2018 08:55:57 -0500 Date: Tue, 18 Sep 2018 08:55:55 -0500 From: "Gustavo A. R. Silva" To: Tudor Ambarus , Boris Brezillon , Miquel Raynal , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , Nicolas Ferre , Alexandre Belloni , Ludovic Desroches Cc: linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH v2] mtd: rawnand: atmel: Fix potential NULL pointer dereference Message-ID: <20180918135555.GA18114@embeddedor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) 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.250.49.176 X-Source-L: No X-Exim-ID: 1g2GTt-001Kce-9E X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.49.176]:39462 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 39 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is a potential execution path in which function of_find_compatible_node() returns NULL. In such a case, we end up having a NULL pointer dereference when accessing pointer *nfc_np* in function of_clk_get(). So, we better don't take any chances and fix this by null checking pointer *nfc_np* before calling of_clk_get(). Addresses-Coverity-ID: 1473052 ("Dereference null return value") Fixes: f88fc122cc34 ("mtd: nand: Cleanup/rework the atmel_nand driver") Signed-off-by: Gustavo A. R. Silva --- Changes in v2: - Add Fixes tag to the commit log. - Remove blank line before null checking nfc_np. drivers/mtd/nand/raw/atmel/nand-controller.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/mtd/nand/raw/atmel/nand-controller.c b/drivers/mtd/nand/raw/atmel/nand-controller.c index a38633a..5bfbe97 100644 --- a/drivers/mtd/nand/raw/atmel/nand-controller.c +++ b/drivers/mtd/nand/raw/atmel/nand-controller.c @@ -2034,6 +2034,10 @@ atmel_hsmc_nand_controller_legacy_init(struct atmel_hsmc_nand_controller *nc) nand_np = dev->of_node; nfc_np = of_find_compatible_node(dev->of_node, NULL, "atmel,sama5d3-nfc"); + if (!nfc_np) { + dev_err(dev, "Could not find device node for sama5d3-nfc\n"); + return -ENODEV; + } nc->clk = of_clk_get(nfc_np, 0); if (IS_ERR(nc->clk)) { -- 2.7.4