block/bio-integrity: fix mismatched alloc free
Subsystems (2)
PATCH v2 1/1 block/bio-integrity: fix mismatched alloc free
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.
---
V2: add Fixes and CC tags
--- block/bio-integrity.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
block/bio-integrity.c +4 -1
@@ -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);
Signature · 1 line
2.7.4
Quoted 20 lines · Pan Bian
The function kmalloc rather than
mempool_allocis called to allocate memory when the memory pool is unavailable. However,mempool_allocis used to release the memory chunck in both cases when error occurs. This patch fixes the bug.Fixes 9f060e2231c ("block: Convert integrity to bvec_alloc_bs()")Signed-off-by Pan Bian <[email protected]>---
V2: add Fixes and CC tags--- block/bio-integrity.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)block/bio-integrity.c +0
-0@@ -75,7 +75,10 @@ struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio,
block/bio-integrity.c struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio, · line 84
Quoted 10 lines
block/bio-integrity.c +4
-1return 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);
'err' is still reached in case that 'bs' is valid, so fix nothing.
Thanks,
Ming
Quoted 21 lines · Ming Lei
Quoted 20 lines · Pan Bian
The function kmalloc rather than
mempool_allocis called to allocate memory when the memory pool is unavailable. However,mempool_allocis used to release the memory chunck in both cases when error occurs. This patch fixes the bug.Fixes 9f060e2231c ("block: Convert integrity to bvec_alloc_bs()")Signed-off-by Pan Bian <[email protected]>---
V2: add Fixes and CC tags--- block/bio-integrity.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)block/bio-integrity.c +0
-0@@ -75,7 +75,10 @@ struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio,
Quoted 12 lines
block/bio-integrity.c struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio, · line 84
Quoted 10 lines
block/bio-integrity.c +4
-1return 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);'err' is still reached in case that 'bs' is valid, so fix nothing.
You are right! It's my fault.
Thanks,
Pan
Quoted 4 lines
Thanks,
Ming