lkml.org 
[lkml]   [2019]   [Aug]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] block/bio-integrity: fix mismatched alloc free
Date
The function kmalloc rather than mempool_alloc is called to allocate
memory when the memory pool is unavailable. However, mempool_alloc is
used to release the memory chunck in both cases when error occurs. This
patch fixes the bug.

Signed-off-by: Pan Bian <bianpan2016@163.com>
---
block/bio-integrity.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index fb95dbb..011dfc8 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -75,7 +75,10 @@ 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))
+ kfree(bip);
+ else
+ mempool_free(bip, &bs->bio_integrity_pool);
return ERR_PTR(-ENOMEM);
}
EXPORT_SYMBOL(bio_integrity_alloc);
--
2.7.4
\
 
 \ /
  Last update: 2019-08-18 12:51    [W:0.045 / U:0.048 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site