Move header copying from ring logic into a new copy_header_from_ring() function. This consolidates error handling. Signed-off-by: Joanne Koong --- fs/fuse/dev_uring.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/fs/fuse/dev_uring.c b/fs/fuse/dev_uring.c index e94af90d4d46..faa7217e85c4 100644 --- a/fs/fuse/dev_uring.c +++ b/fs/fuse/dev_uring.c @@ -585,6 +585,17 @@ static int copy_header_to_ring(void __user *ring, const void *header, return 0; } +static int copy_header_from_ring(void *header, const void __user *ring, + size_t header_size) +{ + if (copy_from_user(header, ring, header_size)) { + pr_info_ratelimited("Copying header from ring failed.\n"); + return -EFAULT; + } + + return 0; +} + static int fuse_uring_copy_from_ring(struct fuse_ring *ring, struct fuse_req *req, struct fuse_ring_ent *ent) @@ -595,10 +606,10 @@ static int fuse_uring_copy_from_ring(struct fuse_ring *ring, int err; struct fuse_uring_ent_in_out ring_in_out; - err = copy_from_user(&ring_in_out, &ent->headers->ring_ent_in_out, - sizeof(ring_in_out)); + err = copy_header_from_ring(&ring_in_out, &ent->headers->ring_ent_in_out, + sizeof(ring_in_out)); if (err) - return -EFAULT; + return err; err = import_ubuf(ITER_SOURCE, ent->payload, ring->max_payload_sz, &iter); @@ -789,10 +800,10 @@ static void fuse_uring_commit(struct fuse_ring_ent *ent, struct fuse_req *req, struct fuse_conn *fc = ring->fc; ssize_t err = 0; - err = copy_from_user(&req->out.h, &ent->headers->in_out, - sizeof(req->out.h)); + err = copy_header_from_ring(&req->out.h, &ent->headers->in_out, + sizeof(req->out.h)); if (err) { - req->out.h.error = -EFAULT; + req->out.h.error = err; goto out; } -- 2.47.3