On 6/24/20 2:50 PM, Christoph Hellwig wrote:
On Tue, Jun 23, 2020 at 10:06:53PM +0800, Chengguang Xu wrote:
Release bip using kfree() in error path when that was allocated
by kmalloc().
Signed-off-by: Chengguang Xu <cgxu519@xxxxxxxxxxxx>
---
block/bio-integrity.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index 23632a33ed39..538c8dc8840a 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -78,7 +78,11 @@ struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio,
return bip;
err:
- mempool_free(bip, &bs->bio_integrity_pool);
+ if (bs && mempool_initialized(&bs->bio_integrity_pool))
+ mempool_free(bip, &bs->bio_integrity_pool);
+ else
+ kfree(bip);
+
return ERR_PTR(-ENOMEM);
How about factoring out a __bio_integrity_free helper to not duplicate
this logic?
Yeah, that's better, thanks for the suggestion.
cgxu