@@ -193,20 +193,13 @@ static void pmem_unmapmem(struct pmem_device *pmem)
#endif /* !CONFIG_BLK_DEV_PMEM_USE_PAGES */
-static int pmem_probe(struct platform_device *pdev)
+static int pmem_alloc(struct resource *res, struct device *dev,
+ struct pmem_device **o_pmem)
{
struct pmem_device *pmem;
struct gendisk *disk;
- struct resource *res;
int idx, err;
- if (WARN_ON(pdev->num_resources > 1))
- return -ENXIO;
-
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- if (unlikely(!res))
- return -ENXIO;
-
pmem = kzalloc(sizeof(*pmem), GFP_KERNEL);
if (unlikely(!pmem))
return -ENOMEM;
@@ -240,13 +233,12 @@ static int pmem_probe(struct platform_device *pdev)
disk->queue = pmem->pmem_queue;
disk->flags = GENHD_FL_EXT_DEVT;
sprintf(disk->disk_name, "pmem%d", idx);
- disk->driverfs_dev = &pdev->dev;
+ disk->driverfs_dev = dev;
set_capacity(disk, pmem->size >> 9);
pmem->pmem_disk = disk;
add_disk(disk);
-
- platform_set_drvdata(pdev, pmem);
+ *o_pmem = pmem;
return 0;
out_free_queue:
@@ -255,19 +247,45 @@ out_unmap:
pmem_unmapmem(pmem);
out_free_dev:
kfree(pmem);
+ *o_pmem = NULL;
return err;
}
-static int pmem_remove(struct platform_device *pdev)
+static void pmem_free(struct pmem_device *pmem)
{
- struct pmem_device *pmem = platform_get_drvdata(pdev);
-
del_gendisk(pmem->pmem_disk);
put_disk(pmem->pmem_disk);
blk_cleanup_queue(pmem->pmem_queue);
pmem_unmapmem(pmem);
kfree(pmem);
+}
+
+static int pmem_probe(struct platform_device *pdev)
+{
+ struct pmem_device *pmem;
+ struct resource *res;
+ int err;
+
+ if (WARN_ON(pdev->num_resources > 1))
+ return -ENXIO;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (unlikely(!res))
+ return -ENXIO;
+
+ err = pmem_alloc(res, &pdev->dev, &pmem);
+ if (unlikely(err))
+ return err;
+
+ platform_set_drvdata(pdev, pmem);
+ return 0;
+}
+
+static int pmem_remove(struct platform_device *pdev)
+{
+ struct pmem_device *pmem = platform_get_drvdata(pdev);
+ pmem_free(pmem);
return 0;
}