Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5267164imm; Tue, 18 Sep 2018 06:59:49 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZZw44g0qQXnxWLMxdMNxGV8a14G2Jpym7bY6H4n2qQeopkG00sRdbfxSlU4gW5wXyEMdCI X-Received: by 2002:a62:3ac8:: with SMTP id v69-v6mr31017166pfj.164.1537279188928; Tue, 18 Sep 2018 06:59:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537279188; cv=none; d=google.com; s=arc-20160816; b=UJIbI3c5v0J1OJ7VfRdBChpQy++NgQBdGdyNDjBZeomG9DfO//G93OYTz2l6Xay13L jBvvoJ/CqNrmRk9iKuwdQ5So2cCYWC21p9z5zBBZQnLF+uUgpQf90uKOrmN0+Rrh5pSG E1txiquR/59DAnTdxiLdcexMEhKFOxtxVRvqlPiKgahmLjin6nqEi4NNp6qcTSdKNhyN bQmELmlgbUtPoQoCSyHuXe8Bv744ps0kyNiXHHcIrdNmAY0hSvGHO6XtfrGcn3RpwWyB 947uDRtRQQiFrqWxkZIISNBUSRNnyE64BAg3cOpQDCy+unpAHmlWikQALKH+E+6N5tw2 qoaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=YTk2JFpLhuGNLkzaUOJvrkh3V7l7WIDrVvP6YiXGW2c=; b=l8bIPgG9O7J3BMpZY2UJ2qVAVTKsdF7cjYE5Hh2n9iDetiZKnw0bQE/x5Pubu+etSB oFgqDiNFrYY5lrWpjlp07ATL2lUy/dGAwXZg2rxDZYujcZfcrCsoAOWi0nWjaVOpU4lj geql4fIfDVIctj5NjJCcSZ+ENM3zycsm5mpq2gFT7d1pSV1ur1mPY+fiKQW7D7DFlbIG URz0c5r4mGVjsmtnykA8rEWh4Wha83+s3GUEZt2i/ySuVlOsd+oqWiC07beRBWR0Fwcu H4RjrhP6M8XRF+kpdSO4DxMlqkDFXRemwW9DVk3KJfHsAXDfCkzCzQzwTeZIIUBN0wCc nn5g== 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 u3-v6si18421743plb.401.2018.09.18.06.59.30; Tue, 18 Sep 2018 06:59:48 -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 S1729773AbeIRTbq (ORCPT + 99 others); Tue, 18 Sep 2018 15:31:46 -0400 Received: from mail.bootlin.com ([62.4.15.54]:43958 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728413AbeIRTbq (ORCPT ); Tue, 18 Sep 2018 15:31:46 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 060EF20734; Tue, 18 Sep 2018 15:59:00 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (AAubervilliers-681-1-99-10.w90-88.abo.wanadoo.fr [90.88.4.10]) by mail.bootlin.com (Postfix) with ESMTPSA id A7262206DE; Tue, 18 Sep 2018 15:58:49 +0200 (CEST) Date: Tue, 18 Sep 2018 15:58:49 +0200 From: Boris Brezillon To: "Gustavo A. R. Silva" Cc: Tudor Ambarus , Miquel Raynal , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , Nicolas Ferre , Alexandre Belloni , Ludovic Desroches , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mtd: rawnand: atmel: Fix potential NULL pointer dereference Message-ID: <20180918155849.178c5f48@bbrezillon> In-Reply-To: <20180918135555.GA18114@embeddedor.com> References: <20180918135555.GA18114@embeddedor.com> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 18 Sep 2018 08:55:55 -0500 "Gustavo A. R. Silva" wrote: > 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 Reviewed-by: Boris Brezillon > --- > 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)) {