Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6218581imu; Mon, 21 Jan 2019 05:17:33 -0800 (PST) X-Google-Smtp-Source: ALg8bN4MqgmWeiKBOMURR3s1qtqzl96s6IGtQ4T/BPQw4pnOEysLa2p/DZxCYYh6+5dPisTIzcE3 X-Received: by 2002:a63:4948:: with SMTP id y8mr28127345pgk.32.1548076653026; Mon, 21 Jan 2019 05:17:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548076652; cv=none; d=google.com; s=arc-20160816; b=vr1+YSI9r7jeC41cdk68IKMJcdO99FLRmmOOpzcr+0qes/YGzExfliMwm30MhYSt2S nU7X3OUhnQ+SgKixWaV5h0mDGDcXXa+caqTbTD8VrdcU17SYLNKUKbzWLiQG7YgOs3Dl l0p8MuT6R8GPFMOoAOOkNiGFZzbBRKoxzTxZSkNbM3kXHA4YvYXpWaext/NYF8Yj5cpu KDhQO8fwdTA3KlpwprpqR75ANC42euybemZ2UINM4En6kBQLlVMTtAdqWgYg+KFANjKV y3T+qJqBdSAHgXHXbUiswcotQrObVC17QLUpx1QotVxcAixRI1Lwfb/1KLSyePPAa+F/ Zepw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=S5J1JyxpH1oyKONWhyu9gh+lq4zxnGadafub/ImQcAc=; b=eLPHhY0mKJCNnuIOjG229derByAwwz+ARNb/LhlAZKWlWTCYlQ6ZMCNPyJ1Tl+uEr4 9OYM+5RxvpV9GYZBqqEuY0zkq44nvqXr3qWXCVj9aCicw8YRUc8kbFlM1+/1dxdFzDIm 5KaXrNSzyDt2eZ2+kLIxuthtmMalr/UeX6E5zU/LdizTZiKVUAo93CweCUPTy2WK4L+j sQvtFfiDtmYMz+AjsfvoS2Vll9yN/6uY0rCNhavpwf52mgxDd5JFhB1xxklnZMEae8Qf pTKzr5VgSEiqwaaSUNVEPkBq5ldd0BZYs7KbQXlmbLID5VQ6q3ZQyAHKnxhNmxxdOpwi PvcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PI707eWF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n4si12828382pgm.487.2019.01.21.05.17.09; Mon, 21 Jan 2019 05:17:32 -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=@kernel.org header.s=default header.b=PI707eWF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728901AbfAUNOP (ORCPT + 99 others); Mon, 21 Jan 2019 08:14:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:40798 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725970AbfAUNOP (ORCPT ); Mon, 21 Jan 2019 08:14:15 -0500 Received: from bbrezillon (91-160-177-164.subs.proxad.net [91.160.177.164]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6F1242084C; Mon, 21 Jan 2019 13:14:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548076454; bh=Lq9h2aOh3VJJxFH+SuBIWbWBthqGszQjSGW4+XxgGrI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=PI707eWF0YqzjUfjqxtvgc8ac3E/bk8p2vM7gf9rK3vNQELq3dqH8jXCS3RS+89sh cslE30cwgCnxeakD34kyL6e4D9PCjeANVnwz6FJd3r3kMdmWjCiwlCpvU2t4+HqbLt DzUE1Hyqph1tZzEDbrThY2Mthrxhx1pXv+hUyNu4= Date: Mon, 21 Jan 2019 14:14:03 +0100 From: Boris Brezillon To: Masahiro Yamada Cc: linux-mtd@lists.infradead.org, Boris Brezillon , Miquel Raynal , Marek Vasut , Richard Weinberger , linux-kernel@vger.kernel.org, Brian Norris , David Woodhouse Subject: Re: [PATCH] mtd: rawnand: check return code of nand_reset() and nand_readid_op() Message-ID: <20190121141403.20f6107b@bbrezillon> In-Reply-To: <1548075934-19963-1-git-send-email-yamada.masahiro@socionext.com> References: <1548075934-19963-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 21 Jan 2019 22:05:34 +0900 Masahiro Yamada wrote: > 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. While I agree with the following diff, I'd also like to point out that nand_scan() callers should know how many controller CS lines are connected to the chip (board file or DT description). The check we do in nand_scan_ident() should only be here to clamp this value if the board desc is wrong (maybe we should even fail in that case instead of silently fixing things). > > 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 Reviewed-by: Boris Brezillon > --- > > 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);