Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4826494imm; Tue, 21 Aug 2018 01:26:46 -0700 (PDT) X-Google-Smtp-Source: AA+uWPz2Al6OMn/FPF5huwTWwZSxCXd9lNC9tda/sM/lEJxrG5OzbjNrUruwP8KBXwxPkFx4aXsU X-Received: by 2002:a17:902:2ac3:: with SMTP id j61-v6mr48312118plb.172.1534840006421; Tue, 21 Aug 2018 01:26:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534840006; cv=none; d=google.com; s=arc-20160816; b=bCk2T+o9LtIGKe08rAlVufZGjNdWawjqGuElK7YWoF8FwckRWtjth5uf3S/YPFn7Up 98mnP/QaAdzF4cIihXlamkg6A7Oygr+Aw0rtBR+8USSGh60Pu0oW9onHWM7lwKEJhJXe XHx648b5BTFOrb3/TjmWeQ0IB0J4wKFeGe6Lnqvva/Z/uvCJPhYh/4N1lRMz9Nn0IQWu bL6kFflCKlaytMaOyccQG8moxAfetaumDJ7Ty1VSuYpkPcrOSHKwlU/OHjuWH5a2WEkJ nwefAsG9fyoh0VQoeENzf9Y5QeEZPbYp/h7wKfJUZsWV33xo5V4k8lzNqmTAiUJ/fiqr 2Mlg== 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=cHlV1fzTPy2AxA0OS8cxvziMcEGIywYFVaQHfV5ATVQ=; b=EEDqbps3KFj+XXDUKbT0c9xTykBNkBGYHBnDyNKeSET1iyaDJ7dQx+KYR25p+D9FNt kk6GGVQzXb4ZCXrkJ/Dd6XVwNizMlVN6cbPvBDkmmG0EAHDdk4XYNFBJrPkXDtqYCy89 mxiy0VNStBpTmkulvvy/rvAXUb8SO0a6rRjldw277ze2iK3ZU639t9rZwMPAI0PPsrN8 RUDT5GdOJHHTfYHHnj0OUdlwrQQmTtIw27bo/GPfIsRP/sNW92Betd99rDwMquOimY6L 7+AMF/aI9NiyxcRPVCKs4NytuXjruFad4waqYLNENotrTDrxhK/bvjT7y1KmcXCTbV+Q ahjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=lPWCW4yo; 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 z12-v6si10967688pgu.692.2018.08.21.01.26.30; Tue, 21 Aug 2018 01:26:46 -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=lPWCW4yo; 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 S1726719AbeHULoE (ORCPT + 99 others); Tue, 21 Aug 2018 07:44:04 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:43589 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726315AbeHULoE (ORCPT ); Tue, 21 Aug 2018 07:44:04 -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 w7L8NMfY009148; Tue, 21 Aug 2018 17:23:22 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w7L8NMfY009148 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1534839803; bh=cHlV1fzTPy2AxA0OS8cxvziMcEGIywYFVaQHfV5ATVQ=; h=From:To:Cc:Subject:Date:From; b=lPWCW4yoiI7ZOojB5oQd7HPFPlYg0W1pcYGa+NrXQ03MoNNXT6+HorumyrSQHHsca jGe01k4xzrcj8CiNv6obsSgSMvQDNHVJJW5mphvVoI3Tv1YK3FgGKtR7fFvgNSj6x7 VVcm8YNSJWXISZqzXatoOa7evvWWGGl5g/+HCR96QwvKAT96YBzfEdhl6XFvkzH8GX TNjhhnLul9OzlQF6GLnXWdL+aHS3sVIOijW2kv6p6iiE/CVAoZXxdIGiJ0Hz02YRvZ FGzPzZI61PHC1avf3Np7dxGZfHkT58+U8FcjNMNIVU/tcAO2v174ctXZXQcGxpzKZN vDr2IxQnsNTjg== 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] mtd: rawnand: denali: do not pass zero maxchips to nand_scan() Date: Tue, 21 Aug 2018 17:23:19 +0900 Message-Id: <1534839799-14112-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 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; } static void denali_hw_init(struct denali_nand_info *denali) -- 2.7.4