tlv_eeprom: delete old key before updating if it already exists
authorHugo Villeneuve <hvilleneuve@dimonoff.com>
Wed, 5 Nov 2025 17:09:58 +0000 (12:09 -0500)
committerHugo Villeneuve <hvilleneuve@dimonoff.com>
Mon, 17 Nov 2025 15:36:11 +0000 (10:36 -0500)
Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
src/tlv_eeprom.c

index a1a5d96..967e6dd 100644 (file)
@@ -472,6 +472,15 @@ bool tlvinfo_add_tlv(u8 *eeprom, int tcode, char *strval)
        u32 value;
        char data[MAX_TLV_VALUE_LEN];
        int eeprom_index;
+       int ret;
+
+       /* First check if an existing key exist: */
+       if (tlvinfo_find_tlv(eeprom, tcode, &eeprom_index)) {
+               /* If yes, delete old key first (update mode) : */
+               ret = tlvinfo_delete_tlv(eeprom, tcode);
+               if (!ret)
+                       return false;
+       }
 
        // Encode each TLV type into the format to be stored in the EEPROM
        switch (tcode) {