[PATCH] ublk: don't cast registered buffer index to int

Caleb Sander Mateos posted 1 patch 11 months, 1 week ago
drivers/block/ublk_drv.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
[PATCH] ublk: don't cast registered buffer index to int
Posted by Caleb Sander Mateos 11 months, 1 week ago
io_buffer_register_bvec() takes index as an unsigned int argument, but
ublk_register_io_buf() casts ub_cmd->addr (a u64) to int. Remove the
misleading cast and instead pass index as an unsigned value to
ublk_register_io_buf() and ublk_unregister_io_buf().

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

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 512cbd456817..af5a4ff4bd3d 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -1760,16 +1760,15 @@ static void ublk_io_release(void *priv)
 	ublk_put_req_ref(ubq, rq);
 }
 
 static int ublk_register_io_buf(struct io_uring_cmd *cmd,
 				struct ublk_queue *ubq, unsigned int tag,
-				const struct ublksrv_io_cmd *ub_cmd,
-				unsigned int issue_flags)
+				unsigned int index, unsigned int issue_flags)
 {
 	struct ublk_device *ub = cmd->file->private_data;
-	int index = (int)ub_cmd->addr, ret;
 	struct request *req;
+	int ret;
 
 	req = __ublk_check_and_get_req(ub, ubq, tag, 0);
 	if (!req)
 		return -EINVAL;
 
@@ -1782,14 +1781,13 @@ static int ublk_register_io_buf(struct io_uring_cmd *cmd,
 
 	return 0;
 }
 
 static int ublk_unregister_io_buf(struct io_uring_cmd *cmd,
-				  const struct ublksrv_io_cmd *ub_cmd,
-				  unsigned int issue_flags)
+				  unsigned int index, unsigned int issue_flags)
 {
-	return io_buffer_unregister_bvec(cmd, ub_cmd->addr, issue_flags);
+	return io_buffer_unregister_bvec(cmd, index, issue_flags);
 }
 
 static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
 			       unsigned int issue_flags,
 			       const struct ublksrv_io_cmd *ub_cmd)
@@ -1840,13 +1838,13 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
 		goto out;
 
 	ret = -EINVAL;
 	switch (_IOC_NR(cmd_op)) {
 	case UBLK_IO_REGISTER_IO_BUF:
-		return ublk_register_io_buf(cmd, ubq, tag, ub_cmd, issue_flags);
+		return ublk_register_io_buf(cmd, ubq, tag, ub_cmd->addr, issue_flags);
 	case UBLK_IO_UNREGISTER_IO_BUF:
-		return ublk_unregister_io_buf(cmd, ub_cmd, issue_flags);
+		return ublk_unregister_io_buf(cmd, ub_cmd->addr, issue_flags);
 	case UBLK_IO_FETCH_REQ:
 		/* UBLK_IO_FETCH_REQ is only allowed before queue is setup */
 		if (ublk_queue_ready(ubq)) {
 			ret = -EBUSY;
 			goto out;
-- 
2.45.2
Re: [PATCH] ublk: don't cast registered buffer index to int
Posted by Jens Axboe 11 months, 1 week ago
On Sat, 01 Mar 2025 12:03:16 -0700, Caleb Sander Mateos wrote:
> io_buffer_register_bvec() takes index as an unsigned int argument, but
> ublk_register_io_buf() casts ub_cmd->addr (a u64) to int. Remove the
> misleading cast and instead pass index as an unsigned value to
> ublk_register_io_buf() and ublk_unregister_io_buf().
> 
> 

Applied, thanks!

[1/1] ublk: don't cast registered buffer index to int
      commit: 9e12d09cfdaf89db894abdad392bb8dcd6c0f464

Best regards,
-- 
Jens Axboe
Re: [PATCH] ublk: don't cast registered buffer index to int
Posted by Ming Lei 11 months, 1 week ago
On Sat, Mar 01, 2025 at 12:03:16PM -0700, Caleb Sander Mateos wrote:
> io_buffer_register_bvec() takes index as an unsigned int argument, but
> ublk_register_io_buf() casts ub_cmd->addr (a u64) to int. Remove the
> misleading cast and instead pass index as an unsigned value to
> ublk_register_io_buf() and ublk_unregister_io_buf().
> 
> Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>

Reviewed-by: Ming Lei <ming.lei@redhat.com>


Thanks,
Ming