Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5585998imm; Mon, 27 Aug 2018 00:05:13 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbD7EwCVMS1FGRvbzLE6jo1psrEEM9ITw2mwYZM5eAw+SHJlMeosUPRdj6gJSinxqSrmvhg X-Received: by 2002:a17:902:7c8e:: with SMTP id y14-v6mr12004226pll.259.1535353513147; Mon, 27 Aug 2018 00:05:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535353513; cv=none; d=google.com; s=arc-20160816; b=YiXgwmU0Q/uLmO04AN9H0Y5MYhF9HyI8UFJBuKdUriHoraESz7carL6ZcoTfqB+6PS ub5ozgFIyLLxsykeWtRGQApl2QUEe32dlpscmMnfZNByLa6CDrWQh74VqbX5Immj3gbH 43eCOU3yXpMKJe/IBnkpVUzRuPHd3mFaAKNOGve6pqaftxEOLOLAZPpGvSyaOR/wXfOY JjvJHYJWVBJgKBI7DubbbdlU+a/ErIAmpf7IVKtwyK3szTMGhXnYpFn/oOgsJfe+eXWt 6wpWsYpUSdka/TmNg9CGyE2wrR3AYKjP+HhvT4vmoHzfclw1T69xD1fHzqQ8eAyGRY4V H+8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter:arc-authentication-results; bh=CsXgelmvnyMTmumHsOs/Hy678CwuZXeCIRKotVgV6pA=; b=aYOcwbrD64AHKlvPCvJX1LL0IzEOsvuQW6F1JAAFTzFPu1VMP+u0ivof/GsXfMJpXz XAuSNyI6DmumJpyPcpDrWNMB0+RGPr/YDjpHpDH8p7I6YpGLG7lB8l+oSQkGaUY0X4q0 Ehc52jF2t+QzZjcQ/XlCLJ7eYm+Ofa7YCxPIgKv9yjoIfPDzu+WuR7Bwf4MZ41rkh2uM pzKunfJm5Z11bBRVWlUzSuMrO9WVkyI4bwgWhBkVd+0OCTHoG+GeBz0l7PQdIvFTtLI0 TH7EAj0qbFQowbiAhD597LJGPrCNtng+AChGuPk5Ms96/qR/o4F2keAEgvLKWsKXlbWh nWkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=f0LbQX0b; 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 n72-v6si15112838pfk.14.2018.08.27.00.04.57; Mon, 27 Aug 2018 00:05:13 -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; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=f0LbQX0b; 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 S1727136AbeH0KtD (ORCPT + 99 others); Mon, 27 Aug 2018 06:49:03 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:39533 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726875AbeH0KtC (ORCPT ); Mon, 27 Aug 2018 06:49:02 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-07.nifty.com with ESMTP id w7R71vKg007630; Mon, 27 Aug 2018 16:01:58 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w7R71vKg007630 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1535353318; bh=CsXgelmvnyMTmumHsOs/Hy678CwuZXeCIRKotVgV6pA=; h=From:To:Cc:Subject:Date:From; b=f0LbQX0biuVPrKHauIbQYVZ8jCvwiAQxReotI1JNN+2QpY5H1soU0p0mF77THJDu1 mj2/idwqluwZJ4HXp7UadlJTFez8HCuWV1aY9qNEXMTXdcGKb9GIoszQyjOzEIESvm bc1DYeFRVjl9NrRbLMov525lq3olGDlBOpKINHtroPq7JRM18vJe/jLWBsM5jgf8xZ +3aVeyCIDLmGeb2paUUs+GnQ+zPB5jOeCLiXyUE4uzD2KaAp1T0h0GQw6Y6Sfi2BQP X2EPK/s8meDZ0zGVeLpa0/fMXe34oFyeReflMpT4dgqm2bi0G4H2bZZ1ndfLzwE+45 lwDVOEedpUznQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-mtd@lists.infradead.org, Boris Brezillon , Miquel Raynal Cc: Masahiro Yamada , linux-kernel@vger.kernel.org, Marek Vasut , Brian Norris , Richard Weinberger , David Woodhouse Subject: [PATCH v2] mtd: rawnand: denali: do not pass zero maxchips to nand_scan() Date: Mon, 27 Aug 2018 16:01:41 +0900 Message-Id: <1535353301-1727-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.7.4