[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1595636232-15297-1-git-send-email-wang.yi59@zte.com.cn>
Date: Sat, 25 Jul 2020 08:17:12 +0800
From: Yi Wang <wang.yi59@....com.cn>
To: axboe@...nel.dk
Cc: linux-block@...r.kernel.org, linux-kernel@...r.kernel.org,
xue.zhihong@....com.cn, wang.yi59@....com.cn,
wang.liang82@....com.cn, Liao Pingfang <liao.pingfang@....com.cn>
Subject: [PATCH] block: Fix reference count leak in blk_integrity_add
From: Liao Pingfang <liao.pingfang@....com.cn>
kobject_init_and_add() takes reference even when it fails. If this
function returns an error, kobject_put() must be called to properly
clean up the memory associated with the object.
Signed-off-by: Liao Pingfang <liao.pingfang@....com.cn>
Signed-off-by: Yi Wang <wang.yi59@....com.cn>
---
block/blk-integrity.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/block/blk-integrity.c b/block/blk-integrity.c
index c03705c..118b2f2 100644
--- a/block/blk-integrity.c
+++ b/block/blk-integrity.c
@@ -436,8 +436,10 @@ EXPORT_SYMBOL(blk_integrity_unregister);
void blk_integrity_add(struct gendisk *disk)
{
if (kobject_init_and_add(&disk->integrity_kobj, &integrity_ktype,
- &disk_to_dev(disk)->kobj, "%s", "integrity"))
+ &disk_to_dev(disk)->kobj, "%s", "integrity")) {
+ kobject_put(&disk->integrity_kobj);
return;
+ }
kobject_uevent(&disk->integrity_kobj, KOBJ_ADD);
}
--
2.9.5
Powered by blists - more mailing lists