Skip to contentSkip to conversation

mtd: core: don't remove debugfs directory if device is in use

PATCH Applied Zev Weiss 2 participants 2 messages Oct 14, 2021 – Oct 15, 2021 Memory technology devices (MTD)

lore
Share & tools
lore

Zev Weiss

author
#0 lore raw

PATCH 1/1 mtd: core: don't remove debugfs directory if device is in use

Previously, if del_mtd_device() failed with -EBUSY due to a non-zero usecount, a subsequent call to attempt the deletion again would try to remove a debugfs directory that had already been removed and panic. With this change the second call can instead proceed safely.

Fixes e8e3edb95ce6 ("mtd: create per-device and module-scope debugfs entries")
---
 drivers/mtd/mtdcore.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/mtdcore.c +2 -2
index e22266f63ae9..0a0fca737d43 100644
@@ -724,8 +724,6 @@ int del_mtd_device(struct mtd_info *mtd)
 
 	mutex_lock(&mtd_table_mutex);
 
-	debugfs_remove_recursive(mtd->dbg.dfs_dir);
-
 	if (idr_find(&mtd_idr, mtd->index) != mtd) {
 		ret = -ENODEV;
 		goto out_error;
@@ -741,6 +739,8 @@ int del_mtd_device(struct mtd_info *mtd)
 		       mtd->index, mtd->name, mtd->usecount);
 		ret = -EBUSY;
 	} else {
+		debugfs_remove_recursive(mtd->dbg.dfs_dir);
+
 		/* Try to remove the NVMEM provider */
 		if (mtd->nvmem)
 			nvmem_unregister(mtd->nvmem);
Signature · 1 line
2.33.0
maintainer Applied
#1 lore raw
Quoted 7 lines · Zev Weiss

Previously, if del_mtd_device() failed with -EBUSY due to a non-zero usecount, a subsequent call to attempt the deletion again would try to remove a debugfs directory that had already been removed and panic. With this change the second call can instead proceed safely.

Fixes e8e3edb95ce6 ("mtd: create per-device and module-scope debugfs entries")

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel