[PATCH 10/20] ublk: inline ublk_check_and_get_req() into ublk_user_copy()

Caleb Sander Mateos
2025-12-17T05:35:16Z

ublk_check_and_get_req() has a single callsite in ublk_user_copy(). It
takes a ton of arguments in order to pass local variables from
ublk_user_copy() to ublk_check_and_get_req() and vice versa. And more
are about to be added. Combine the functions to reduce the argument
passing noise.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
---
drivers/block/ublk_drv.c | 51 ++++++++++++++--------------------------
1 file changed, 18 insertions(+), 33 deletions(-)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index e39ed8a0f0ae..273d580ddc46 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -2612,70 +2612,55 @@ static inline bool ublk_check_ubuf_dir(const struct request *req,
return true;

return false;
}

-static struct request *ublk_check_and_get_req(struct kiocb *iocb,
- struct iov_iter *iter, size_t *off, int dir,
- struct ublk_io **io)
+static ssize_t
+ublk_user_copy(struct kiocb *iocb, struct iov_iter *iter, int dir)
{
struct ublk_device *ub = iocb->ki_filp->private_data;
struct ublk_queue *ubq;
struct request *req;
+ struct ublk_io *io;
size_t buf_off;
u16 tag, q_id;
+ ssize_t ret;

if (!user_backed_iter(iter))
- return ERR_PTR(-EACCES);
+ return -EACCES;

if (ub->dev_info.state == UBLK_S_DEV_DEAD)
- return ERR_PTR(-EACCES);
+ return -EACCES;

tag = ublk_pos_to_tag(iocb->ki_pos);
q_id = ublk_pos_to_hwq(iocb->ki_pos);
buf_off = ublk_pos_to_buf_off(iocb->ki_pos);

if (q_id >= ub->dev_info.nr_hw_queues)
- return ERR_PTR(-EINVAL);
+ return -EINVAL;

ubq = ublk_get_queue(ub, q_id);
if (!ublk_dev_support_user_copy(ub))
- return ERR_PTR(-EACCES);
+ return -EACCES;

if (tag >= ub->dev_info.queue_depth)
- return ERR_PTR(-EINVAL);
+ return -EINVAL;

- *io = &ubq->ios[tag];
- req = __ublk_check_and_get_req(ub, q_id, tag, *io, buf_off);
+ io = &ubq->ios[tag];
+ req = __ublk_check_and_get_req(ub, q_id, tag, io, buf_off);
if (!req)
- return ERR_PTR(-EINVAL);
-
- if (!ublk_check_ubuf_dir(req, dir))
- goto fail;
-
- *off = buf_off;
- return req;
-fail:
- ublk_put_req_ref(*io, req);
- return ERR_PTR(-EACCES);
-}
-
-static ssize_t
-ublk_user_copy(struct kiocb *iocb, struct iov_iter *iter, int dir)
-{
- struct request *req;
- struct ublk_io *io;
- size_t buf_off;
- size_t ret;
+ return -EINVAL;

- req = ublk_check_and_get_req(iocb, iter, &buf_off, dir, &io);
- if (IS_ERR(req))
- return PTR_ERR(req);
+ if (!ublk_check_ubuf_dir(req, dir)) {
+ ret = -EACCES;
+ goto out;
+ }

ret = ublk_copy_user_pages(req, buf_off, iter, dir);
- ublk_put_req_ref(io, req);

+out:
+ ublk_put_req_ref(io, req);
return ret;
}

static ssize_t ublk_ch_read_iter(struct kiocb *iocb, struct iov_iter *to)
{
--
2.45.2