mtd: create per-device and module-scope debugfs entries · shadowscript/linux@e8e3edb · GitHub
Skip to content

Commit e8e3edb

Browse files
Oppencomputersforpeace
authored andcommitted
mtd: create per-device and module-scope debugfs entries
Several MTD devices are using debugfs entries created in the root. This commit provides the means for a standardized subtree, creating one "mtd" entry at root, and one entry per device inside it, named after the device. The tree is registered in add_mtd_device, and released in del_mtd_device. Devices docg3, mtdswap and nandsim were updated to use this subtree instead of custom ones, and their entries were prefixed with the drivers' names. Signed-off-by: Mario J. Rugiero <mrugiero@gmail.com> Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
1 parent 5771a8c commit e8e3edb

6 files changed

Lines changed: 59 additions & 84 deletions

File tree

drivers/mtd/devices/docg3.c

Lines changed: 17 additions & 32 deletions

drivers/mtd/devices/docg3.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ struct docg3_cascade {
299299
* @oob_autoecc: if 1, use only bytes 0-7, 15, and fill the others with HW ECC
300300
* if 0, use all the 16 bytes.
301301
* @oob_write_buf: prepared OOB for next page_write
302-
* @debugfs_root: debugfs root node
303302
*/
304303
struct docg3 {
305304
struct device *dev;
@@ -312,7 +311,6 @@ struct docg3 {
312311
loff_t oob_write_ofs;
313312
int oob_autoecc;
314313
u8 oob_write_buf[DOC_LAYOUT_OOB_SIZE];
315-
struct dentry *debugfs_root;
316314
};
317315

318316
#define doc_err(fmt, arg...) dev_err(docg3->dev, (fmt), ## arg)

drivers/mtd/mtdcore.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <linux/slab.h>
4141
#include <linux/reboot.h>
4242
#include <linux/leds.h>
43+
#include <linux/debugfs.h>
4344

4445
#include <linux/mtd/mtd.h>
4546
#include <linux/mtd/partitions.h>
@@ -477,6 +478,8 @@ int mtd_pairing_groups(struct mtd_info *mtd)
477478
}
478479
EXPORT_SYMBOL_GPL(mtd_pairing_groups);
479480

481+
static struct dentry *dfs_dir_mtd;
482+
480483
/**
481484
* add_mtd_device - register an MTD device
482485
* @mtd: pointer to new MTD device info structure
@@ -552,6 +555,14 @@ int add_mtd_device(struct mtd_info *mtd)
552555
if (error)
553556
goto fail_added;
554557

558+
if (!IS_ERR_OR_NULL(dfs_dir_mtd)) {
559+
mtd->dbg.dfs_dir = debugfs_create_dir(dev_name(&mtd->dev), dfs_dir_mtd);
560+
if (IS_ERR_OR_NULL(mtd->dbg.dfs_dir)) {
561+
pr_debug("mtd device %s won't show data in debugfs\n",
562+
dev_name(&mtd->dev));
563+
}
564+
}
565+
555566
device_create(&mtd_class, mtd->dev.parent, MTD_DEVT(i) + 1, NULL,
556567
"mtd%dro", i);
557568

@@ -594,6 +605,8 @@ int del_mtd_device(struct mtd_info *mtd)
594605

595606
mutex_lock(&mtd_table_mutex);
596607

608+
debugfs_remove_recursive(mtd->dbg.dfs_dir);
609+
597610
if (idr_find(&mtd_idr, mtd->index) != mtd) {
598611
ret = -ENODEV;
599612
goto out_error;
@@ -1811,6 +1824,8 @@ static int __init init_mtd(void)
18111824
if (ret)
18121825
goto out_procfs;
18131826

1827+
dfs_dir_mtd = debugfs_create_dir("mtd", NULL);
1828+
18141829
return 0;
18151830

18161831
out_procfs:
@@ -1826,6 +1841,7 @@ static int __init init_mtd(void)
18261841

18271842
static void __exit cleanup_mtd(void)
18281843
{
1844+
debugfs_remove_recursive(dfs_dir_mtd);
18291845
cleanup_mtdchar();
18301846
if (proc_mtd)
18311847
remove_proc_entry("mtd", NULL);

drivers/mtd/mtdswap.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ struct mtdswap_dev {
138138

139139
char *page_buf;
140140
char *oob_buf;
141-
142-
struct dentry *debugfs_root;
143141
};
144142

145143
struct mtdswap_oobdata {
@@ -1318,26 +1316,19 @@ static int mtdswap_add_debugfs(struct mtdswap_dev *d)
13181316
struct gendisk *gd = d->mbd_dev->disk;
13191317
struct device *dev = disk_to_dev(gd);
13201318

1321-
struct dentry *root;
1319+
struct dentry *root = d->mtd->dbg.dfs_dir;
13221320
struct dentry *dent;
13231321

1324-
root = debugfs_create_dir(gd->disk_name, NULL);
1325-
if (IS_ERR(root))
1322+
if (!IS_ENABLED(CONFIG_DEBUG_FS))
13261323
return 0;
13271324

1328-
if (!root) {
1329-
dev_err(dev, "failed to initialize debugfs\n");
1325+
if (IS_ERR_OR_NULL(root))
13301326
return -1;
1331-
}
1332-
1333-
d->debugfs_root = root;
13341327

1335-
dent = debugfs_create_file("stats", S_IRUSR, root, d,
1328+
dent = debugfs_create_file("mtdswap_stats", S_IRUSR, root, d,
13361329
&mtdswap_fops);
13371330
if (!dent) {
13381331
dev_err(d->dev, "debugfs_create_file failed\n");
1339-
debugfs_remove_recursive(root);
1340-
d->debugfs_root = NULL;
13411332
return -1;
13421333
}
13431334

@@ -1540,7 +1531,6 @@ static void mtdswap_remove_dev(struct mtd_blktrans_dev *dev)
15401531
{
15411532
struct mtdswap_dev *d = MTDSWAP_MBD_TO_MTDSWAP(dev);
15421533

1543-
debugfs_remove_recursive(d->debugfs_root);
15441534
del_mtd_blktrans_dev(dev);
15451535
mtdswap_cleanup(d);
15461536
kfree(d);

drivers/mtd/nand/nandsim.c

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,6 @@ MODULE_PARM_DESC(bch, "Enable BCH ecc and set how many bits should "
287287
/* Maximum page cache pages needed to read or write a NAND page to the cache_file */
288288
#define NS_MAX_HELD_PAGES 16
289289

290-
struct nandsim_debug_info {
291-
struct dentry *dfs_root;
292-
struct dentry *dfs_wear_report;
293-
};
294-
295290
/*
296291
* A union to represent flash memory contents and flash buffer.
297292
*/
@@ -370,8 +365,6 @@ struct nandsim {
370365
void *file_buf;
371366
struct page *held_pages[NS_MAX_HELD_PAGES];
372367
int held_cnt;
373-
374-
struct nandsim_debug_info dbg;
375368
};
376369

377370
/*
@@ -524,39 +517,23 @@ static const struct file_operations dfs_fops = {
524517
*/
525518
static int nandsim_debugfs_create(struct nandsim *dev)
526519
{
527-
struct nandsim_debug_info *dbg = &dev->dbg;
520+
struct dentry *root = nsmtd->dbg.dfs_dir;
528521
struct dentry *dent;
529522

530523
if (!IS_ENABLED(CONFIG_DEBUG_FS))
531524
return 0;
532525

533-
dent = debugfs_create_dir("nandsim", NULL);
534-
if (!dent) {
535-
NS_ERR("cannot create \"nandsim\" debugfs directory\n");
536-
return -ENODEV;
537-
}
538-
dbg->dfs_root = dent;
526+
if (IS_ERR_OR_NULL(root))
527+
return -1;
539528

540-
dent = debugfs_create_file("wear_report", S_IRUSR,
541-
dbg->dfs_root, dev, &dfs_fops);
542-
if (!dent)
543-
goto out_remove;
544-
dbg->dfs_wear_report = dent;
529+
dent = debugfs_create_file("nandsim_wear_report", S_IRUSR,
530+
root, dev, &dfs_fops);
531+
if (IS_ERR_OR_NULL(dent)) {
532+
NS_ERR("cannot create \"nandsim_wear_report\" debugfs entry\n");
533+
return -1;
534+
}
545535

546536
return 0;
547-
548-
out_remove:
549-
debugfs_remove_recursive(dbg->dfs_root);
550-
return -ENODEV;
551-
}
552-
553-
/**
554-
* nandsim_debugfs_remove - destroy all debugfs files
555-
*/
556-
static void nandsim_debugfs_remove(struct nandsim *ns)
557-
{
558-
if (IS_ENABLED(CONFIG_DEBUG_FS))
559-
debugfs_remove_recursive(ns->dbg.dfs_root);
560537
}
561538

562539
/*
@@ -2352,9 +2329,6 @@ static int __init ns_init_module(void)
23522329
if ((retval = setup_wear_reporting(nsmtd)) != 0)
23532330
goto err_exit;
23542331

2355-
if ((retval = nandsim_debugfs_create(nand)) != 0)
2356-
goto err_exit;
2357-
23582332
if ((retval = init_nandsim(nsmtd)) != 0)
23592333
goto err_exit;
23602334

@@ -2370,6 +2344,9 @@ static int __init ns_init_module(void)
23702344
if (retval != 0)
23712345
goto err_exit;
23722346

2347+
if ((retval = nandsim_debugfs_create(nand)) != 0)
2348+
goto err_exit;
2349+
23732350
return 0;
23742351

23752352
err_exit:
@@ -2395,7 +2372,6 @@ static void __exit ns_cleanup_module(void)
23952372
struct nandsim *ns = nand_get_controller_data(chip);
23962373
int i;
23972374

2398-
nandsim_debugfs_remove(ns);
23992375
free_nandsim(ns); /* Free nandsim private resources */
24002376
nand_release(nsmtd); /* Unregister driver */
24012377
for (i = 0;i < ARRAY_SIZE(ns->partitions); ++i)

include/linux/mtd/mtd.h

Lines changed: 10 additions & 0 deletions

0 commit comments

Comments
 (0)