Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2971312imm; Fri, 24 Aug 2018 08:23:04 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYhr/DUDYW7FECkDYEjW+B3VzHpRhp8kuwcSqkCA+Dqkx0qdbD4R9XfwhusEWxst7fo1fBz X-Received: by 2002:a62:6a01:: with SMTP id f1-v6mr2482412pfc.156.1535124184214; Fri, 24 Aug 2018 08:23:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535124184; cv=none; d=google.com; s=arc-20160816; b=VbYhVYKBmqEqgYThAwrqc4FAtKY4NdTyeQrHOaA1kf4KpcYl1X0NM7cAGlH61wZ/pQ snyYl9ZAiBvCugUeLInAkOgMXK+/4bSmfkn910/ItZn0hbMKUk8qBY4roa2FvzM3t7OR 6y27Zxy46PK/LEC6dSkt9U9LdsEvvyS6E5XHjxaolDybwF33KVz3pjdvik19YZEXkFNm EETUfuTjipljSHXcmHQZ0ZqosOdbSwT5+lUKhnmviXIAVk+CRJ4N3ufX0l58YfvOPN/K ysIrBd6+xCGCv31aDmH8cR7krNZpyxloRV9UN77+XEV2lJPbY1ZZUxdWOOVenZvy6ZZ9 zDYg== 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 :arc-authentication-results; bh=UFKUu9K/n55famlFU8fPdlMyeaMAz3xjpG94bDK5pGk=; b=WZZpBnXxF6whasUy3IFIq3sJnAM5viGOt9QN7HAWMWKCg/pWS0OOqeSNNyMlrHSwVe RIisBs8BvbmwHmw7V/b2cAK3OafXANLXKHu2EAxPR4Db6F9HqR1837cb9PrHNGHt+X29 jS7gVMcBNPADB+CwUzdgwFr+VzUtOtTINSClNr0+HD9bsg7ywL+uTYumTfvXE91/4Z/6 afqjD6iqopgdu7OKngEkzLWlMqUi+fA6ZUebY11bUgo7HZ5Zhj0+p8EspXdcHzGfPYHo PJwBQlXitXI1TWy6kU061u7KuOz8oErOaPsFFWgUBHXK6chgd/uWt6QbqBK/ksrlqMlS SP+w== 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 d12-v6si6743217pla.421.2018.08.24.08.22.24; Fri, 24 Aug 2018 08:23:04 -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 S1726677AbeHXSye (ORCPT + 99 others); Fri, 24 Aug 2018 14:54:34 -0400 Received: from mail.bootlin.com ([62.4.15.54]:56150 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726374AbeHXSye (ORCPT ); Fri, 24 Aug 2018 14:54:34 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 4C2A522A2A; Fri, 24 Aug 2018 17:19:28 +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-53-19.w90-88.abo.wanadoo.fr [90.88.170.19]) by mail.bootlin.com (Postfix) with ESMTPSA id F22A420719; Fri, 24 Aug 2018 17:19:27 +0200 (CEST) Date: Fri, 24 Aug 2018 17:19:26 +0200 From: Boris Brezillon To: Masahiro Yamada Cc: linux-mtd , Miquel Raynal , Linux Kernel Mailing List , Marek Vasut , Brian Norris , Richard Weinberger , David Woodhouse Subject: Re: [PATCH] mtd: rawnand: denali: do not pass zero maxchips to nand_scan() Message-ID: <20180824171926.2e3af016@bbrezillon> In-Reply-To: References: <1534839799-14112-1-git-send-email-yamada.masahiro@socionext.com> <20180824145519.330133a4@bbrezillon> 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 Sat, 25 Aug 2018 00:04:43 +0900 Masahiro Yamada wrote: > Hi Boris, > > 2018-08-24 21:55 GMT+09:00 Boris Brezillon : > > Hi Masahiro, > > > > On Tue, 21 Aug 2018 17:23:19 +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 in fact > >> 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, i.e. nand_set_defaults() is skipped. Therefore, the > >> driver must have 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, it is zero. > >> > >> The reason of this trick was, as commit f486287d2372 ("mtd: nand: > >> denali: fix bank reset function to detect the number of chips") > >> explained, nand_scan_ident() issued Set Features (0xEF) command > >> to all CS lines, some of which may not be connected with a chip. > >> Then, the driver would wait until R/B# response, which never happens. > >> > >> This problem was solved by commit 107b7d6a7ad4 ("mtd: rawnand: avoid > >> setting again the timings to mode 0 after a reset"). In the current > >> code, nand_setup_data_interface() is called from nand_scan_tail(), > >> which is after the chip detection is done. > >> > >> Remove the code that is causing NULL pointer dereference. Now, the > >> maxchips passed to nand_scan() is the maximum number of chip selects > >> supported by the IP (typically 4 or 8). Leave all the chip detection > >> process to nand_scan_ident(). > >> > >> Signed-off-by: Masahiro Yamada > >> --- > >> > >> drivers/mtd/nand/raw/denali.c | 1 - > >> 1 file changed, 1 deletion(-) > >> > >> diff --git a/drivers/mtd/nand/raw/denali.c b/drivers/mtd/nand/raw/denali.c > >> index ca18612..3e4b8e1 100644 > >> --- a/drivers/mtd/nand/raw/denali.c > >> +++ b/drivers/mtd/nand/raw/denali.c > >> @@ -1086,7 +1086,6 @@ static void denali_reset_banks(struct denali_nand_info *denali) > >> } > >> > >> dev_dbg(denali->dev, "%d chips connected\n", i); > >> - denali->max_banks = i; > > > > Shouldn't we instead avoid calling nand_scan() when > > denali->max_banks=0? I mean, what's the point of calling this function > > if you know for sure it will fail. > > > Right. If no chip is found, it should error out with -ENODEV or something. > > > > > Last question: do we still need this denali_reset_banks()? If it's only > > about resetting the chip to detect how many are actually present, > > that's already done by nand_scan(). > > I thought this too. > > Please give me time to answer this question. > I need to check the datasheet and test on my boards. > > If I can remove denali_reset_banks() entirely, > it would be the best. I'd like the fix to be as simple as possible, so that I can queue it for -rc2. Please consider the solution where nand_scan() is skipped when denali->max_banks=0 first. We can then decide to remove denali_reset_banks() if that's appropriate. Thanks, Boris