[PATCH] mtd: Fix error handling in mtd_device_parse_register() error path
Wentao Liang
vulab at iscas.ac.cn
Mon Mar 3 06:52:23 PST 2025
Check and log del_mtd_device() failures. Print an error message
with pr_err() to prevent silent failures, but preserve the original
error code instead of propagating the secondary error since
del_mtd_device() is already in an error handling path.
Signed-off-by: Wentao Liang <vulab at iscas.ac.cn>
---
drivers/mtd/mtdcore.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 724f917f91ba..a7b01ed37f42 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1053,7 +1053,7 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
const struct mtd_partition *parts,
int nr_parts)
{
- int ret;
+ int ret, err;
mtd_set_dev_defaults(mtd);
@@ -1105,8 +1105,11 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
nvmem_unregister(mtd->otp_factory_nvmem);
}
- if (ret && device_is_registered(&mtd->dev))
- del_mtd_device(mtd);
+ if (ret && device_is_registered(&mtd->dev)) {
+ err = del_mtd_device(mtd);
+ if (err)
+ pr_err("Error when deleting MTD device (%d)\n", err);
+ }
return ret;
}
--
2.42.0.windows.2
More information about the linux-mtd
mailing list