linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] blk-mq: Fix refcounting leak in __blk_mq_register_dev()
@ 2020-09-05 12:52 Dan Carpenter
  2020-09-07  7:19 ` Ming Lei
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2020-09-05 12:52 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, linux-kernel, kernel-janitors

There is a kobject_add() hidden in the call to kobject_add().

	ret = kobject_add(q->mq_kobj, kobject_get(&dev->kobj), "%s", "mq");
                                      ^^^^^^^^^^^^^^^^^^^^^^^

It needs to be release on the error path.

Fixes: 320ae51feed5 ("blk-mq: new multi-queue block IO queueing mechanism")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 block/blk-mq-sysfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c
index 062229395a50..5a63659163c1 100644
--- a/block/blk-mq-sysfs.c
+++ b/block/blk-mq-sysfs.c
@@ -321,7 +321,7 @@ int __blk_mq_register_dev(struct device *dev, struct request_queue *q)
 
 	ret = kobject_add(q->mq_kobj, kobject_get(&dev->kobj), "%s", "mq");
 	if (ret < 0)
-		goto out;
+		goto out_kobj;
 
 	kobject_uevent(q->mq_kobj, KOBJ_ADD);
 
@@ -333,8 +333,7 @@ int __blk_mq_register_dev(struct device *dev, struct request_queue *q)
 
 	q->mq_sysfs_init_done = true;
 
-out:
-	return ret;
+	return 0;
 
 unreg:
 	while (--i >= 0)
@@ -342,6 +341,7 @@ int __blk_mq_register_dev(struct device *dev, struct request_queue *q)
 
 	kobject_uevent(q->mq_kobj, KOBJ_REMOVE);
 	kobject_del(q->mq_kobj);
+out_kobj:
 	kobject_put(&dev->kobj);
 	return ret;
 }
-- 
2.28.0


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

* Re: [PATCH] blk-mq: Fix refcounting leak in __blk_mq_register_dev()
  2020-09-05 12:52 [PATCH] blk-mq: Fix refcounting leak in __blk_mq_register_dev() Dan Carpenter
@ 2020-09-07  7:19 ` Ming Lei
  0 siblings, 0 replies; 2+ messages in thread
From: Ming Lei @ 2020-09-07  7:19 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Jens Axboe, linux-block, linux-kernel, kernel-janitors

On Sat, Sep 05, 2020 at 03:52:06PM +0300, Dan Carpenter wrote:
> There is a kobject_add() hidden in the call to kobject_add().
> 
> 	ret = kobject_add(q->mq_kobj, kobject_get(&dev->kobj), "%s", "mq");
>                                       ^^^^^^^^^^^^^^^^^^^^^^^
> 
> It needs to be release on the error path.
> 
> Fixes: 320ae51feed5 ("blk-mq: new multi-queue block IO queueing mechanism")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  block/blk-mq-sysfs.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c
> index 062229395a50..5a63659163c1 100644
> --- a/block/blk-mq-sysfs.c
> +++ b/block/blk-mq-sysfs.c
> @@ -321,7 +321,7 @@ int __blk_mq_register_dev(struct device *dev, struct request_queue *q)
>  
>  	ret = kobject_add(q->mq_kobj, kobject_get(&dev->kobj), "%s", "mq");
>  	if (ret < 0)
> -		goto out;
> +		goto out_kobj;
>  
>  	kobject_uevent(q->mq_kobj, KOBJ_ADD);
>  
> @@ -333,8 +333,7 @@ int __blk_mq_register_dev(struct device *dev, struct request_queue *q)
>  
>  	q->mq_sysfs_init_done = true;
>  
> -out:
> -	return ret;
> +	return 0;
>  
>  unreg:
>  	while (--i >= 0)
> @@ -342,6 +341,7 @@ int __blk_mq_register_dev(struct device *dev, struct request_queue *q)
>  
>  	kobject_uevent(q->mq_kobj, KOBJ_REMOVE);
>  	kobject_del(q->mq_kobj);
> +out_kobj:
>  	kobject_put(&dev->kobj);
>  	return ret;
>  }
> -- 
> 2.28.0
> 

Looks good fix:

Reviewed-by: Ming Lei <ming.lei@redhat.com>

-- 
Ming


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

end of thread, other threads:[~2020-09-07  7:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-05 12:52 [PATCH] blk-mq: Fix refcounting leak in __blk_mq_register_dev() Dan Carpenter
2020-09-07  7:19 ` Ming Lei

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