[PATCH v2 2/2] mtd: core: Don't fail mtd_otp_nvmem_add() if OTP is unsupported

From: Aapo Vienamo
Date: Wed Mar 13 2024 - 14:43:28 EST


Handle the case where -EOPNOTSUPP is returned from OTP driver.

This addresses an issue that occurs with the Intel SPI flash controller,
which has a limited supported opcode set. Whilst the OTP functionality
is not available due to this restriction, other parts of the MTD
functionality of the device are intact. This change allows the driver
to gracefully handle the restriction by allowing the supported
functionality to remain available instead of failing the probe
altogether.

Signed-off-by: Aapo Vienamo <aapo.vienamo@xxxxxxxxxxxxxxx>
Reviewed-by: Mika Westerberg <mika.westerberg@xxxxxxxxxxxxxxx>
---
drivers/mtd/mtdcore.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index c365c97e7232..9e18422fdc77 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1014,7 +1014,11 @@ static int mtd_otp_nvmem_add(struct mtd_info *mtd)

err:
nvmem_unregister(mtd->otp_user_nvmem);
- return dev_err_probe(dev, err, "Failed to register OTP NVMEM device\n");
+ /* Don't report error if OTP is not supported. */
+ if (err != -EOPNOTSUPP)
+ return dev_err_probe(dev, err,
+ "Failed to register OTP NVMEM device\n");
+ return 0;
}

/**
--
2.41.0