Skip to content
Snippets Groups Projects
Commit 62574aa5 authored by Stefan Tauner's avatar Stefan Tauner
Browse files

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: default avatarStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Acked-by: default avatarIdwer Vollering <vidwer@gmail.com>
parent 26148ae3
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment