ublk: specify io_cmd_buf pointer type
authorCaleb Sander Mateos <csander@purestorage.com>
Fri, 28 Mar 2025 19:42:29 +0000 (13:42 -0600)
committerJens Axboe <axboe@kernel.dk>
Sat, 29 Mar 2025 11:56:36 +0000 (05:56 -0600)
io_cmd_buf points to an array of ublksrv_io_desc structs but its type is
char *. Indexing the array requires an explicit multiplication and cast.
The compiler also can't check the pointer types.

Change io_cmd_buf's type to struct ublksrv_io_desc * so it can be
indexed directly and the compiler can type-check the code.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Link: https://lore.kernel.org/r/20250328194230.2726862-2-csander@purestorage.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/ublk_drv.c

index 466a23b8937999c5e53cbe667c0ef096b5732a5e..2fd05c1bd30b03343cb6f357f8c08dd92ff47af9 100644 (file)
@@ -158,7 +158,7 @@ struct ublk_queue {
 
        unsigned long flags;
        struct task_struct      *ubq_daemon;
-       char *io_cmd_buf;
+       struct ublksrv_io_desc *io_cmd_buf;
 
        bool force_abort;
        bool timeout;
@@ -706,11 +706,11 @@ static inline bool ublk_rq_has_data(const struct request *rq)
 static inline struct ublksrv_io_desc *ublk_get_iod(struct ublk_queue *ubq,
                int tag)
 {
-       return (struct ublksrv_io_desc *)
-               &(ubq->io_cmd_buf[tag * sizeof(struct ublksrv_io_desc)]);
+       return &ubq->io_cmd_buf[tag];
 }
 
-static inline char *ublk_queue_cmd_buf(struct ublk_device *ub, int q_id)
+static inline struct ublksrv_io_desc *
+ublk_queue_cmd_buf(struct ublk_device *ub, int q_id)
 {
        return ublk_get_queue(ub, q_id)->io_cmd_buf;
 }