1 From e0489f6e221f5ddee6cb3bd51b992b790c5fa4b9 Mon Sep 17 00:00:00 2001
2 From: Michael Walle <michael@walle.cc>
3 Date: Wed, 8 Mar 2023 09:20:20 +0100
4 Subject: [PATCH] mtd: core: fix error path for nvmem provider
6 If mtd_otp_nvmem_add() fails, the partitions won't be removed
7 because there is simply no call to del_mtd_partitions().
8 Unfortunately, add_mtd_partitions() will print all partitions to
9 the kernel console. If mtd_otp_nvmem_add() returns -EPROBE_DEFER
10 this would print the partitions multiple times to the kernel
11 console. Instead move mtd_otp_nvmem_add() to the beginning of the
14 Fixes: 4b361cfa8624 ("mtd: core: add OTP nvmem provider support")
15 Cc: stable@vger.kernel.org
16 Signed-off-by: Michael Walle <michael@walle.cc>
17 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
18 Link: https://lore.kernel.org/linux-mtd/20230308082021.870459-3-michael@walle.cc
20 drivers/mtd/mtdcore.c | 13 ++++++++++---
21 1 file changed, 10 insertions(+), 3 deletions(-)
23 --- a/drivers/mtd/mtdcore.c
24 +++ b/drivers/mtd/mtdcore.c
25 @@ -1031,10 +1031,14 @@ int mtd_device_parse_register(struct mtd
27 mtd_set_dev_defaults(mtd);
29 + ret = mtd_otp_nvmem_add(mtd);
33 if (IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)) {
34 ret = add_mtd_device(mtd);
40 /* Prefer parsed partitions over driver-provided fallback */
41 @@ -1069,9 +1073,12 @@ int mtd_device_parse_register(struct mtd
42 register_reboot_notifier(&mtd->reboot_notifier);
45 - ret = mtd_otp_nvmem_add(mtd);
49 + nvmem_unregister(mtd->otp_user_nvmem);
50 + nvmem_unregister(mtd->otp_factory_nvmem);
53 if (ret && device_is_registered(&mtd->dev))