From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B7A1ECE564 for ; Tue, 18 Sep 2018 13:40:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4162F2086E for ; Tue, 18 Sep 2018 13:40:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4162F2086E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bootlin.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729680AbeIRTNQ (ORCPT ); Tue, 18 Sep 2018 15:13:16 -0400 Received: from mail.bootlin.com ([62.4.15.54]:42956 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728413AbeIRTNQ (ORCPT ); Tue, 18 Sep 2018 15:13:16 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 6563520734; Tue, 18 Sep 2018 15:40:35 +0200 (CEST) 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 1120E206DE; Tue, 18 Sep 2018 15:40:25 +0200 (CEST) Date: Tue, 18 Sep 2018 15:40:25 +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] mtd: rawnand: atmel: Fix potential NULL pointer dereference Message-ID: <20180918154025.55137b03@bbrezillon> In-Reply-To: <20180918133317.GA17358@embeddedor.com> References: <20180918133317.GA17358@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 Hi Gustavo, On Tue, 18 Sep 2018 08:33:17 -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") Can you add a Fixes tag here? > Signed-off-by: Gustavo A. R. Silva > --- > drivers/mtd/nand/raw/atmel/nand-controller.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/drivers/mtd/nand/raw/atmel/nand-controller.c b/drivers/mtd/nand/raw/atmel/nand-controller.c > index a38633a..ffa0c6b6 100644 > --- a/drivers/mtd/nand/raw/atmel/nand-controller.c > +++ b/drivers/mtd/nand/raw/atmel/nand-controller.c > @@ -2035,6 +2035,11 @@ atmel_hsmc_nand_controller_legacy_init(struct atmel_hsmc_nand_controller *nc) > nfc_np = of_find_compatible_node(dev->of_node, NULL, > "atmel,sama5d3-nfc"); > Can you drop this blank line? > + 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)) { > ret = PTR_ERR(nc->clk); Thanks, Boris