Skip to contentSkip to conversation

bcache: Fix an error code in bch_dump_read()

PATCH New Dan Carpenter 1 participant 1 message Aug 21, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bcache: Fix an error code in bch_dump_read()

The copy_to_user() function returns the number of bytes remaining to be copied, but the intention here was to return -EFAULT if the copy fails.

Fixes cafe56359144 ("bcache: A block layer cache")

---
Another option to fix this bug would be to return the number of bytes which were successfully copied. But probably -EFAULT is the right fix.

 drivers/md/bcache/debug.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/md/bcache/debug.c +2 -3
index 8b123be05254..336f43910383 100644
@@ -178,10 +178,9 @@ static ssize_t bch_dump_read(struct file *file, char __user *buf,
 	while (size) {
 		struct keybuf_key *w;
 		unsigned int bytes = min(i->bytes, size);
-		int err = copy_to_user(buf, i->buf, bytes);
 
-		if (err)
-			return err;
+		if (copy_to_user(buf, i->buf, bytes))
+			return -EFAULT;
 
 		ret	 += bytes;
 		buf	 += bytes;
Signature · 1 line
2.20.1