Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5602053imm; Mon, 27 Aug 2018 00:27:54 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbYrfEyctSBKlcEuDrVUpg3aC9jxeZYxw7Kq0fsDWes3ARmr3r7x4ArFs3Or52LFhwY0Ak5 X-Received: by 2002:a63:f206:: with SMTP id v6-v6mr11362137pgh.319.1535354874409; Mon, 27 Aug 2018 00:27:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535354874; cv=none; d=google.com; s=arc-20160816; b=qIu/4Up9wbr6IfFfg6fR9prA8l40l7ttB+0rTEcWI1uXU6gQrxAccM13nMMEr6NAqM 0XeSpJhAs2t6HS8OjQ1rUBg5Gd9S0oS2NSYgnkWAC7byl0yKpAipVTdsLJynKxajU8Pn 3CjfYxQ173HPddnCJNSHJisUP6IA52U7AfvkI4mHTeNmugMgdO6KPqADVNG8VjQbqzTe YiXPE+DgO4/48stQbNKKLIDN9TMtO4lA76XrntA+tozl1sHGYtJ8jwwLqoT4E1k1lECQ wLBHPtEsILNnfrVn5k4/7+QpANg466Lj8JXMLDA0x0i2TVsbwNdZ3lLR36Onl2LkirRu uqeg== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:arc-authentication-results; bh=2Hm+A1X5MHXdJGKR1O3dFFv4jqYpAM1yrVlLgA7BhTE=; b=y7I+6dZLqp0B8qnPaleTPWlOvfUygr+bLWPyQNeXJM5zTwlcLLNUGJlcePFPuZ2zPS /3ynBHVEuVaaApwdOuJ2gZvlFeg28vMVvQXECFgUiSrjrZdhwaisRxLm5rR9GzqfuWxZ a0qUi3CTbW15SnsrI/e9TsSX15B5vQpmyzxDECzbPzB5cxk279tk2HGs9wMi1x/Eg7BQ ZHpxKB6I/WRAZyC5zZ1y+Jesumo97W3HXDkdlwcC41gGuF6bu3GEonhEcjXAIAmRwhVx yuU45bDSlh1b42TmqXy04UpdZiPOXNIWVq1tyURkX7xMML5kdEY4VMfOv+Ezm+8pFotJ SIug== 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 s136-v6si10131063pfs.255.2018.08.27.00.27.38; Mon, 27 Aug 2018 00:27: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 S1727120AbeH0LLu convert rfc822-to-8bit (ORCPT + 99 others); Mon, 27 Aug 2018 07:11:50 -0400 Received: from mail.bootlin.com ([62.4.15.54]:58368 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726882AbeH0LLu (ORCPT ); Mon, 27 Aug 2018 07:11:50 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 7BCC7207B1; Mon, 27 Aug 2018 09:26:24 +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 xps13 (AAubervilliers-681-1-53-19.w90-88.abo.wanadoo.fr [90.88.170.19]) by mail.bootlin.com (Postfix) with ESMTPSA id 2B2F920787; Mon, 27 Aug 2018 09:26:14 +0200 (CEST) Date: Mon, 27 Aug 2018 09:26:12 +0200 From: Miquel Raynal To: Masahiro Yamada Cc: linux-mtd@lists.infradead.org, Boris Brezillon , linux-kernel@vger.kernel.org, Marek Vasut , Brian Norris , Richard Weinberger , David Woodhouse Subject: Re: [PATCH v2] mtd: rawnand: denali: do not pass zero maxchips to nand_scan() Message-ID: <20180827092612.38e8fc64@xps13> In-Reply-To: <1535353301-1727-1-git-send-email-yamada.masahiro@socionext.com> References: <1535353301-1727-1-git-send-email-yamada.masahiro@socionext.com> Organization: Bootlin X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Masahiro, Masahiro Yamada wrote on Mon, 27 Aug 2018 16:01:41 +0900: > 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 > --- > > 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; > Acked-by: Miquel Raynal Boris, This is for you :) Thanks, Miquèl