On Tue, Sep 09, 2025 at 04:40:33PM +0800, Yu Kuai wrote: > Hi, > > 在 2025/09/09 16:16, John Garry 写道: >>> diff --git a/drivers/md/bcache/movinggc.c b/drivers/md/bcache/movinggc.c >>> index 4fc80c6d5b31..73918e55bf04 100644 >>> --- a/drivers/md/bcache/movinggc.c >>> +++ b/drivers/md/bcache/movinggc.c >>> @@ -145,9 +145,9 @@ static void read_moving(struct cache_set *c) >>> continue; >>> } >>> - io = kzalloc(struct_size(io, bio.bio.bi_inline_vecs, >>> - DIV_ROUND_UP(KEY_SIZE(&w->key), PAGE_SECTORS)), >>> - GFP_KERNEL); >>> + io = kzalloc(sizeof(*io) + sizeof(struct bio_vec) * >>> + DIV_ROUND_UP(KEY_SIZE(&w->key), PAGE_SECTORS), >>> + GFP_KERNEL); >> >> this seems a common pattern, so maybe another helper (which could be used >> by bio_kmalloc)? I am not advocating it, but just putting the idea out >> there... too many helpers makes it messy IMHO > > Not sure how to do this, do you mean a marco to pass in the base > structure type, nr_vecs and the gfp_mask? It's not a very common pattern, and should be even less common. If a driver / file system wants to embed a bio into its own structure but dynamically allocate the bio_vecs, it can simply use kmalloc_array, or add a bio_vec VLA to its own structure and use struct_size on that.