Patchwork [4/5] ft2232_spi: retry short reads

login
register
about
Submitter Alex Badea
Date 2010-10-16 12:20:56
Message ID <1287231657-16981-5-git-send-email-vamposdecampos@gmail.com>
Download mbox | patch
Permalink /patch/2123/
State Accepted
Commit r1228
Headers show

Comments

Alex Badea - 2010-10-16 12:20:56
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@gmail.com>
---
 ft2232_spi.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)
Carl-Daniel Hailfinger - 2010-11-10 03:11:17
On 16.10.2010 14:20, Alex Badea wrote:
> 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@gmail.com>
>   

Thanks for spotting and fixing this bug!
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
and committed in r1228.

Regards,
Carl-Daniel

Patch

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;
 }