Linux-Block Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] blk-mq: Fix memory leak in blk_mq_init_allocated_queue error handling
@ 2019-07-23 14:10 zhengbin
  2019-08-12  8:53 ` zhengbin (A)
  2019-08-12 14:17 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: zhengbin @ 2019-07-23 14:10 UTC (permalink / raw)
  To: axboe, ming.lei, linux-block; +Cc: yi.zhang, zhengbin13

If blk_mq_init_allocated_queue->elevator_init_mq fails, need to release
the previously requested resources.

Fixes: d34849913 ("blk-mq-sched: allow setting of default IO scheduler")
Signed-off-by: zhengbin <zhengbin13@huawei.com>
---
 block/blk-mq.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index b038ec6..e001610 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2845,6 +2845,8 @@ static unsigned int nr_hw_queues(struct blk_mq_tag_set *set)
 struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
 						  struct request_queue *q)
 {
+	int ret = -ENOMEM;
+
 	/* mark the queue as mq asap */
 	q->mq_ops = set->ops;

@@ -2906,17 +2908,18 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
 	blk_mq_map_swqueue(q);

 	if (!(set->flags & BLK_MQ_F_NO_SCHED)) {
-		int ret;
-
 		ret = elevator_init_mq(q);
 		if (ret)
-			return ERR_PTR(ret);
+			goto err_tag_set;
 	}

 	return q;

+err_tag_set:
+	blk_mq_del_queue_tag_set(q);
 err_hctxs:
 	kfree(q->queue_hw_ctx);
+	q->nr_hw_queues = 0;
 err_sys_init:
 	blk_mq_sysfs_deinit(q);
 err_poll:
--
2.7.4


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

* Re: [PATCH] blk-mq: Fix memory leak in blk_mq_init_allocated_queue error handling
  2019-07-23 14:10 [PATCH] blk-mq: Fix memory leak in blk_mq_init_allocated_queue error handling zhengbin
@ 2019-08-12  8:53 ` zhengbin (A)
  2019-08-12 14:17 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: zhengbin (A) @ 2019-08-12  8:53 UTC (permalink / raw)
  To: axboe, ming.lei, linux-block; +Cc: yi.zhang, bvanassche

ping

On 2019/7/23 22:10, zhengbin wrote:
> If blk_mq_init_allocated_queue->elevator_init_mq fails, need to release
> the previously requested resources.
>
> Fixes: d34849913 ("blk-mq-sched: allow setting of default IO scheduler")
> Signed-off-by: zhengbin <zhengbin13@huawei.com>
> ---
>  block/blk-mq.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index b038ec6..e001610 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -2845,6 +2845,8 @@ static unsigned int nr_hw_queues(struct blk_mq_tag_set *set)
>  struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
>  						  struct request_queue *q)
>  {
> +	int ret = -ENOMEM;
> +
>  	/* mark the queue as mq asap */
>  	q->mq_ops = set->ops;
>
> @@ -2906,17 +2908,18 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
>  	blk_mq_map_swqueue(q);
>
>  	if (!(set->flags & BLK_MQ_F_NO_SCHED)) {
> -		int ret;
> -
>  		ret = elevator_init_mq(q);
>  		if (ret)
> -			return ERR_PTR(ret);
> +			goto err_tag_set;
>  	}
>
>  	return q;
>
> +err_tag_set:
> +	blk_mq_del_queue_tag_set(q);
>  err_hctxs:
>  	kfree(q->queue_hw_ctx);
> +	q->nr_hw_queues = 0;
>  err_sys_init:
>  	blk_mq_sysfs_deinit(q);
>  err_poll:
> --
> 2.7.4
>
>
> .
>


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

* Re: [PATCH] blk-mq: Fix memory leak in blk_mq_init_allocated_queue error handling
  2019-07-23 14:10 [PATCH] blk-mq: Fix memory leak in blk_mq_init_allocated_queue error handling zhengbin
  2019-08-12  8:53 ` zhengbin (A)
@ 2019-08-12 14:17 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2019-08-12 14:17 UTC (permalink / raw)
  To: zhengbin, ming.lei, linux-block; +Cc: yi.zhang

On 7/23/19 7:10 AM, zhengbin wrote:
> If blk_mq_init_allocated_queue->elevator_init_mq fails, need to release
> the previously requested resources.
> 
> Fixes: d34849913 ("blk-mq-sched: allow setting of default IO scheduler")

Please always use 12 char abbreviations for git shas. I fixed it up.

But thanks for the patch, applied.

-- 
Jens Axboe


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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-23 14:10 [PATCH] blk-mq: Fix memory leak in blk_mq_init_allocated_queue error handling zhengbin
2019-08-12  8:53 ` zhengbin (A)
2019-08-12 14:17 ` Jens Axboe

Linux-Block Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-block/0 linux-block/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-block linux-block/ https://lore.kernel.org/linux-block \
		linux-block@vger.kernel.org linux-block@archiver.kernel.org
	public-inbox-index linux-block


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-block


AGPL code for this site: git clone https://public-inbox.org/ public-inbox