From 7bf3f5990eae3a692e5956566d9e366186cd1783 Mon Sep 17 00:00:00 2001 From: hailfinger Date: Wed, 10 Nov 2010 03:10:41 +0000 Subject: 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. Signed-off-by: Alex Badea Acked-by: Carl-Daniel Hailfinger git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1228 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 --- ft2232_spi.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'ft2232_spi.c') diff --git a/ft2232_spi.c b/ft2232_spi.c index a2ea2a8..7c2d9b5 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; } -- cgit v1.2.1