Fix kobject_add refcount imbalance on block layer
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
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.
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
@@ -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
Re: [PATCH 1/2] block :blk-sysfs :fix kobj refcount imbalance on the err return path
Looks good.
Quoted 24 lines · Lin Yi
kobject_addtakes a refcount to the objectdev->kobj, but forget to release it before return, lead to a memory leak.Signed-off-by Lin Yi <[email protected]>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@@ -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; }
PATCH 2/2 block :blk-mq-sysfs :fix kobj refcount imbalance on err return path
In reply to Lin Yikobject_add takes a refcount to the object dev->kobj, but forget to release it before return, lead to a memory leak.
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
@@ -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
Re: [PATCH 2/2] block :blk-mq-sysfs :fix kobj refcount imbalance on err return path
Looks good.
Quoted 28 lines · Lin Yi
kobject_addtakes a refcount to the objectdev->kobj, but forget to release it before return, lead to a memory leak.Signed-off-by Lin Yi <[email protected]>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@@ -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 );
Re: [PATCH 2/2] block :blk-mq-sysfs :fix kobj refcount imbalance on err return path
In reply to Lin YiLooks good.
Quoted 28 lines · Lin Yi
kobject_addtakes a refcount to the objectdev->kobj, but forget to release it before return, lead to a memory leak.Signed-off-by Lin Yi <[email protected]>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@@ -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 );