From dd693e037f0dd799e77af397b4d23190b66e9cf1 Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Fri, 24 Nov 2023 23:29:55 +0100
Subject: [PATCH 17/17] nvmem: layouts: onie-tlv: Let device probe even when
 TLV is invalid

Before this change, probing an NVMEM device, expected to contain a
valid TLV, would fail if it had not been provisioned yet. But an
obvious way of provisioning is to write the TLV to the nvmem
attribute, which would not be possible because the device would not
be successfully probed.

Therefore, settle for reporting data corruption issues in the log, and
simply refrain from registering any cells in those cases.

Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
---
 drivers/nvmem/layouts/onie-tlv.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/nvmem/layouts/onie-tlv.c b/drivers/nvmem/layouts/onie-tlv.c
index 59fc87ccfcff..834c46e46d0a 100644
--- a/drivers/nvmem/layouts/onie-tlv.c
+++ b/drivers/nvmem/layouts/onie-tlv.c
@@ -196,7 +196,7 @@ static int onie_tlv_parse_table(struct device *dev, struct nvmem_device *nvmem,
 
 	if (!onie_tlv_hdr_is_valid(dev, &hdr)) {
 		dev_err(dev, "Invalid ONIE TLV header\n");
-		return -EINVAL;
+		return 0;
 	}
 
 	hdr_len = sizeof(hdr.id) + sizeof(hdr.version) + sizeof(hdr.data_len);
@@ -204,7 +204,7 @@ static int onie_tlv_parse_table(struct device *dev, struct nvmem_device *nvmem,
 	table_len = hdr_len + data_len;
 	if (table_len > ONIE_TLV_MAX_LEN) {
 		dev_err(dev, "Invalid ONIE TLV data length\n");
-		return -EINVAL;
+		return 0;
 	}
 
 	table = devm_kmalloc(dev, table_len, GFP_KERNEL);
@@ -216,7 +216,7 @@ static int onie_tlv_parse_table(struct device *dev, struct nvmem_device *nvmem,
 		return ret;
 
 	if (!onie_tlv_crc_is_valid(dev, table_len, table))
-		return -EINVAL;
+		return 0;
 
 	data = table + hdr_len;
 	ret = onie_tlv_add_cells(dev, nvmem, data_len, data);
-- 
2.34.1

