linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] mtd: mtdcore: add debugfs nodes for querying the flash name and id
@ 2019-08-29  7:10 Tudor.Ambarus
  2019-08-29  7:10 ` [PATCH 1/2] " Tudor.Ambarus
  2019-08-29  7:10 ` [PATCH 2/2] mtd: spi-nor: enable the debugfs for the partname and partid Tudor.Ambarus
  0 siblings, 2 replies; 3+ messages in thread
From: Tudor.Ambarus @ 2019-08-29  7:10 UTC (permalink / raw)
  To: richard, miquel.raynal, vigneshr, boris.brezillon, linux-mtd,
	linux-kernel, zhuohao
  Cc: Tudor.Ambarus

From: Tudor Ambarus <tudor.ambarus@microchip.com>

I just rebased Zhuohao's patches and fixed some checkpatch warnings and
checks. I'll let this a little bit here for some short review, and I intend
to apply the patches later today.

For patch 1/, I fixed the following:
CHECK: multiple assignments should be avoided
#82: FILE: drivers/mtd/mtdcore.c:390:
+	root = mtd->dbg.dfs_dir = debugfs_create_dir(dev_name(dev),

WARNING: Symbolic permissions 'S_IRUSR' are not preferred. Consider using octal permissions '0400'.
#90: FILE: drivers/mtd/mtdcore.c:398:
+		dent = debugfs_create_file("partid", S_IRUSR, root, mtd,

WARNING: Symbolic permissions 'S_IRUSR' are not preferred. Consider using octal permissions '0400'.
#97: FILE: drivers/mtd/mtdcore.c:405:
+		dent = debugfs_create_file("partname", S_IRUSR, root, mtd,


For patch 2/, I fixed some alignment checks, and I moved the call to
spi_nor_debugfs_init() immediately after spi_nor_get_flash_info(),
because it uses some info data set there.
CHECK: Alignment should match open parenthesis
#162: FILE: drivers/mtd/spi-nor/spi-nor.c:3939:
+static void spi_nor_debugfs_init(struct spi_nor *nor,
+		const struct flash_info *info)

CHECK: Alignment should match open parenthesis
#168: FILE: drivers/mtd/spi-nor/spi-nor.c:3945:
+	mtd->dbg.partid = devm_kasprintf(nor->dev, GFP_KERNEL,
+					"spi-nor:%*phN",

Zhuohao Lee (2):
  mtd: mtdcore: add debugfs nodes for querying the flash name and id
  mtd: spi-nor: enable the debugfs for the partname and partid

 drivers/mtd/mtdcore.c         | 86 ++++++++++++++++++++++++++++++++++++++-----
 drivers/mtd/spi-nor/spi-nor.c | 12 ++++++
 include/linux/mtd/mtd.h       |  3 ++
 3 files changed, 92 insertions(+), 9 deletions(-)

-- 
2.9.5


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] mtd: mtdcore: add debugfs nodes for querying the flash name and id
  2019-08-29  7:10 [PATCH 0/2] mtd: mtdcore: add debugfs nodes for querying the flash name and id Tudor.Ambarus
@ 2019-08-29  7:10 ` Tudor.Ambarus
  2019-08-29  7:10 ` [PATCH 2/2] mtd: spi-nor: enable the debugfs for the partname and partid Tudor.Ambarus
  1 sibling, 0 replies; 3+ messages in thread
From: Tudor.Ambarus @ 2019-08-29  7:10 UTC (permalink / raw)
  To: richard, miquel.raynal, vigneshr, boris.brezillon, linux-mtd,
	linux-kernel, zhuohao
  Cc: Tudor.Ambarus

From: Zhuohao Lee <zhuohao@chromium.org>

Currently, we don't have vfs nodes for querying the underlying flash name
and flash id. This information is important especially when we want to
know the flash detail of the defective system. In order to support the
query, we add mtd_debugfs_populate() to create two debugfs nodes
(ie. partname and partid). The upper driver can assign the pointer to
partname and partid before calling mtd_device_register().

Signed-off-by: Zhuohao Lee <zhuohao@chromium.org>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/mtdcore.c   | 86 +++++++++++++++++++++++++++++++++++++++++++------
 include/linux/mtd/mtd.h |  3 ++
 2 files changed, 80 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 408615f29e57..830a114e8500 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -335,6 +335,82 @@ static const struct device_type mtd_devtype = {
 	.release	= mtd_release,
 };
 
+static int mtd_partid_show(struct seq_file *s, void *p)
+{
+	struct mtd_info *mtd = s->private;
+
+	seq_printf(s, "%s\n", mtd->dbg.partid);
+
+	return 0;
+}
+
+static int mtd_partid_debugfs_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, mtd_partid_show, inode->i_private);
+}
+
+static const struct file_operations mtd_partid_debug_fops = {
+	.open           = mtd_partid_debugfs_open,
+	.read           = seq_read,
+	.llseek         = seq_lseek,
+	.release        = single_release,
+};
+
+static int mtd_partname_show(struct seq_file *s, void *p)
+{
+	struct mtd_info *mtd = s->private;
+
+	seq_printf(s, "%s\n", mtd->dbg.partname);
+
+	return 0;
+}
+
+static int mtd_partname_debugfs_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, mtd_partname_show, inode->i_private);
+}
+
+static const struct file_operations mtd_partname_debug_fops = {
+	.open           = mtd_partname_debugfs_open,
+	.read           = seq_read,
+	.llseek         = seq_lseek,
+	.release        = single_release,
+};
+
+static struct dentry *dfs_dir_mtd;
+
+static void mtd_debugfs_populate(struct mtd_info *mtd)
+{
+	struct device *dev = &mtd->dev;
+	struct dentry *root, *dent;
+
+	if (IS_ERR_OR_NULL(dfs_dir_mtd))
+		return;
+
+	root = debugfs_create_dir(dev_name(dev), dfs_dir_mtd);
+	if (IS_ERR_OR_NULL(root)) {
+		dev_dbg(dev, "won't show data in debugfs\n");
+		return;
+	}
+
+	mtd->dbg.dfs_dir = root;
+
+	if (mtd->dbg.partid) {
+		dent = debugfs_create_file("partid", 0400, root, mtd,
+					   &mtd_partid_debug_fops);
+		if (IS_ERR_OR_NULL(dent))
+			dev_err(dev,
+				"can't create debugfs entry for partid\n");
+	}
+	if (mtd->dbg.partname) {
+		dent = debugfs_create_file("partname", 0400, root, mtd,
+					   &mtd_partname_debug_fops);
+		if (IS_ERR_OR_NULL(dent))
+			dev_err(dev,
+				"can't create debugfs entry for partname\n");
+	}
+}
+
 #ifndef CONFIG_MMU
 unsigned mtd_mmap_capabilities(struct mtd_info *mtd)
 {
@@ -512,8 +588,6 @@ static int mtd_nvmem_add(struct mtd_info *mtd)
 	return 0;
 }
 
-static struct dentry *dfs_dir_mtd;
-
 /**
  *	add_mtd_device - register an MTD device
  *	@mtd: pointer to new MTD device info structure
@@ -607,13 +681,7 @@ int add_mtd_device(struct mtd_info *mtd)
 	if (error)
 		goto fail_nvmem_add;
 
-	if (!IS_ERR_OR_NULL(dfs_dir_mtd)) {
-		mtd->dbg.dfs_dir = debugfs_create_dir(dev_name(&mtd->dev), dfs_dir_mtd);
-		if (IS_ERR_OR_NULL(mtd->dbg.dfs_dir)) {
-			pr_debug("mtd device %s won't show data in debugfs\n",
-				 dev_name(&mtd->dev));
-		}
-	}
+	mtd_debugfs_populate(mtd);
 
 	device_create(&mtd_class, mtd->dev.parent, MTD_DEVT(i) + 1, NULL,
 		      "mtd%dro", i);
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 4ca8c1c845fb..249e8d9bfbcd 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -189,6 +189,9 @@ struct module;	/* only needed for owner field in mtd_info */
  */
 struct mtd_debug_info {
 	struct dentry *dfs_dir;
+
+	const char *partname;
+	const char *partid;
 };
 
 struct mtd_info {
-- 
2.9.5


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] mtd: spi-nor: enable the debugfs for the partname and partid
  2019-08-29  7:10 [PATCH 0/2] mtd: mtdcore: add debugfs nodes for querying the flash name and id Tudor.Ambarus
  2019-08-29  7:10 ` [PATCH 1/2] " Tudor.Ambarus
@ 2019-08-29  7:10 ` Tudor.Ambarus
  1 sibling, 0 replies; 3+ messages in thread
From: Tudor.Ambarus @ 2019-08-29  7:10 UTC (permalink / raw)
  To: richard, miquel.raynal, vigneshr, boris.brezillon, linux-mtd,
	linux-kernel, zhuohao
  Cc: Tudor.Ambarus

From: Zhuohao Lee <zhuohao@chromium.org>

This patch adds spi_nor_debugfs_init() for the debugfs initialization.
With this patch, we can read the partname and partid through the
debugfs.

The output of new debugfs nodes on my device are:
cat /sys/kernel/debug/mtd/mtd0/partid
spi-nor:ef6017
cat /sys/kernel/debug/mtd/mtd0/partname
w25q64dw

Signed-off-by: Zhuohao Lee <zhuohao@chromium.org>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/spi-nor.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 79c8f1dd8c6b..6a2fff0598af 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -4767,6 +4767,16 @@ static int spi_nor_set_addr_width(struct spi_nor *nor)
 	return 0;
 }
 
+static void spi_nor_debugfs_init(struct spi_nor *nor,
+				 const struct flash_info *info)
+{
+	struct mtd_info *mtd = &nor->mtd;
+
+	mtd->dbg.partname = info->name;
+	mtd->dbg.partid = devm_kasprintf(nor->dev, GFP_KERNEL, "spi-nor:%*phN",
+					 info->id_len, info->id);
+}
+
 static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor,
 						       const char *name)
 {
@@ -4847,6 +4857,8 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 
 	nor->info = info;
 
+	spi_nor_debugfs_init(nor, info);
+
 	mutex_init(&nor->lock);
 
 	/*
-- 
2.9.5


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-08-29  7:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-29  7:10 [PATCH 0/2] mtd: mtdcore: add debugfs nodes for querying the flash name and id Tudor.Ambarus
2019-08-29  7:10 ` [PATCH 1/2] " Tudor.Ambarus
2019-08-29  7:10 ` [PATCH 2/2] mtd: spi-nor: enable the debugfs for the partname and partid Tudor.Ambarus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).