mtd: Fix error handling in mtd_device_parse_register() error path
authorWentao Liang <vulab@iscas.ac.cn>
Mon, 3 Mar 2025 14:52:23 +0000 (22:52 +0800)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Tue, 4 Mar 2025 11:07:30 +0000 (12:07 +0100)
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@iscas.ac.cn>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
drivers/mtd/mtdcore.c

index b80d5098d27687da624744bf2f854e5de3048012..5ba9a741f5ac3c297ae21329c2827baf5dc471f0 100644 (file)
@@ -1056,7 +1056,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);
 
@@ -1108,8 +1108,11 @@ out:
                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;
 }