serial: Be careful with comparison of transmit_max to transmit_pos

There is a small possibility that a shutdown could occur between
clearing transmit_max and clearing transmit_pos - so make sure to
handle the case where transmit_pos > transmit_max.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-01-14 12:11:30 -05:00
parent 7567885115
commit 262ccbcf30
2 changed files with 2 additions and 2 deletions

View File

@ -115,7 +115,7 @@ char *
console_get_output(uint8_t len) console_get_output(uint8_t len)
{ {
uint8_t tpos = readb(&transmit_pos), tmax = readb(&transmit_max); uint8_t tpos = readb(&transmit_pos), tmax = readb(&transmit_max);
if (tpos == tmax) { if (tpos >= tmax) {
tpos = tmax = 0; tpos = tmax = 0;
writeb(&transmit_max, 0); writeb(&transmit_max, 0);
writeb(&transmit_pos, 0); writeb(&transmit_pos, 0);

View File

@ -120,7 +120,7 @@ char *
console_get_output(uint8_t len) console_get_output(uint8_t len)
{ {
uint32_t tpos = readb(&transmit_pos), tmax = readb(&transmit_max); uint32_t tpos = readb(&transmit_pos), tmax = readb(&transmit_max);
if (tpos == tmax) { if (tpos >= tmax) {
tpos = tmax = 0; tpos = tmax = 0;
writeb(&transmit_max, 0); writeb(&transmit_max, 0);
writeb(&transmit_pos, 0); writeb(&transmit_pos, 0);