Skip to content

Commit

Permalink
block: release bip in a right way in error path
Browse files Browse the repository at this point in the history
Release bip using kfree() in error path when that was allocated
by kmalloc().

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Chengguang Xu authored and Jens Axboe committed Jun 24, 2020
1 parent 3373a34 commit 0b8eb62
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions block/bio-integrity.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,7 +90,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);
Expand All @@ -99,14 +111,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;
}
Expand Down

0 comments on commit 0b8eb62

Please sign in to comment.