]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mtd: mtdswap: remove debugfs stats file on teardown
authorPengpeng Hou <pengpeng@iscas.ac.cn>
Tue, 23 Jun 2026 01:53:17 +0000 (09:53 +0800)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Mon, 29 Jun 2026 14:52:26 +0000 (16:52 +0200)
mtdswap_add_debugfs() creates an mtdswap_stats debugfs file under the
per-MTD debugfs directory, but mtdswap_remove_dev() never removes it
before freeing the mtdswap_dev.

Store the returned dentry and remove it during device teardown before the
driver-private state is freed.

Fixes: a32159024620 ("mtd: Add mtdswap block driver")
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
drivers/mtd/mtdswap.c

index 866933fc84265dafb1a0031e81ea060a5767eb8e..f33f753f0a9fda38cf52668052cb1c3060fcea8c 100644 (file)
@@ -125,6 +125,7 @@ struct mtdswap_dev {
 
        char *page_buf;
        char *oob_buf;
+       struct dentry *debugfs_stats;
 };
 
 struct mtdswap_oobdata {
@@ -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,7 @@ static void mtdswap_remove_dev(struct mtd_blktrans_dev *dev)
 {
        struct mtdswap_dev *d = MTDSWAP_MBD_TO_MTDSWAP(dev);
 
+       debugfs_remove(d->debugfs_stats);
        del_mtd_blktrans_dev(dev);
        mtdswap_cleanup(d);
        kfree(d);