linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pan Bian <bianpan2016@163.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	Pan Bian <bianpan2016@163.com>,
	stable@vger.kernel.org
Subject: [PATCH V2] block: fix a mismatched alloc free in bio_alloc_bioset
Date: Mon, 19 Aug 2019 08:55:20 +0800	[thread overview]
Message-ID: <1566176120-19924-1-git-send-email-bianpan2016@163.com> (raw)

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.


Fixes: 3f86a82aeb ("block: Consolidate bio_alloc_bioset(), bio_kmalloc()")
Signed-off-by: Pan Bian <bianpan2016@163.com>
Cc: stable@vger.kernel.org
---
V2: add Fixes and Cc tags
---
 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


             reply	other threads:[~2019-08-19  1:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-19  0:55 Pan Bian [this message]
2019-08-19  3:53 ` [PATCH V2] block: fix a mismatched alloc free in bio_alloc_bioset Ming Lei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1566176120-19924-1-git-send-email-bianpan2016@163.com \
    --to=bianpan2016@163.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).