linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block/bio-integrity: fix mismatched alloc free
@ 2019-08-18 10:35 Pan Bian
  2019-08-18 16:27 ` Bart Van Assche
  0 siblings, 1 reply; 2+ messages in thread
From: Pan Bian @ 2019-08-18 10:35 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, linux-kernel, Pan Bian

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] block/bio-integrity: fix mismatched alloc free
  2019-08-18 10:35 [PATCH] block/bio-integrity: fix mismatched alloc free Pan Bian
@ 2019-08-18 16:27 ` Bart Van Assche
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Van Assche @ 2019-08-18 16:27 UTC (permalink / raw)
  To: Pan Bian, Jens Axboe; +Cc: linux-block, linux-kernel

On 8/18/19 3:35 AM, Pan Bian wrote:
> 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);
> 

Also for this patch, please add "Fixes:" and "Cc: stable" tags.

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-08-18 16:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-18 10:35 [PATCH] block/bio-integrity: fix mismatched alloc free Pan Bian
2019-08-18 16:27 ` Bart Van Assche

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).