Commit f7f6943a authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Fix copy_to_user() usage in flush_buf()

copy_to_user() returns the number of bytes successfully copied - not an
errcode.
Reported-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 3e55189b
...@@ -319,16 +319,16 @@ static ssize_t flush_buf(struct dump_iter *i) ...@@ -319,16 +319,16 @@ static ssize_t flush_buf(struct dump_iter *i)
{ {
if (i->buf.pos) { if (i->buf.pos) {
size_t bytes = min_t(size_t, i->buf.pos, i->size); 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) i->ret += copied;
return err; i->ubuf += copied;
i->size -= copied;
i->buf.pos -= copied;
memmove(i->buf.buf, i->buf.buf + copied, i->buf.pos);
i->ret += bytes; if (copied != bytes)
i->ubuf += bytes; return -EFAULT;
i->size -= bytes;
i->buf.pos -= bytes;
memmove(i->buf.buf, i->buf.buf + bytes, i->buf.pos);
} }
return i->size ? 0 : i->ret; return i->size ? 0 : i->ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment