From patchwork Mon Jan 21 13:05:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 156198 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6359025jaa; Mon, 21 Jan 2019 05:06:28 -0800 (PST) X-Google-Smtp-Source: ALg8bN7l0G6jX8Yudy1myGWAyWKh5pe/97LI9AnI3hQ/wuw/7PBX+q+uI5oMMZvOxwrEBSlhIYpj X-Received: by 2002:a17:902:a5c3:: with SMTP id t3mr29678303plq.117.1548075988236; Mon, 21 Jan 2019 05:06:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548075988; cv=none; d=google.com; s=arc-20160816; b=AGnIhpRRwL0hHf769E2Fc8jmbflAhV4rQ3zjjqFLGOcAK7Xz+LOFO8zkrzTgQIypQE R8sqiOabUWCYxb1ourALVSKyLZdZqqNXFcEyEZbzYLCjszeeXqJNAK7KD6ke6Da64jcq N/zxuPTg9k5b9lU00ov99lFOErXeP3fO9fgCao2yDcwu0L9jiDwStSqgspMJb0dJ9Sej osq0v3ZS9HGTIC+xE9ccK1gN2c+f4EdVCCjisVTacIGR6y4F4v99P2w6+Pm1gHydseCZ JxG8ITB4LkToBfluXCwBgmZ4HGRYr9ka8kJJzOalN+g5cUEIktdJaVOu0sV0NrZkkDJS uYRA== 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; bh=8vKSWJJxdAubic2Wvnbzgv4+cwXt89KnOAHhmoANWt8=; b=qSvEpMRwxa0cD3xqPOeswqDNzHJBlVUJOhu2r4S2+ZuuuUR+eel/ERqgIhmNIzs12n 9rB+qEPepLjBfHVoXUfU77PrbLUFG3IgfDN5rkKZqXHawus4gLd7O+0PIxeR2ruc1USJ cxdjY6SgTTO4OXreC/gdFbpZYXIdVg1++WNz1szAIDDJ4EhZyZaA9AQql5K43n5x7iqZ 76pawLE+pbyXN7Fl46pJ0iIr2eUwXtbKAbYaXDfmGafwVyCitrAFo91pAZp69gIhiUuy DvqIzuCtzqg05gB5IrozKehfdBfO4CbozxIhoziPsHyIxfd4EqOePT8xgJ5S80LqfpTW 5LNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=u8CWEeM0; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=wXCI3GF6; 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 k72si12041760pge.310.2019.01.21.05.06.28 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Jan 2019 05:06:28 -0800 (PST) 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=u8CWEeM0; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=wXCI3GF6; 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=8vKSWJJxdAubic2Wvnbzgv4+cwXt89KnOAHhmoANWt8=; b=u8C WEeM0b5b5uEwXDbqW5lK50Kuhtf6cyX7M5BfJgUDYPGOcJh3UAVoQmH0VQK63BFTqoILPr0FR12uu MHpusKlOV87txgG9UX8hk5FL5sea2Cus2fJAFRGBkA2CL9l6FWz9PUHP24yfkLSsjmsz4tNlep2Mq TF3JjMj02hzxJ7fasVSXPcADCI++rBW1Z4TLjVqcF+Q8/laNuvGo3sI+N5JK5lruXsnXYmL1T2Gxa aTi54dTQ4L2SWJKPghKUN8tTMD4Qlg7Ydgl7F4yO8Qg8hColAfZkwGbc5vZbmbbOLtDzlJq/o5bQ8 AkPL8+febA0lQqI7lXU/tCDR6oXPeSw==; 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 1glZHL-0007q9-Vb; Mon, 21 Jan 2019 13:06:15 +0000 Received: from conuserg-12.nifty.com ([210.131.2.79]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1glZHI-0007po-MZ for linux-mtd@lists.infradead.org; Mon, 21 Jan 2019 13:06:14 +0000 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190121_050613_086311_56D2F06E X-CRM114-Status: GOOD ( 14.18 ) X-Spam-Score: 1.0 (+) X-Spam-Report: SpamAssassin version 3.4.2 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.79 listed in list.dnswl.org] 1.0 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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 , Boris Brezillon , 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 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(-) -- 2.7.4 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ 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);