diff options
author | stefanct <stefanct@2b7e53f0-3cfb-0310-b3e9-8179ed1497e1> | 2012-11-30 16:46:41 +0000 |
---|---|---|
committer | stefanct <stefanct@2b7e53f0-3cfb-0310-b3e9-8179ed1497e1> | 2012-11-30 16:46:41 +0000 |
commit | 34f616b534b9e812c3fddffd54b5f76abe8a7d59 (patch) | |
tree | 788120efb7d40c50991b226181d1b1896adf07cb /serial.c | |
parent | 2d990d443b58a9d996149036eb1e9c7e5e116697 (diff) | |
download | flashrom-34f616b534b9e812c3fddffd54b5f76abe8a7d59.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.
Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at>
Acked-by: Idwer Vollering <vidwer@gmail.com>
git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1626 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'serial.c')
-rw-r--r-- | serial.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -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; } |