NSH USB Console: Add logic to restart the console wait if an error occurs while reading from the console. In USB console startup, the logic must be able to open the USB serial and receive 3 newlines. However, it the USB driver is disconnected or otherwise fails before the 3 newlines are received, the receive loop becomes a killer, infinite loop, CPU hog. Noted by spasbyspas

This commit is contained in:
Gregory Nutt 2014-11-16 06:48:46 -06:00
parent be98711f33
commit 4542091dac

View File

@ -176,6 +176,8 @@ static int nsh_waitusbready(void)
* host-side application opens the connection.
*/
restart:
/* Open the USB serial device for read/write access */
do
@ -225,6 +227,17 @@ static int nsh_waitusbready(void)
/* No.. Reset the count. We need to see 3 in a row to continue. */
nlc = 0;
/* If a read error occurred (nbytes < 0) or an end-of-file was
* encountered (nbytes == 0), then close the driver and start
* over.
*/
if (nbytes <= 0)
{
(void)close(fd);
goto restart;
}
}
}
while (nlc < 3);