diff --git a/block/genhd.c b/block/genhd.c
index 64f83c4aee99bfd7eb7bacdd0907830c88aa1d4e..8ea818aa88caa955ecb466b0729c4fe74e337d2f 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -468,11 +468,15 @@ int device_add_disk(struct device *parent, struct gendisk *disk,
 
 	disk->part0->bd_holder_dir =
 		kobject_create_and_add("holders", &ddev->kobj);
-	if (!disk->part0->bd_holder_dir)
+	if (!disk->part0->bd_holder_dir) {
+		ret = -ENOMEM;
 		goto out_del_integrity;
+	}
 	disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj);
-	if (!disk->slave_dir)
+	if (!disk->slave_dir) {
+		ret = -ENOMEM;
 		goto out_put_holder_dir;
+	}
 
 	ret = bd_register_pending_holders(disk);
 	if (ret < 0)