Thread (3 messages) 3 messages, 2 authors, 2020-06-24

Re: [PATCH] block; release bip in a right way in error path

From: Christoph Hellwig <hch@infradead.org>
Date: 2020-06-24 06:50:25

On Tue, Jun 23, 2020 at 10:06:53PM +0800, Chengguang Xu wrote:
quoted hunk ↗ jump to hunk
Release bip using kfree() in error path when that was allocated
by kmalloc().

Signed-off-by: Chengguang Xu <redacted>
---
 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?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help