aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-01-14 12:11:30 -0500
committerKevin O'Connor <kevin@koconnor.net>2017-01-14 12:11:30 -0500
commit262ccbcf302f8dae0baccd1747406b18be7cd60e (patch)
tree61b66ac924b1c2fdb27e75e68ba6ee3ce89ef418
parent756788511529b9da651c5f0af29251f83c5a2cd2 (diff)
downloadkutter-262ccbcf302f8dae0baccd1747406b18be7cd60e.tar.gz
kutter-262ccbcf302f8dae0baccd1747406b18be7cd60e.tar.xz
kutter-262ccbcf302f8dae0baccd1747406b18be7cd60e.zip
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>
-rw-r--r--src/avr/serial.c2
-rw-r--r--src/sam3x8e/serial.c2
2 files changed, 2 insertions, 2 deletions
diff --git a/src/avr/serial.c b/src/avr/serial.c
index 8c0da553..0b5fea1f 100644
--- a/src/avr/serial.c
+++ b/src/avr/serial.c
@@ -115,7 +115,7 @@ char *
console_get_output(uint8_t len)
{
uint8_t tpos = readb(&transmit_pos), tmax = readb(&transmit_max);
- if (tpos == tmax) {
+ if (tpos >= tmax) {
tpos = tmax = 0;
writeb(&transmit_max, 0);
writeb(&transmit_pos, 0);
diff --git a/src/sam3x8e/serial.c b/src/sam3x8e/serial.c
index 35a7d35c..a14f97fb 100644
--- a/src/sam3x8e/serial.c
+++ b/src/sam3x8e/serial.c
@@ -120,7 +120,7 @@ char *
console_get_output(uint8_t len)
{
uint32_t tpos = readb(&transmit_pos), tmax = readb(&transmit_max);
- if (tpos == tmax) {
+ if (tpos >= tmax) {
tpos = tmax = 0;
writeb(&transmit_max, 0);
writeb(&transmit_pos, 0);