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

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.
---
 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 0967a32319a2..48547d5bb502 100644
--- a/drivers/nvmem/layouts/onie-tlv.c
+++ b/drivers/nvmem/layouts/onie-tlv.c
@@ -197,7 +197,7 @@ static int onie_tlv_parse_table(struct nvmem_layout *layout)
 
 	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);
@@ -205,7 +205,7 @@ static int onie_tlv_parse_table(struct nvmem_layout *layout)
 	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);
@@ -217,7 +217,7 @@ static int onie_tlv_parse_table(struct nvmem_layout *layout)
 		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);
