summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-09-20 00:09:22 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-23 00:10:14 +0300
commitf7f6943a8c6dccbd085600bbb7bae4f6f6047dc4 (patch)
tree1ad07be7dbe50d411a45dfaab624a28a64a9c5fb /fs
parent3e55189b504f961e68e631b72a2ed71991397ef9 (diff)
downloadlinux-f7f6943a8c6dccbd085600bbb7bae4f6f6047dc4.tar.xz
bcachefs: Fix copy_to_user() usage in flush_buf()
copy_to_user() returns the number of bytes successfully copied - not an errcode. Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs')
-rw-r--r--fs/bcachefs/debug.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/fs/bcachefs/debug.c b/fs/bcachefs/debug.c
index 404148bd348a..75a3dc7cbd47 100644
--- a/fs/bcachefs/debug.c
+++ b/fs/bcachefs/debug.c
@@ -319,16 +319,16 @@ static ssize_t flush_buf(struct dump_iter *i)
{
if (i->buf.pos) {
size_t bytes = min_t(size_t, i->buf.pos, i->size);
- int err = copy_to_user(i->ubuf, i->buf.buf, bytes);
+ int copied = bytes - copy_to_user(i->ubuf, i->buf.buf, bytes);
- if (err)
- return err;
+ i->ret += copied;
+ i->ubuf += copied;
+ i->size -= copied;
+ i->buf.pos -= copied;
+ memmove(i->buf.buf, i->buf.buf + copied, i->buf.pos);
- i->ret += bytes;
- i->ubuf += bytes;
- i->size -= bytes;
- i->buf.pos -= bytes;
- memmove(i->buf.buf, i->buf.buf + bytes, i->buf.pos);
+ if (copied != bytes)
+ return -EFAULT;
}
return i->size ? 0 : i->ret;