Convert ublk_queue to use DECLARE_FLEX_ARRAY for the ios field and use struct_size() for allocation, following kernel best practices. Changes in this commit: 1. Convert ios field from "struct ublk_io ios[]" to use DECLARE_FLEX_ARRAY(struct ublk_io, ios) for consistency with modern kernel style. 2. Update ublk_init_queue() to use struct_size(ubq, ios, depth) instead of manual size calculation (sizeof(struct ublk_queue) + depth * sizeof(struct ublk_io)). This provides better type safety and makes the code more maintainable by using standard kernel macros for flexible array handling. Signed-off-by: Ming Lei --- drivers/block/ublk_drv.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 394e9b5f512f..cef9cfa94feb 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -203,7 +203,8 @@ struct ublk_queue { bool fail_io; /* copy of dev->state == UBLK_S_DEV_FAIL_IO */ spinlock_t cancel_lock; struct ublk_device *dev; - struct ublk_io ios[]; + + DECLARE_FLEX_ARRAY(struct ublk_io, ios); }; struct ublk_device { @@ -2700,7 +2701,6 @@ static int ublk_get_queue_numa_node(struct ublk_device *ub, int q_id) static int ublk_init_queue(struct ublk_device *ub, int q_id) { int depth = ub->dev_info.queue_depth; - int ubq_size = sizeof(struct ublk_queue) + depth * sizeof(struct ublk_io); gfp_t gfp_flags = GFP_KERNEL | __GFP_ZERO; struct ublk_queue *ubq; struct page *page; @@ -2711,7 +2711,8 @@ static int ublk_init_queue(struct ublk_device *ub, int q_id) numa_node = ublk_get_queue_numa_node(ub, q_id); /* Allocate queue structure on local NUMA node */ - ubq = kvzalloc_node(ubq_size, GFP_KERNEL, numa_node); + ubq = kvzalloc_node(struct_size(ubq, ios, depth), GFP_KERNEL, + numa_node); if (!ubq) return -ENOMEM; -- 2.47.0