public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [RFC] mtd: Fix error code loss in mtdchar_read() function.
@ 2023-09-23  0:58 ZhaoLong Wang
  2023-09-25  8:49 ` Miquel Raynal
  2023-09-25 14:03 ` Richard Weinberger
  0 siblings, 2 replies; 11+ messages in thread
From: ZhaoLong Wang @ 2023-09-23  0:58 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr
  Cc: linux-mtd, linux-kernel, chengzhihao1, wangzhaolong1, yi.zhang,
	yangerkun

In the first while loop, if the mtd_read() function returns -EBADMSG
and 'retlen' returns 0, the loop break and the function returns value
'total_retlen' is 0, not the error code.

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.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=217939
Signed-off-by: ZhaoLong Wang <wangzhaolong1@huawei.com>
---
 drivers/mtd/mtdchar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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,
 	}
 
 	kfree(kbuf);
-	return total_retlen;
+	return total_retlen ? total_retlen : ret;
 } /* mtdchar_read */
 
 static ssize_t mtdchar_write(struct file *file, const char __user *buf, size_t count,
-- 
2.31.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-09-26  1:08 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-23  0:58 [RFC] mtd: Fix error code loss in mtdchar_read() function ZhaoLong Wang
2023-09-25  8:49 ` Miquel Raynal
2023-09-25  9:14   ` Richard Weinberger
2023-09-25  9:28     ` Miquel Raynal
2023-09-25  9:31       ` Richard Weinberger
2023-09-25 14:22   ` ZhaoLong Wang
2023-09-25 14:03 ` Richard Weinberger
2023-09-25 14:37   ` Miquel Raynal
2023-09-25 14:59     ` Richard Weinberger
2023-09-25 15:06       ` Miquel Raynal
2023-09-26  1:08         ` ZhaoLong Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox