[PATCH] mtd: mtdswap: remove debugfs stats file on teardown
From: Pengpeng Hou
Date: Mon Jun 15 2026 - 05:13:47 EST
mtdswap_add_debugfs() publishes mtdswap_stats with struct mtdswap_dev as
its private data. mtdswap_remove_dev() deletes the block translation
device and frees that private data, but it does not remove the debugfs
file.
Keep the debugfs dentry and remove it before freeing the mtdswap device
state.
Signed-off-by: Pengpeng Hou <pengpeng@xxxxxxxxxxx>
---
drivers/mtd/mtdswap.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c
index 866933fc8426..844d75ba05f3 100644
--- a/drivers/mtd/mtdswap.c
+++ b/drivers/mtd/mtdswap.c
@@ -101,6 +101,7 @@ struct mtdswap_dev {
struct mtd_blktrans_dev *mbd_dev;
struct mtd_info *mtd;
struct device *dev;
+ struct dentry *debugfs_stats;
unsigned int *page_data;
unsigned int *revmap;
@@ -1262,7 +1263,8 @@ static int mtdswap_add_debugfs(struct mtdswap_dev *d)
if (IS_ERR_OR_NULL(root))
return -1;
- debugfs_create_file("mtdswap_stats", S_IRUSR, root, d, &mtdswap_fops);
+ d->debugfs_stats = debugfs_create_file("mtdswap_stats", 0400,
+ root, d, &mtdswap_fops);
return 0;
}
@@ -1463,6 +1465,8 @@ static void mtdswap_remove_dev(struct mtd_blktrans_dev *dev)
{
struct mtdswap_dev *d = MTDSWAP_MBD_TO_MTDSWAP(dev);
+ if (!IS_ERR_OR_NULL(d->debugfs_stats))
+ debugfs_remove(d->debugfs_stats);
del_mtd_blktrans_dev(dev);
mtdswap_cleanup(d);
kfree(d);
--
2.50.1 (Apple Git-155)