Fix eeprom decoding of BM chip type: The previous code resulted in a temporary 1...
[libftdi] / src / ftdi.c
index e0c9213..c62ede7 100644 (file)
@@ -1954,7 +1954,8 @@ int ftdi_eeprom_decode(struct ftdi_eeprom *eeprom, unsigned char *buf, int size)
     // Addr 04: Product ID
     eeprom->product_id = buf[0x04] + (buf[0x05] << 8);
 
-    switch (buf[0x06] + (buf[0x07]<<8))
+    value = buf[0x06] + (buf[0x07]<<8);
+    switch (value)
     {
         case 0x0400:
             eeprom->BM_type_chip = 1;
@@ -2183,12 +2184,15 @@ int ftdi_read_eeprom_getsize(struct ftdi_context *ftdi, unsigned char *eeprom, i
 int ftdi_write_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom)
 {
     unsigned short usb_val, status;
-    int i;
+    int i, ret;
 
     /* These commands were traced while running MProg */
-    ftdi_usb_reset(ftdi);
-    ftdi_poll_modem_status(ftdi, &status);
-    ftdi_set_latency_timer(ftdi, 0x77);
+    if ((ret = ftdi_usb_reset(ftdi)) != 0)
+        return ret;
+    if ((ret = ftdi_poll_modem_status(ftdi, &status)) != 0)
+        return ret;
+    if ((ret = ftdi_set_latency_timer(ftdi, 0x77)) != 0)
+        return ret;
 
     for (i = 0; i < ftdi->eeprom_size/2; i++)
     {