Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6210871imu; Mon, 21 Jan 2019 05:10:23 -0800 (PST) X-Google-Smtp-Source: ALg8bN4jmoIJyAh4HGh+KyjWIaKmFWzTr4OVjGEJvkmhFW8b8VV4LrlLcOomz80eUIr4McG6v9It X-Received: by 2002:a62:5793:: with SMTP id i19mr29854252pfj.49.1548076223254; Mon, 21 Jan 2019 05:10:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548076223; cv=none; d=google.com; s=arc-20160816; b=fuIgOLRWRHFzsxwGZg30b4MifVnbabHnF7rI3GcB6OF9kAVJP+5QTKy2posH/Ip24J lAGRrOQdr6dy9teWAb6m55LiPyropxhjNEp2ZeR56+mOYurdw2Bpnob6EmuGpQEFk/nk hGJWzVjaODn9SOGYcggTo6qst2J/THPDZlt0aD4W8UGErUCXt5VJDAktKFJAcj7+i0Z0 2cKGAAD2aD1gwHaZ3u5hQ+UQJMMdTeB4huX217V38w7cvAqEhzmv+jMVUzIiLl3Mlb5+ GwHebT4OA6r8CIaCWPBg7CxDQGc4+93H7qWuRuRmdtaXMuT7whNUrBIODaFB6q/9q8ws u1oA== 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; bh=oDS6K478k8S9TuIPdGCS0e12SPNRa7vs+WnpfNLNJ18=; b=G8/8jnvBfh54YnWNNuk9VDBjOyXmf39sJqnVYItfb1jxLOEE/zRUay1ldLIgn5dbSM Fh0aWOocJT0C4LDyUIIRyJgL3kyQgL5yvP7XCIpjuS8v0EK0iK0fJTlfLttnsSCfm+NP dHwrem7Er5ELC7uO55BtdmJ4EfQwPLdx7bqGJ0UsGZMnxTBJKBoq7rtX5qLPW3Nbr/+M rD+sjXYrUNRurDS1rlv9lYb2E5yP9jKCB0o9F+mL7i6Ug9ia1ZrFdVKuUPkgco5ZX7dH jMEYQZZ6fcxhH8XRNZr0YeM7UzrujxnVc2iAMCe2YYKjjNSt4MAJHGABD+kcKdEpu9r8 LTkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=wXCI3GF6; 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 v25si12495662pfj.139.2019.01.21.05.09.59; Mon, 21 Jan 2019 05:10:23 -0800 (PST) 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=wXCI3GF6; 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 S1728789AbfAUNHG (ORCPT + 99 others); Mon, 21 Jan 2019 08:07:06 -0500 Received: from conuserg-12.nifty.com ([210.131.2.79]:47345 "EHLO conuserg-12.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727449AbfAUNHF (ORCPT ); Mon, 21 Jan 2019 08:07:05 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-12.nifty.com with ESMTP id x0LD5exQ027454; Mon, 21 Jan 2019 22:05:40 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com x0LD5exQ027454 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1548075941; bh=oDS6K478k8S9TuIPdGCS0e12SPNRa7vs+WnpfNLNJ18=; h=From:To:Cc:Subject:Date:From; b=wXCI3GF6HAanitgdyzFucM1iCB+qgXsVG5mMXCrqtHocFPjGYFN91iGSNnyR5Goph FuipL0/OXmon/BTB5PeReDS9a/F1UN6xu8cLrBaUoGA6YIr+CTk4JLXwtrlVyU39z4 rQQD8Ml/CRJkECI4rgQ1tJcNuizXUYEYixqDNEmyzS6HvameSpqzklX2TN8k7JI2qP o6yLJwbwVga/1N+KoJTTCjObWjlpnKbnS1QW8o/m/Sp7SatvVnsjURI9+5WlvG/NKd QKTLUJ2hjMCWTP2wCVc/QAZbeldjWrbqXDR813seBx8bARje5IPUHU/PZ8oq8TkcOd Qac5lPE9EP05g== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-mtd@lists.infradead.org, Boris Brezillon , Miquel Raynal Cc: Masahiro Yamada , Brian Norris , linux-kernel@vger.kernel.org, Marek Vasut , Richard Weinberger , David Woodhouse , Boris Brezillon Subject: [PATCH] mtd: rawnand: check return code of nand_reset() and nand_readid_op() Date: Mon, 21 Jan 2019 22:05:34 +0900 Message-Id: <1548075934-19963-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 nand_scan_ident() iterates over maxchips to find as many homogeneous chips as possible. Currently, this loop bails out only when manufacturer or device ID unmatches. The reason of unmatch is most likely no chip is connected to that chip select. In this case, nand_reset() has already failed, and the following nand_readid_op() is pointless. Before ->exec_op hook was introduced, drivers had no way to tell the failure of NAND_CMD_RESET to the framework because the legacy ->cmdfunc() has void return type. Now drivers implementing ->exec_op hook can return the error code. You can save nand_readid_op() by checking the return value of nand_reset(). The return value of nand_readid_op() should be checked as well. If it fails, probably id[0] and id[1] are undefined values. Just for consistency, it should be sensible to check the return code in nand_do_write_oob() as well. Signed-off-by: Masahiro Yamada --- drivers/mtd/nand/raw/nand_base.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 7ea3f10..3407523 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -457,7 +457,7 @@ static int nand_do_write_oob(struct nand_chip *chip, loff_t to, struct mtd_oob_ops *ops) { struct mtd_info *mtd = nand_to_mtd(chip); - int chipnr, page, status, len; + int chipnr, page, status, len, ret; pr_debug("%s: to = 0x%08x, len = %i\n", __func__, (unsigned int)to, (int)ops->ooblen); @@ -479,7 +479,9 @@ static int nand_do_write_oob(struct nand_chip *chip, loff_t to, * if we don't do this. I have no clue why, but I seem to have 'fixed' * it in the doc2000 driver in August 1999. dwmw2. */ - nand_reset(chip, chipnr); + ret = nand_reset(chip, chipnr); + if (ret) + return ret; nand_select_target(chip, chipnr); @@ -5037,11 +5039,15 @@ static int nand_scan_ident(struct nand_chip *chip, unsigned int maxchips, u8 id[2]; /* See comment in nand_get_flash_type for reset */ - nand_reset(chip, i); + ret = nand_reset(chip, i); + if (ret) + break; nand_select_target(chip, i); /* Send the command for reading device ID */ - nand_readid_op(chip, 0, id, sizeof(id)); + ret = nand_readid_op(chip, 0, id, sizeof(id)); + if (ret) + break; /* Read manufacturer and device IDs */ if (nand_maf_id != id[0] || nand_dev_id != id[1]) { nand_deselect_target(chip); -- 2.7.4