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

The function kmalloc is called to allocate memory if bs is NULL.
However, mempool_free is used to release the memory chunk even if bs is
NULL in the error hanlding code. This patch checks bs and use the
correct function to release memory.

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

diff --git a/block/bio.c b/block/bio.c
index 299a0e7..c5f5238 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -515,7 +515,10 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask, unsigned int nr_iovecs,
 	return bio;
 
 err_free:
-	mempool_free(p, &bs->bio_pool);
+	if (!bs)
+		kfree(p);
+	else
+		mempool_free(p, &bs->bio_pool);
 	return NULL;
 }
 EXPORT_SYMBOL(bio_alloc_bioset);
-- 
2.7.4


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

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

On 8/18/19 3:57 AM, Pan Bian wrote:
> The function kmalloc is called to allocate memory if bs is NULL.
> However, mempool_free is used to release the memory chunk even if bs is
> NULL in the error hanlding code. This patch checks bs and use the
> correct function to release memory.
> 
> Signed-off-by: Pan Bian <bianpan2016@163.com>
> ---
>   block/bio.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/block/bio.c b/block/bio.c
> index 299a0e7..c5f5238 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -515,7 +515,10 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask, unsigned int nr_iovecs,
>   	return bio;
>   
>   err_free:
> -	mempool_free(p, &bs->bio_pool);
> +	if (!bs)
> +		kfree(p);
> +	else
> +		mempool_free(p, &bs->bio_pool);
>   	return NULL;
>   }
>   EXPORT_SYMBOL(bio_alloc_bioset);
> 

Please add "Fixes:" and "Cc: stable" tags. See also 
Documentation/process/submitting-patches.rst.

Thanks,

Bart.

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

end of thread, other threads:[~2019-08-18 16:26 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:57 [PATCH] block: fix a mismatched alloc free in bio_alloc_bioset Pan Bian
2019-08-18 16:26 ` Bart Van Assche

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.