Skip to contentSkip to conversation

Fix kobject_add refcount imbalance on block layer

PATCH In review Lin Yi 2 participants 6 messages Jun 4, 2019 Block layer

lore
Share & tools
lore

Lin Yi

author
#0 lore raw

cover Fix kobject_add refcount imbalance on block layer

kobject_add increments the parent kobj refcount, but forget to release it after err return, it will lead to a memory leak.

Lin Yi (2):
block :blk-sysfs :fix kobj refcount imbalance on the err return path block :blk-mq-sysfs :fix kobj refcount imbalance on err return path

 block/blk-mq-sysfs.c | 4 +++-
 block/blk-sysfs.c    | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH 1/2 block :blk-sysfs :fix kobj refcount imbalance on the err return path

kobject_add takes a refcount to the object dev->kobj, but forget to release it before return, lead to a memory leak.

Fixes 7bd1d5edd016 ("Merge branch 'x86-urgent-for-linus' of

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip")
Cc: [email protected]

---
 block/blk-sysfs.c | 1 +
 1 file changed, 1 insertion(+)
block/blk-sysfs.c +1 -0
index 75b5281..539b7cb 100644
@@ -971,6 +971,7 @@ int blk_register_queue(struct gendisk *disk)
 	ret = kobject_add(&q->kobj, kobject_get(&dev->kobj), "%s", "queue");
 	if (ret < 0) {
 		blk_trace_remove_sysfs(dev);
+		kobject_put(&dev->kobj);
 		goto unlock;
 	}
 
Signature · 1 line
1.9.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] block :blk-sysfs :fix kobj refcount imbalance on the err return path

Looks good.

Quoted 24 lines · Lin Yi

kobject_add takes a refcount to the object dev->kobj, but forget to release it before return, lead to a memory leak.

Fixes 7bd1d5edd016 ("Merge branch 'x86-urgent-for-linus' of

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip")
Cc: [email protected]

---
  block/blk-sysfs.c | 1 +
  1 file changed, 1 insertion(+)
block/blk-sysfs.c +1 -0
index 75b5281..539b7cb 100644
@@ -971,6 +971,7 @@ int blk_register_queue(struct gendisk *disk)
  	ret = kobject_add(&q->kobj, kobject_get(&dev->kobj), "%s", "queue");
  	if (ret < 0) {
  		blk_trace_remove_sysfs(dev);
+		kobject_put(&dev->kobj);
  		goto unlock;
  	}
 
author
#3 lore raw

PATCH 2/2 block :blk-mq-sysfs :fix kobj refcount imbalance on err return path

In reply to Lin Yi

kobject_add takes a refcount to the object dev->kobj, but forget to release it before return, lead to a memory leak.

Fixes 7bd1d5edd016 ("Merge branch 'x86-urgent-for-linus' of

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip")
Cc: [email protected]

---
 block/blk-mq-sysfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/blk-mq-sysfs.c +3 -1
index d6e1a9b..7499a47 100644
@@ -323,8 +323,10 @@ int __blk_mq_register_dev(struct device *dev, struct request_queue *q)
 	lockdep_assert_held(&q->sysfs_lock);
 
 	ret = kobject_add(q->mq_kobj, kobject_get(&dev->kobj), "%s", "mq");
-	if (ret < 0)
+	if (ret < 0) {
+		kobject_put(&dev->kobj);
 		goto out;
+	}
 
 	kobject_uevent(q->mq_kobj, KOBJ_ADD);
 
Signature · 1 line
1.9.1
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] block :blk-mq-sysfs :fix kobj refcount imbalance on err return path

Looks good.

Quoted 28 lines · Lin Yi

kobject_add takes a refcount to the object dev->kobj, but forget to release it before return, lead to a memory leak.

Fixes 7bd1d5edd016 ("Merge branch 'x86-urgent-for-linus' of

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip")
Cc: [email protected]

---
  block/blk-mq-sysfs.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
block/blk-mq-sysfs.c +3 -1
index d6e1a9b..7499a47 100644
@@ -323,8 +323,10 @@ int __blk_mq_register_dev(struct device *dev, struct request_queue *q)
  	lockdep_assert_held(&q->sysfs_lock);
 
  	ret = kobject_add(q->mq_kobj, kobject_get(&dev->kobj), "%s", "mq");
-	if (ret < 0)
+	if (ret < 0) {
+		kobject_put(&dev->kobj);
  		goto out;
+	}
 
  	kobject_uevent(q->mq_kobj, KOBJ_ADD);
 
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] block :blk-mq-sysfs :fix kobj refcount imbalance on err return path

In reply to Lin Yi

Looks good.

Quoted 28 lines · Lin Yi

kobject_add takes a refcount to the object dev->kobj, but forget to release it before return, lead to a memory leak.

Fixes 7bd1d5edd016 ("Merge branch 'x86-urgent-for-linus' of

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip")
Cc: [email protected]

---
  block/blk-mq-sysfs.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
block/blk-mq-sysfs.c +3 -1
index d6e1a9b..7499a47 100644
@@ -323,8 +323,10 @@ int __blk_mq_register_dev(struct device *dev, struct request_queue *q)
  	lockdep_assert_held(&q->sysfs_lock);
 
  	ret = kobject_add(q->mq_kobj, kobject_get(&dev->kobj), "%s", "mq");
-	if (ret < 0)
+	if (ret < 0) {
+		kobject_put(&dev->kobj);
  		goto out;
+	}
 
  	kobject_uevent(q->mq_kobj, KOBJ_ADD);