[PATCH 2/2] mtd: mtdpart: Create a symlink to the master debugfs dir

Boris Brezillon
2017-10-04T13:53:18Z

It's sometime hard to figure out which master device is attached to an
MTD partition, especially when this master device is not registered to
the device model.

Add a symlink to master's debugfs dir from the partition debugfs dir to
help with that.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
drivers/mtd/mtdpart.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index a308e707392d..6f81acdd7f34 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -21,6 +21,7 @@
*
*/

+#include <linux/debugfs.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
@@ -778,15 +779,18 @@ int add_mtd_partitions(struct mtd_info *master,
{
struct mtd_part *slave;
uint64_t cur_offset = 0;
- int i;
+ int ret = 0, i;
+ char *link;

printk(KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n", nbparts, master->name);
+ link = kasprintf(GFP_KERNEL, "../%s", dev_name(&master->dev));

for (i = 0; i < nbparts; i++) {
slave = allocate_partition(master, parts + i, i, cur_offset);
if (IS_ERR(slave)) {
del_mtd_partitions(master);
- return PTR_ERR(slave);
+ ret = PTR_ERR(slave);
+ break;
}

mutex_lock(&mtd_partitions_mutex);
@@ -798,10 +802,13 @@ int add_mtd_partitions(struct mtd_info *master,
if (parts[i].types)
mtd_parse_part(slave, parts[i].types);

+ debugfs_create_symlink("master", slave->mtd.dbg.dfs_dir, link);
cur_offset = slave->offset + slave->mtd.size;
}

- return 0;
+ kfree(link);
+
+ return ret;
}

static DEFINE_SPINLOCK(part_parser_lock);
--
2.11.0