Author: stefanct Date: Fri Nov 30 17:46:41 2012 New Revision: 1626 URL: http://flashrom.org/trac/flashrom/changeset/1626
Log: 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.
Signed-off-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at Acked-by: Idwer Vollering vidwer@gmail.com
Modified: trunk/serial.c
Modified: trunk/serial.c ============================================================================== --- trunk/serial.c Thu Nov 29 23:22:04 2012 (r1625) +++ trunk/serial.c Fri Nov 30 17:46:41 2012 (r1626) @@ -262,6 +262,7 @@ #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 @@ 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; }