Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1677618rdh; Mon, 25 Sep 2023 23:16:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHSAaf27/v3KbX8J63ZecCxJbCWJqfvFdiqPc44km7EyJXK0nNehPaOQ1UBmH8OTgddV8xd X-Received: by 2002:a81:a241:0:b0:59c:b61:898b with SMTP id z1-20020a81a241000000b0059c0b61898bmr7622294ywg.52.1695708988640; Mon, 25 Sep 2023 23:16:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695708988; cv=none; d=google.com; s=arc-20160816; b=LYxbpPnXdcnAmwYu38aJoS7PTWNB8dzvgYblqKGCEOVn6DyUSnxcum0AWQmCIlS13x sicxPs+ECxQ7aa9nclFdQ/Yhq5Bhugxv4yOY1AsHd7kmwW1mtjschS11qlnLb+7iOpD7 UCDTDnh2g2d/VZC16mQ2b1mt5EMBFp4FNp8ykeeYABNf2BPl7HOGg0pjYq4nlBDvlhGA z9ciLjKQ1g7OPuRVsYhimTJSGuYVSMBvrBVZH9Lwd4bGLkSgFqkYWUmK5uYpAPSidXR9 BkpKDi/ABWC9DyOBGtOPfCbGEvyuLlF3BrghG9cjQCJ07gIe8WKkOHpnGHxJvtUHxa/R 6vQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=INBNCslwxKAO9zA0oLb6M4ySYAmug40tgKE1H/MmE0A=; fh=KE3YvDUPcLfTObDP0YixwwOCNX8t73QnE/qSy6EQqWY=; b=mOGNDnjN27Mhq2xlwC9rD50eCV39aw0PDpqBKqL71TaY4zjOQ6GjlX2u2OzTb7U2Ua mUCmJCAneYj0eShupoSC1urBoCGBlOpO9accqJuq+ADmfeF4abYIZH+OogE2nYy2YTLL Z73ZLOdCSPgm/R70CHpRFDV6bfNau9y1c9NrxgNvfDLhh1yePjyyjE10AjD7MvYE3Xab rc6UTqAIODS8mlZiIFjKyOHwI+VvZ9vqxtUjHG/FS4Bsxmtj/RAOVg1qD56Ny56KR5Ie CLhLcxmJ+9At+6/v80HEhmhL4owJDri1eGHmtL8XD62IUQPd/ldrK+cufsOttzIoHDxq Kr6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="TYej/Qhs"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id my5-20020a17090b4c8500b00274d6373fe1si15767366pjb.120.2023.09.25.23.16.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:16:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="TYej/Qhs"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id A5DF881142DD; Mon, 25 Sep 2023 01:50:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233065AbjIYIty (ORCPT + 99 others); Mon, 25 Sep 2023 04:49:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232979AbjIYItv (ORCPT ); Mon, 25 Sep 2023 04:49:51 -0400 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E14C1D3 for ; Mon, 25 Sep 2023 01:49:43 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 19B2CFF803; Mon, 25 Sep 2023 08:49:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1695631782; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=INBNCslwxKAO9zA0oLb6M4ySYAmug40tgKE1H/MmE0A=; b=TYej/Qhs2tQt0X2X/1RpcZsO4PzpvkrHD6BxUtce/kqEyax4ZxRj1S/sEYcWjqB0CO7TOK HwaElyLLqzCZdL56EkdOOuZy6SXYGOEK7VBY9yirkxT/jTHZdITbC7qWW9+K1T9RHH3PMY JsKw3fQpnhmU+Xi8dCW88Y/WNNrhqDjfBoyZiz9uJtT04NQiy3CvxGZo3g9QC9utv3rz26 grC+poafNhzfdTSS1R2PAgHR3MPF/KLR++jSqhXpz+P9tjBLbQLmhAJZtg7fznHcedhviv yQzPzPnn6QubeEZoxgSR9rRNwUqgUaHQ5DkaCsZHYycaOk1f1VBRO/ouHIH81Q== Date: Mon, 25 Sep 2023 10:49:38 +0200 From: Miquel Raynal To: ZhaoLong Wang Cc: , , , , , , Subject: Re: [RFC] mtd: Fix error code loss in mtdchar_read() function. Message-ID: <20230925104938.3f7b4284@xps-13> In-Reply-To: <20230923005856.2538223-1-wangzhaolong1@huawei.com> References: <20230923005856.2538223-1-wangzhaolong1@huawei.com> Organization: Bootlin X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: miquel.raynal@bootlin.com X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:50:04 -0700 (PDT) Hello, Richard, your advice is welcome here. wangzhaolong1@huawei.com wrote on Sat, 23 Sep 2023 08:58:56 +0800: > In the first while loop, if the mtd_read() function returns -EBADMSG s/the// s/function// , > and 'retlen' returns 0, the loop break and the function returns value s/and// remains to 0. The loop breaks and the function returns 'total_retlen' which is 0 instead of the error code. > 'total_retlen' is 0, not the error code. Actually after looking at the code, I have no strong opinion regarding whether we should return 0 or an error code in this case.=20 There is this comment right above, and I'm not sure it is still up to date because I believe many drivers just don't provide the data upon ECC error: /* Nand returns -EBADMSG on ECC errors, but it returns * the data. For our userspace tools it is important * to dump areas with ECC errors! * For kernel internal usage it also might return -EUCLEAN * to signal the caller that a bitflip has occurred and has * been corrected by the ECC algorithm. * Userspace software which accesses NAND this way * must be aware of the fact that it deals with NAND */ > This problem causes the user-space program to encounter EOF when it has > not finished reading the mtd partion, and this also violates the read > system call standard in POSIX. >=20 > Link: https://bugzilla.kernel.org/show_bug.cgi?id=3D217939 > Signed-off-by: ZhaoLong Wang > --- > drivers/mtd/mtdchar.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >=20 > diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c > index 8dc4f5c493fc..ba60dc6bef98 100644 > --- a/drivers/mtd/mtdchar.c > +++ b/drivers/mtd/mtdchar.c > @@ -211,7 +211,7 @@ static ssize_t mtdchar_read(struct file *file, char _= _user *buf, size_t count, > } > =20 > kfree(kbuf); > - return total_retlen; > + return total_retlen ? total_retlen : ret; This is kind of wrong, if ret is 0 then you return ret while you should return total_retlen. In practice it does not really matter, the result is the same, but it makes it harder to understand the code IMHO. > } /* mtdchar_read */ > =20 > static ssize_t mtdchar_write(struct file *file, const char __user *buf, = size_t count, Thanks, Miqu=C3=A8l