Hi,
在 2025/09/09 16:55, John Garry 写道:
On 09/09/2025 09:40, Yu Kuai wrote:
在 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?
something like the following (which I think is messy and an imprecise
API, so again I am not advocating it):
struct bio *bio_kmalloc(unsigned short nr_vecs, gfp_t gfp_mask)
{
return kmalloc(sizeof(struct bio) + nr_vecs * sizeof(struct bio_vec),
gfp_mask);
}
struct bio *bio_kmalloc_inline(unsigned short nr_vecs, gfp_t gfp_mask)
{
if (nr_vecs > BIO_MAX_INLINE_VECS)
return NULL;
return bio_kmalloc(nr_vecs, gfp_mask);
}
However, the caller is allocating the base structure that bio is
embedded, the above helper to return bio is still not common.
Perhaps this patch is better anyway.
Thanks,
Kuai
.