Skip to content

Commit

Permalink
mtd: core: don't remove debugfs directory if device is in use
Browse files Browse the repository at this point in the history
[ Upstream commit c13de23 ]

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: e8e3edb ("mtd: create per-device and module-scope debugfs entries")
Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20211014203953.5424-1-zev@bewilderbeest.net
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
zevweiss authored and gregkh committed Nov 17, 2021
1 parent f3ecfa9 commit c0bd86c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/mtd/mtdcore.c
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit c0bd86c

Please sign in to comment.