]> www.infradead.org Git - users/hch/misc.git/commitdiff
block: remove the bi_inline_vecs variable sized array from struct bio remove-bi_inline_vecs
authorChristoph Hellwig <hch@lst.de>
Fri, 5 Sep 2025 03:29:35 +0000 (05:29 +0200)
committerChristoph Hellwig <hch@lst.de>
Fri, 5 Sep 2025 03:34:23 +0000 (05:34 +0200)
Bios are embedded into other structures, and at least spare is unhappy
about embedding structures with variable sized arrays.  There's no
real need to the array anyway, we can replace it with a helper pointing
to the memory just behind the bio, and with the previous cleanups there
is very few site (and only one outside the usual suspects) doing
anything special with it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
block/bio.c
drivers/md/bcache/movinggc.c
drivers/md/bcache/writeback.c
drivers/md/dm-vdo/vio.c
fs/bcachefs/data_update.h
fs/bcachefs/journal.c
include/linux/bio.h
include/linux/blk_types.h

index bd8bf179981a80e708e15c351c1f591b93195202..971d96afaf8d0e56199fc547570de5974c75c5f6 100644 (file)
@@ -617,7 +617,8 @@ struct bio *bio_kmalloc(unsigned short nr_vecs, gfp_t gfp_mask)
 
        if (nr_vecs > BIO_MAX_INLINE_VECS)
                return NULL;
-       return kmalloc(struct_size(bio, bi_inline_vecs, nr_vecs), gfp_mask);
+       return kmalloc(sizeof(*bio) + nr_vecs * sizeof(struct bio_vec),
+                       gfp_mask);
 }
 EXPORT_SYMBOL(bio_kmalloc);
 
index 4fc80c6d5b31dc9807d9b1cf07b0d229f70c6a82..73918e55bf041d4b662f0e5484db14936d75f2bd 100644 (file)
@@ -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);
                if (!io)
                        goto err;
 
index 36dd8f14a6df0820f69492cbb4588f4bae3ceb07..6ba73dc1a3dff175482ce06cbd09e6dcabd83b2f 100644 (file)
@@ -536,9 +536,9 @@ static void read_dirty(struct cached_dev *dc)
                for (i = 0; i < nk; i++) {
                        w = keys[i];
 
-                       io = kzalloc(struct_size(io, 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);
                        if (!io)
                                goto err;
 
index e7f4153e55e3c04e91ba8a9530255be05b45a90f..8fc22fb141965d081efb4f120c0174da34225c61 100644 (file)
@@ -212,7 +212,7 @@ int vio_reset_bio_with_size(struct vio *vio, char *data, int size, bio_end_io_t
                return VDO_SUCCESS;
 
        bio->bi_ioprio = 0;
-       bio->bi_io_vec = bio->bi_inline_vecs;
+       bio->bi_io_vec = bio_inline_vecs(bio);
        bio->bi_max_vecs = vio->block_count + 1;
        if (VDO_ASSERT(size <= vio_size, "specified size %d is not greater than allocated %d",
                       size, vio_size) != VDO_SUCCESS)
index 5e14d13568de8f980a4452be5d423a56d6657890..1b37780abfda1b078b7d1157404b9a5e170186f8 100644 (file)
@@ -62,7 +62,6 @@ struct promote_op {
 
        struct work_struct      work;
        struct data_update      write;
-       struct bio_vec          bi_inline_vecs[]; /* must be last */
 };
 
 void bch2_data_update_to_text(struct printbuf *, struct data_update *);
index 3dbf9faaaa4c6b81e10dbb28d5e57493debc5c07..474e0e867b68869bbbb03be12433d86b1715c276 100644 (file)
@@ -1627,8 +1627,8 @@ int bch2_dev_journal_init(struct bch_dev *ca, struct bch_sb *sb)
        unsigned nr_bvecs = DIV_ROUND_UP(JOURNAL_ENTRY_SIZE_MAX, PAGE_SIZE);
 
        for (unsigned i = 0; i < ARRAY_SIZE(ja->bio); i++) {
-               ja->bio[i] = kzalloc(struct_size(ja->bio[i], bio.bi_inline_vecs,
-                                    nr_bvecs), GFP_KERNEL);
+               ja->bio[i] = kzalloc(sizeof(*ja->bio[i]) +
+                               sizeof(struct bio_vec) * nr_bvecs, GFP_KERNEL);
                if (!ja->bio[i])
                        return bch_err_throw(c, ENOMEM_dev_journal_init);
 
index eb7f4fbd8aa93fa385062c0c0238438605ba6af4..27cbff5b0356e26f168dd6754f3379ae013935e9 100644 (file)
@@ -408,7 +408,7 @@ void bio_init(struct bio *bio, struct block_device *bdev, struct bio_vec *table,
 static inline void bio_init_inline(struct bio *bio, struct block_device *bdev,
              unsigned short max_vecs, blk_opf_t opf)
 {
-       bio_init(bio, bdev, bio->bi_inline_vecs, max_vecs, opf);
+       bio_init(bio, bdev, bio_inline_vecs(bio), max_vecs, opf);
 }
 extern void bio_uninit(struct bio *);
 void bio_reset(struct bio *bio, struct block_device *bdev, blk_opf_t opf);
index 930daff207df2cf80cf8831e6e5a1daab225d2e9..bbb7893e05422aa1cb7e76860db3899a55f7d6d8 100644 (file)
@@ -269,18 +269,16 @@ struct bio {
        struct bio_vec          *bi_io_vec;     /* the actual vec list */
 
        struct bio_set          *bi_pool;
-
-       /*
-        * We can inline a number of vecs at the end of the bio, to avoid
-        * double allocations for a small number of bio_vecs. This member
-        * MUST obviously be kept at the very end of the bio.
-        */
-       struct bio_vec          bi_inline_vecs[];
 };
 
 #define BIO_RESET_BYTES                offsetof(struct bio, bi_max_vecs)
 #define BIO_MAX_SECTORS                (UINT_MAX >> SECTOR_SHIFT)
 
+static inline struct bio_vec *bio_inline_vecs(struct bio *bio)
+{
+       return (struct bio_vec *)(bio + 1);
+}
+
 /*
  * bio flags
  */