On Tue, Jul 2, 2024 at 7:38 PM Anuj Gupta <anuj20.g@xxxxxxxxxxx> wrote: > > Modify bio_integrity_clone to reuse the original bvec array instead of > allocating and copying it, similar to how bio data path is cloned. > > Suggested-by: Christoph Hellwig <hch@xxxxxx> > Signed-off-by: Anuj Gupta <anuj20.g@xxxxxxxxxxx> > --- > block/bio-integrity.c | 9 +++------ > 1 file changed, 3 insertions(+), 6 deletions(-) > > diff --git a/block/bio-integrity.c b/block/bio-integrity.c > index c4aed1dfa497..b78c145eb026 100644 > --- a/block/bio-integrity.c > +++ b/block/bio-integrity.c > @@ -76,7 +76,7 @@ struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio, > &bip->bip_max_vcnt, gfp_mask); > if (!bip->bip_vec) > goto err; > - } else { > + } else if (nr_vecs) { > bip->bip_vec = bip->bip_inline_vecs; > } > > @@ -584,14 +584,11 @@ int bio_integrity_clone(struct bio *bio, struct bio *bio_src, > > BUG_ON(bip_src == NULL); > > - bip = bio_integrity_alloc(bio, gfp_mask, bip_src->bip_vcnt); > + bip = bio_integrity_alloc(bio, gfp_mask, 0); > if (IS_ERR(bip)) > return PTR_ERR(bip); > > - memcpy(bip->bip_vec, bip_src->bip_vec, > - bip_src->bip_vcnt * sizeof(struct bio_vec)); > - > - bip->bip_vcnt = bip_src->bip_vcnt; > + bip->bip_vec = bip_src->bip_vec; > bip->bip_iter = bip_src->bip_iter; > bip->bip_flags = bip_src->bip_flags & ~BIP_BLOCK_INTEGRITY; I am curious how the patch avoids double free? Given nothing changes in bip free code path and source bip_vec is associated with this bip. Thanks,