diff mbox

[2/9] block: clarify badblocks lifetime

Message ID 20160106072257.40900.58682.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Williams Jan. 6, 2016, 7:22 a.m. UTC
The badblocks list attached to a gendisk is optionally allocated by the
driver which implies the driver owns the lifetime of the object.  Do not
automatically free it in del_gendisk(), leave that to the driver.  This
is in preparation for expanding the use of badblocks in libnvdimm
drivers and introducing devm_alloc_badblocks().

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 block/badblocks.c     |    2 ++
 block/genhd.c         |    5 -----
 drivers/nvdimm/pmem.c |   10 +++++++---
 3 files changed, 9 insertions(+), 8 deletions(-)


--
To unsubscribe from this list: send the line "unsubscribe linux-block" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/block/badblocks.c b/block/badblocks.c
index 96aeb9194a2e..9be8bf94f979 100644
--- a/block/badblocks.c
+++ b/block/badblocks.c
@@ -555,6 +555,8 @@  EXPORT_SYMBOL_GPL(badblocks_init);
  */
 void badblocks_free(struct badblocks *bb)
 {
+	if (!bb)
+		return;
 	kfree(bb->page);
 	bb->page = NULL;
 }
diff --git a/block/genhd.c b/block/genhd.c
index 5481b5308a70..b96012849e26 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -660,11 +660,6 @@  static void del_gendisk_end(struct gendisk *disk)
 	blk_unregister_queue(disk);
 	blk_unregister_region(disk_devt(disk), disk->minors);
 
-	if (disk->bb) {
-		badblocks_free(disk->bb);
-		kfree(disk->bb);
-	}
-
 	part_stat_set_all(&disk->part0, 0);
 	disk->part0.stamp = 0;
 
diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index d20c8112e90d..dd829251342d 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -23,6 +23,7 @@ 
 #include <linux/module.h>
 #include <linux/memory_hotplug.h>
 #include <linux/moduleparam.h>
+#include <linux/badblocks.h>
 #include <linux/vmalloc.h>
 #include <linux/slab.h>
 #include <linux/pmem.h>
@@ -155,11 +156,14 @@  static struct pmem_device *pmem_alloc(struct device *dev,
 
 static void pmem_detach_disk(struct pmem_device *pmem)
 {
-	if (!pmem->pmem_disk)
+	struct gendisk *disk = pmem->pmem_disk;
+
+	if (!disk)
 		return;
 
-	del_gendisk_queue(pmem->pmem_disk);
-	put_disk(pmem->pmem_disk);
+	badblocks_free(disk->bb);
+	del_gendisk_queue(disk);
+	put_disk(disk);
 }
 
 static int pmem_attach_disk(struct device *dev,