summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2012-11-30 16:46:41 +0000
committerStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2012-11-30 16:46:41 +0000
commit62574aa5c0bf0df43a2ed0182562f17f30825f0d (patch)
tree788120efb7d40c50991b226181d1b1896adf07cb
parent26148ae3a881a2323ef130427ee8749a2ab53c9e (diff)
downloadast2050-flashrom-62574aa5c0bf0df43a2ed0182562f17f30825f0d.zip
ast2050-flashrom-62574aa5c0bf0df43a2ed0182562f17f30825f0d.tar.gz
Break endless loop in serialport_write()
Serialport_write could loop endlessly when used with a seemingly valid port that does always return 0 on writes instead of an error. Give up after about 125 ms i.e. 250 tries with a period of 500 us. Corresponding to flashrom svn r1626. Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Idwer Vollering <vidwer@gmail.com>
-rw-r--r--serial.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/serial.c b/serial.c
index 7e47dcc..9446ce3 100644
--- a/serial.c
+++ b/serial.c
@@ -262,6 +262,7 @@ int serialport_write(unsigned char *buf, unsigned int writecnt)
#else
ssize_t tmp = 0;
#endif
+ unsigned int empty_writes = 250; /* results in a ca. 125ms timeout */
while (writecnt > 0) {
#ifdef _WIN32
@@ -273,9 +274,16 @@ int serialport_write(unsigned char *buf, unsigned int writecnt)
msg_perr("Serial port write error!\n");
return 1;
}
- if (!tmp)
- msg_pdbg("Empty write\n");
- writecnt -= tmp;
+ if (!tmp) {
+ msg_pdbg2("Empty write\n");
+ empty_writes--;
+ programmer_delay(500);
+ if (empty_writes == 0) {
+ msg_perr("Serial port is unresponsive!\n");
+ return 1;
+ }
+ }
+ writecnt -= tmp;
buf += tmp;
}
OpenPOWER on IntegriCloud