From patchwork Mon Aug 27 07:01:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 145160 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3861532ljw; Mon, 27 Aug 2018 00:03:26 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYqlBOlYxELfcX9/TpcNY/Qa2YqogivB8pfkqdmDSk3CWiNVmAlTCvVtPnomfHAVtmYZTWN X-Received: by 2002:a17:902:b7c3:: with SMTP id v3-v6mr11880938plz.238.1535353406419; Mon, 27 Aug 2018 00:03:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535353406; cv=none; d=google.com; s=arc-20160816; b=NsGvJT7LnzcnaNqAYUAmQ5QIrMdb/uo/J9nGM+BdKmc+fhA62jPTBcY/fHtCoiKkEY tQ2NCWDlMZv4GlRXbuEagbH5BaAEDOJBOKeZsLueVKbSCjjLtoX6YZtwDJxbsoZcb/+B PTAvkaLkFNIExSozYbgYSgclRA5sILZnmEDBhYtNxXzTsHYYm8n/lhGYIBqNQIeCv1Fp IqTORVzkFVEQB0ry4XOjVS6FBsKdaW3LK72ztqfbU6I/bJZZhz+8VWXz+HFx4anxfpKU AEt/oNk6OFXLt3weok8LBWf+L29/I9io7lx3N20Ve0YrH5WQNZc/6mO2qWRlkiruusiV UENA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:message-id:date:subject:to:from:dkim-signature :dkim-filter:dkim-signature:arc-authentication-results; bh=V3WiGEQsrsdPeDhwM07v4zPTnNzgiWE6k70qia+yRow=; b=OvmkjZ7csCOV24/XvR6pJS2tQhx6MUc693k2l6dPkCcRxVj0KZnGvccaJREGZka1o/ yJGLUMYC2M+4wzRHkX0BKmauf4Fi5k+wOtXbckn4i2pHVDcjtCgqnqS8yTp9CWTdjmgU 2pHHQvRHogLYdqruorqucfS4Lq+vHD6ZedGveWo1hFpPLybFyfsyBGQx17PBgFD5xVrR OTUHHZkLkIipFlh0RYw2Dgt93fZgtBb5K2qMjkNr3vXYo0qK3tsNVrRAYkr8ZIfkI4ya odAn9CEkw9d3UCv78R9Q14MiYcgJ/qyqSi+jEIq96+WDEaAqf31HmqTHIR9y/rx6sV3S KWkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=uRFNDsSf; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=f0LbQX0b; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org" Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id b8-v6si12132384plx.110.2018.08.27.00.03.26 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Aug 2018 00:03:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=uRFNDsSf; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=f0LbQX0b; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=V3WiGEQsrsdPeDhwM07v4zPTnNzgiWE6k70qia+yRow=; b=uRF NDsSfjAdK1PPJ51hlZzaRvAzdt37EPEjuH/x+gspreg+458jhX0NwmVqmyDIJSYou4kHqOuk9btDY D2C7/klCTOo7o4+aJ1T/spN+TGgXNcFvB10waAUX60u9PRuclfpCjNR2mhExO92q37YKu3CsPO5BI rkgDpx1q2HzGHklOczV8j1WsXMjcUSPu/HBB2tPuhKMuVW0fV7Bt8MYwiyUgycFOrPxAbKxscSLPT Ro6evCFWbjaFzy+OzDddYWC6axafFGbCud2tEv/DPbFSEr/uzyYODZy856NiJ8oxHasHA+YfFvGk3 yigEqhJiMYrBOZCAZAbLTzACG+pheVQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fuBYI-0008M9-GT; Mon, 27 Aug 2018 07:03:06 +0000 Received: from conuserg-07.nifty.com ([210.131.2.74]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fuBXu-0007uV-Hl for linux-mtd@lists.infradead.org; Mon, 27 Aug 2018 07:02:44 +0000 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180827_000242_951085_30352B48 X-CRM114-Status: GOOD ( 12.90 ) X-Spam-Score: 1.0 (+) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (1.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [210.131.2.74 listed in list.dnswl.org] 1.0 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marek Vasut , Richard Weinberger , linux-kernel@vger.kernel.org, Masahiro Yamada , Brian Norris , David Woodhouse MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.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(+) -- 2.7.4 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ 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;