@@ -324,6 +324,15 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size,
dev->mtd.priv = dev;
dev->mtd.owner = THIS_MODULE;
+ /*
+ * Check if we are using root blockdev.
+ * If it's the case, connect the MTD of_node to the ddev parent
+ * to support providing partition in DT node.
+ */
+ ddev = disk_to_dev(dev->blkdev->bd_disk);
+ if (ddev == &dev->blkdev->bd_device)
+ dev->mtd.dev.of_node = of_node_get(ddev->parent->of_node);
+
if (mtd_device_register(&dev->mtd, NULL, 0)) {
/* Device didn't get added, so free the entry */
goto err_destroy_mutex;
@@ -337,6 +346,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size,
return dev;
err_destroy_mutex:
+ of_node_put(dev->mtd.dev.of_node);
mutex_destroy(&dev->write_mutex);
err_free_block2mtd:
block2mtd_free_device(dev);
@@ -515,6 +525,7 @@ static void block2mtd_exit(void)
struct block2mtd_dev *dev = list_entry(pos, typeof(*dev), list);
block2mtd_sync(&dev->mtd);
mtd_device_unregister(&dev->mtd);
+ of_node_put(dev->mtd.dev.of_node);
mutex_destroy(&dev->write_mutex);
pr_info("mtd%d: [%s] removed\n",
dev->mtd.index,
Attach device OF node to MTD device if defined and the root blockdev is being used to add support for partitions defined in DT node. This permits the usage of fixed-partition or alternative parser with the use of block2mtd module. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com> --- drivers/mtd/devices/block2mtd.c | 11 +++++++++++ 1 file changed, 11 insertions(+)