It's possible that ftdi_read_data() returns less data
than requested.  Catch this case and retry reading the rest
of the buffer.

Signed-off-by: Alex Badea <[email protected]>
---
 ft2232_spi.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/ft2232_spi.c b/ft2232_spi.c
index 84a70de..0f9bc79 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -114,11 +114,16 @@ static int get_buf(struct ftdi_context *ftdic, const 
unsigned char *buf,
                   int size)
 {
        int r;
-       r = ftdi_read_data(ftdic, (unsigned char *) buf, size);
-       if (r < 0) {
-               msg_perr("ftdi_read_data: %d, %s\n", r,
-                               ftdi_get_error_string(ftdic));
-               return 1;
+
+       while (size > 0) {
+               r = ftdi_read_data(ftdic, (unsigned char *) buf, size);
+               if (r < 0) {
+                       msg_perr("ftdi_read_data: %d, %s\n", r,
+                                       ftdi_get_error_string(ftdic));
+                       return 1;
+               }
+               buf += r;
+               size -= r;
        }
        return 0;
 }
-- 
1.7.0.4


_______________________________________________
flashrom mailing list
[email protected]
http://www.flashrom.org/mailman/listinfo/flashrom

Reply via email to