Skip to contentSkip to conversation

mtd: core: Handle unsupported OTP operations

PATCH Applied Aapo Vienamo 3 participants 6 messages Mar 13, 2024 – Mar 25, 2024 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

v2 cover mtd: core: Handle unsupported OTP operations

Make MTD core tolerate SPI controllers without OTP support.

These changes address the issue that occurs when an OTP capable SPI NOR device is initialized with the Intel SPI controller. The limited supported opcode set of the SPI controller leads to failure in the OTP initialization, which in turn fails the probe for the MTD device. By allowing the MTD core to tolerate unsupported OTP, the rest of the MTD functionality remains intact even if OTP initialization is unsupported.

v2 changes:
- Move handling of -EOPNOTSUPP to mtd_otp_nvmem_add()
- Omit error message if -EOPNOTSUPP is returned

Aapo Vienamo (2):
mtd: core: Report error if first mtd_otp_size() call fails in

    mtd_otp_nvmem_add()

mtd: core: Don't fail mtd_otp_nvmem_add() if OTP is unsupported

 drivers/mtd/mtdcore.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH v2 1/2 mtd: core: Report error if first mtd_otp_size() call fails in mtd_otp_nvmem_add()

Jump to the error reporting code in mtd_otp_nvmem_add() if the mtd_otp_size() call fails. Without this fix, the error is not logged.

Fixes 4b361cfa8624 ("mtd: core: add OTP nvmem provider support")
---
 drivers/mtd/mtdcore.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/mtd/mtdcore.c +4 -2
index 5887feb347a4..c365c97e7232 100644
@@ -956,8 +956,10 @@ static int mtd_otp_nvmem_add(struct mtd_info *mtd)
 
 	if (mtd->_get_user_prot_info && mtd->_read_user_prot_reg) {
 		size = mtd_otp_size(mtd, true);
-		if (size < 0)
-			return size;
+		if (size < 0) {
+			err = size;
+			goto err;
+		}
 
 		if (size > 0) {
 			nvmem = mtd_otp_nvmem_register(mtd, "user-otp", size,
Signature · 1 line
2.41.0
maintainer Applied
#2 lore raw

Re: [PATCH v2 1/2] mtd: core: Report error if first mtd_otp_size() call fails in mtd_otp_nvmem_add()

Quoted 7 lines · Aapo Vienamo

Jump to the error reporting code in mtd_otp_nvmem_add() if the mtd_otp_size() call fails. Without this fix, the error is not logged.

Fixes 4b361cfa8624 ("mtd: core: add OTP nvmem provider support")

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel

#3 lore raw

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

In reply to Aapo Vienamo

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.

---
 drivers/mtd/mtdcore.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/mtd/mtdcore.c +5 -1
index c365c97e7232..9e18422fdc77 100644
@@ -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;
 }
 
 /**
Signature · 1 line
2.41.0
Reviewed-by on v2 2/2
#4 lore raw

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

Quoted 10 lines · Aapo Vienamo

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.

Quoted 2 lines

-michael

maintainer Applied
#5 lore raw

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

In reply to Aapo Vienamo
Quoted 10 lines · Aapo Vienamo

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.

Quoted 3 lines

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel