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=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 90169C433F5 for ; Mon, 27 Aug 2018 18:44:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 37747208D5 for ; Mon, 27 Aug 2018 18:44:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 37747208D5 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 S1727178AbeH0Wbw (ORCPT ); Mon, 27 Aug 2018 18:31:52 -0400 Received: from mail.bootlin.com ([62.4.15.54]:49633 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726826AbeH0Wbv (ORCPT ); Mon, 27 Aug 2018 18:31:51 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 56BEA207EB; Mon, 27 Aug 2018 20:44:05 +0200 (CEST) Received: from bbrezillon (unknown [91.160.177.164]) by mail.bootlin.com (Postfix) with ESMTPSA id 9271E2079D; Mon, 27 Aug 2018 20:43:54 +0200 (CEST) Date: Mon, 27 Aug 2018 20:43:49 +0200 From: Boris Brezillon To: Masahiro Yamada Cc: linux-mtd@lists.infradead.org, Miquel Raynal , Marek Vasut , Richard Weinberger , linux-kernel@vger.kernel.org, Brian Norris , David Woodhouse Subject: Re: [PATCH v2] mtd: rawnand: denali: do not pass zero maxchips to nand_scan() Message-ID: <20180827204349.47f21c05@bbrezillon> In-Reply-To: <1535353301-1727-1-git-send-email-yamada.masahiro@socionext.com> References: <1535353301-1727-1-git-send-email-yamada.masahiro@socionext.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 Mon, 27 Aug 2018 16:01:41 +0900 Masahiro Yamada wrote: > Commit 49aa76b16676 ("mtd: rawnand: do not execute nand_scan_ident() > if maxchips is zero") gave a new meaning for calling nand_scan_ident() > with maxchips=0. > > It is a special usage for some drivers such as docg4, but actually > the Denali driver may pass maxchips=0 to nand_scan() when the driver > is enabled but no NAND chip is found on the board for some reasons. > > If nand_scan_with_ids() is called with maxchips=0, nand_scan_ident() > is skipped, then nand_set_defaults() is skipped as well. Thus, the > driver must set chip->controller beforehand. Otherwise, nand_attach() > causes NULL pointer dereference. > > In fact, the Denali controller knows the number of connected chips > before calling nand_scan_ident(); if DEVICE_RESET fails, there is no > chip in that chip select. Then, denali_reset_banks() sets the maxchips > to the number of detected chips. If no chip is found, maxchips is zero. > > In this case, there is no point for calling nand_scan() because we know > it will fail for sure. Let's make the probe function fail immediately. > > Signed-off-by: Masahiro Yamada Queued to mtd/master after adding 49aa76b16676 ("mtd: rawnand: do not execute nand_scan_ident() if maxchips is zero") Thanks, Boris > --- > > Changes in v2: > - Return -ENODEV immediately if no chip was found on the board > for some reasons. > This is the smallest, and safest change for the fixes branch. > (I will investigate later if further cleanups are possible or not.) > > drivers/mtd/nand/raw/denali.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/drivers/mtd/nand/raw/denali.c b/drivers/mtd/nand/raw/denali.c > index ca18612..67b2065 100644 > --- a/drivers/mtd/nand/raw/denali.c > +++ b/drivers/mtd/nand/raw/denali.c > @@ -1338,6 +1338,11 @@ int denali_init(struct denali_nand_info *denali) > > denali_enable_irq(denali); > denali_reset_banks(denali); > + if (!denali->max_banks) { > + /* Error out earlier if no chip is found for some reasons. */ > + ret = -ENODEV; > + goto disable_irq; > + } > > denali->active_bank = DENALI_INVALID_BANK; >