From b9556e0fd4ab189b5d9dcb86b2bdbf8e5c584db7 Mon Sep 17 00:00:00 2001 From: Alex Badea Date: Wed, 10 Nov 2010 03:10:41 +0000 Subject: [PATCH] Retry short reads in ft2232_spi It is possible that ftdi_read_data() returns less data than requested. Catch this case and retry reading the rest of the buffer. Corresponding to flashrom svn r1228. Signed-off-by: Alex Badea Acked-by: Carl-Daniel Hailfinger --- ft2232_spi.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ft2232_spi.c b/ft2232_spi.c index a2ea2a8d5..7c2d9b51b 100644 --- a/ft2232_spi.c +++ b/ft2232_spi.c @@ -108,11 +108,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; }