* [PATCH v2] block: release bip in a right way in error path
@ 2020-06-24 10:21 Chengguang Xu
2020-06-24 10:34 ` Christoph Hellwig
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Chengguang Xu @ 2020-06-24 10:21 UTC (permalink / raw)
To: axboe; +Cc: hch, linux-block, Chengguang Xu
Release bip using kfree() in error path when that was allocated
by kmalloc().
Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
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(-)
diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index bf62c25cde8f..1d173feb3883 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -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;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] block: release bip in a right way in error path
2020-06-24 10:21 [PATCH v2] block: release bip in a right way in error path Chengguang Xu
@ 2020-06-24 10:34 ` Christoph Hellwig
2020-06-24 12:07 ` Martin K. Petersen
2020-06-24 14:49 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2020-06-24 10:34 UTC (permalink / raw)
To: Chengguang Xu; +Cc: axboe, hch, linux-block
On Wed, Jun 24, 2020 at 06:21:39PM +0800, Chengguang Xu wrote:
> Release bip using kfree() in error path when that was allocated
> by kmalloc().
>
> Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
Looks good,
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] block: release bip in a right way in error path
2020-06-24 10:21 [PATCH v2] block: release bip in a right way in error path Chengguang Xu
2020-06-24 10:34 ` Christoph Hellwig
@ 2020-06-24 12:07 ` Martin K. Petersen
2020-06-24 14:49 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2020-06-24 12:07 UTC (permalink / raw)
To: Chengguang Xu; +Cc: axboe, hch, linux-block
Chengguang,
> Release bip using kfree() in error path when that was allocated
> by kmalloc().
Looks good to me.
Acked-by: Martin K. Petersen <martin.petersen@oracle.com>
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] block: release bip in a right way in error path
2020-06-24 10:21 [PATCH v2] block: release bip in a right way in error path Chengguang Xu
2020-06-24 10:34 ` Christoph Hellwig
2020-06-24 12:07 ` Martin K. Petersen
@ 2020-06-24 14:49 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2020-06-24 14:49 UTC (permalink / raw)
To: Chengguang Xu; +Cc: hch, linux-block
On 6/24/20 4:21 AM, Chengguang Xu wrote:
> Release bip using kfree() in error path when that was allocated
> by kmalloc().
Applied, thanks.
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-06-24 14:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-24 10:21 [PATCH v2] block: release bip in a right way in error path Chengguang Xu
2020-06-24 10:34 ` Christoph Hellwig
2020-06-24 12:07 ` Martin K. Petersen
2020-06-24 14:49 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).