On 4/29/23 11:15, Josua Mayer wrote:
When tlv eeprom does not exist, return error code instead of quietly
making up tlv structure in memory.

Signed-off-by: Josua Mayer <jo...@solid-run.com>
Cc: Stefan Roese <s...@denx.de>
Cc: Baruch Siach <bar...@tkos.co.il>
Cc: Heinrich Schuchardt <xypron.g...@gmx.de>

Reviewed-by: Stefan Roese <s...@denx.de>

Thanks,
Stefan

---
  cmd/tlv_eeprom.c | 22 ++++++++++++++++------
  1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/cmd/tlv_eeprom.c b/cmd/tlv_eeprom.c
index d36401e9138..636c1fe32ef 100644
--- a/cmd/tlv_eeprom.c
+++ b/cmd/tlv_eeprom.c
@@ -134,6 +134,8 @@ static int read_eeprom(int devnum, u8 *eeprom)
        if (ret == 0 && is_valid_tlvinfo_header(eeprom_hdr))
                ret = read_tlv_eeprom((void *)eeprom_tlv, HDR_SIZE,
                                      be16_to_cpu(eeprom_hdr->totallen), 
devnum);
+       else if (ret == -ENODEV)
+               return ret;
// If the contents are invalid, start over with default contents
        if (!is_valid_tlvinfo_header(eeprom_hdr) ||
@@ -432,8 +434,13 @@ int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
        // If no arguments, read the EERPOM and display its contents
        if (argc == 1) {
                if (!has_been_read) {
-                       if (read_eeprom(current_dev, eeprom) == 0)
-                               has_been_read = 1;
+                       ret = read_eeprom(current_dev, eeprom);
+                       if (ret) {
+                               printf("Failed to read EEPROM data from 
device.\n");
+                               return 0;
+                       }
+
+                       has_been_read = 1;
                }
                show_eeprom(current_dev, eeprom);
                return 0;
@@ -446,11 +453,14 @@ int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
        // Read the EEPROM contents
        if (cmd == 'r') {
                has_been_read = 0;
-               if (read_eeprom(current_dev, eeprom) == 0) {
-                       printf("EEPROM data loaded from device to memory.\n");
-                       has_been_read = 1;
+               ret = read_eeprom(current_dev, eeprom);
+               if (ret) {
+                       printf("Failed to read EEPROM data from device.\n");
+                       return 0;
                }
-               return 0;
+
+               printf("EEPROM data loaded from device to memory.\n");
+               has_been_read = 1;
        }
// Subsequent commands require that the EEPROM has already been read.

Viele Grüße,
Stefan Roese

--
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: s...@denx.de

Reply via email to