[PATCH v2 10/10] block: put_device() if device_add() fails
From: Luis Chamberlain
Date: Sun Apr 19 2020 - 15:46:01 EST
Through code inspection I've found that we don't put_device() if
device_add() fails, and this must be done to decrement its refcount.
Signed-off-by: Luis Chamberlain <mcgrof@xxxxxxxxxx>
---
block/genhd.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/block/genhd.c b/block/genhd.c
index 06b642b23a07..c52095a74792 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -721,8 +721,10 @@ static void register_disk(struct device *parent, struct gendisk *disk,
WARN_ON(ddev->groups);
ddev->groups = groups;
}
- if (device_add(ddev))
+ if (device_add(ddev)) {
+ put_device(ddev);
return;
+ }
if (!sysfs_deprecated) {
err = sysfs_create_link(block_depr, &ddev->kobj,
kobject_name(&ddev->kobj));
--
2.25.1