Skip to content

Commit e0489f6

Browse files
mwallemiquelraynal
authored andcommitted
mtd: core: fix error path for nvmem provider
If mtd_otp_nvmem_add() fails, the partitions won't be removed because there is simply no call to del_mtd_partitions(). Unfortunately, add_mtd_partitions() will print all partitions to the kernel console. If mtd_otp_nvmem_add() returns -EPROBE_DEFER this would print the partitions multiple times to the kernel console. Instead move mtd_otp_nvmem_add() to the beginning of the function. Fixes: 4b361cf ("mtd: core: add OTP nvmem provider support") Cc: stable@vger.kernel.org Signed-off-by: Michael Walle <michael@walle.cc> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/20230308082021.870459-3-michael@walle.cc
1 parent 8bd1d24 commit e0489f6

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

drivers/mtd/mtdcore.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,10 +1023,14 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
10231023

10241024
mtd_set_dev_defaults(mtd);
10251025

1026+
ret = mtd_otp_nvmem_add(mtd);
1027+
if (ret)
1028+
goto out;
1029+
10261030
if (IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)) {
10271031
ret = add_mtd_device(mtd);
10281032
if (ret)
1029-
return ret;
1033+
goto out;
10301034
}
10311035

10321036
/* Prefer parsed partitions over driver-provided fallback */
@@ -1061,9 +1065,12 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
10611065
register_reboot_notifier(&mtd->reboot_notifier);
10621066
}
10631067

1064-
ret = mtd_otp_nvmem_add(mtd);
1065-
10661068
out:
1069+
if (ret) {
1070+
nvmem_unregister(mtd->otp_user_nvmem);
1071+
nvmem_unregister(mtd->otp_factory_nvmem);
1072+
}
1073+
10671074
if (ret && device_is_registered(&mtd->dev))
10681075
del_mtd_device(mtd);
10691076

0 commit comments

Comments
 (0)