[flashrom] [PATCH 4/5] ft2232_spi: retry short reads
Alex Badea
vamposdecampos at gmail.com
Sat Oct 16 14:20:56 CEST 2010
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 <vamposdecampos at gmail.com>
---
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
More information about the flashrom
mailing list