Skip to contentSkip to conversation

block :blk-sysfs: fix refcount imbalance on the error path

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

lore
Share & tools
lore

Lin Yi

author
#0 lore raw

PATCH 1/1 block :blk-sysfs: fix refcount imbalance on the error path

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

---
 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
#1 lore raw
Quoted 13 lines · Lin Yi

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

---
  block/blk-sysfs.c | 1 +
  1 file changed, 1 insertion(+)
block/blk-sysfs.c +0 -0
index 75b5281..539b7cb 100644

block/blk-sysfs.c int blk_register_queue(struct gendisk *disk) · line 976

Quoted 6 lines
block/blk-sysfs.c +1 -0
@@ -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;
  	}

Have you reviewed the other kobject_add() calls in the block layer? Are there more such calls that need to be fixed?

Additionally, please add "Fixes:" and "Cc: stable" tags.

Thanks,

Bart.