block: release bip in a right way in error path
PATCH v2 1/1 block: release bip in a right way in error path
Release bip using kfree() in error path when that was allocated by kmalloc().
Signed-off-by Chengguang Xu <[email protected]>
---v1->v2:
- Introduce a new helper __bio_integrity_free() to reduce duplicated code.
block/bio-integrity.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
block/bio-integrity.c +14 -9
@@ -24,6 +24,18 @@ void blk_flush_integrity(void)flush_workqueue (kintegrityd_wq); } +void __bio_integrity_free (struct bio_set *bs,struct bio_integrity_payload *bip) +{ +if (bs &&mempool_initialized (&bs->bio_integrity_pool)) { +if (bip->bip_vec) +bvec_free (&bs->bvec_integrity_pool, bip->bip_vec, + bip->bip_slab); +mempool_free (bip, &bs->bio_integrity_pool); + }else { +kfree (bip); + } +} +/** * bio_integrity_alloc - Allocate integrity payload and attach it to bio * @bio: bio to attach integrity metadata to
@@ -75,7 +87,7 @@ struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio,return bip; err: -mempool_free (bip, &bs->bio_integrity_pool); +__bio_integrity_free (bs, bip);return ERR_PTR (-ENOMEM ); }EXPORT_SYMBOL (bio_integrity_alloc);
@@ -96,14 +108,7 @@ void bio_integrity_free(struct bio *bio)kfree (page_address (bip->bip_vec->bv_page) + bip->bip_vec->bv_offset); -if (bs &&mempool_initialized (&bs->bio_integrity_pool)) { -bvec_free (&bs->bvec_integrity_pool, bip->bip_vec, bip->bip_slab); - -mempool_free (bip, &bs->bio_integrity_pool); - }else { -kfree (bip); - } - +__bio_integrity_free (bs, bip); bio->bi_integrity =NULL ; bio->bi_opf &= ~REQ_INTEGRITY ; }
Signature · 1 line
2.20.1
Quoted 4 lines · Chengguang Xu
Release bip using
kfree()in error path when that was allocated bykmalloc().Signed-off-by Chengguang Xu <[email protected]>
Looks good,
Reviewed-by Christoph Hellwig <[email protected]>
Chengguang,
Quoted 2 lines
Release bip using
kfree()in error path when that was allocated bykmalloc().
Looks good to me.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Quoted 2 lines · Chengguang Xu
Release bip using
kfree()in error path when that was allocated bykmalloc().
Applied, thanks.
Signature · 1 line
Jens Axboe