diff options
author | Roel Kluin <roel.kluin@gmail.com> | 2009-06-22 13:41:56 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-06-22 14:32:23 -0400 |
commit | 52e3632ea603ef92757d5d0dedcd9fc8643445e3 (patch) | |
tree | 8ab96a99d898ada201b55ccb30fe7c0e6a10170f /drivers/serial/sb1250-duart.c | |
parent | 607c268ef9a4675287e77f732071e426e62c2d86 (diff) |
serial: fix off by one errors
In zs_console_putchar() occurs:
if (zs_transmit_drain(zport, irq))
write_zsdata(zport, ch);
However if in zs_transmit_drain() no empty Tx Buffer occurs, limit reaches
-1 => true, and the write still occurs.
This patch changes postfix to prefix decrements in this and similar
functions to prevent similar mistakes in the future. This decreases the
iterations with one but the chosen loop count was arbitrary anyway.
In sunhv limit reaches -1, not 0, so the test is off by one.
Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Acked-by: David S. Miller <davem@davemloft.net>
Acked-by: Maciej W. Rozycki <macro@linux-mips.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/serial/sb1250-duart.c')
-rw-r--r-- | drivers/serial/sb1250-duart.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/serial/sb1250-duart.c b/drivers/serial/sb1250-duart.c index a4fb343a08da..319e8b83f6be 100644 --- a/drivers/serial/sb1250-duart.c +++ b/drivers/serial/sb1250-duart.c | |||
@@ -204,7 +204,7 @@ static int sbd_receive_drain(struct sbd_port *sport) | |||
204 | { | 204 | { |
205 | int loops = 10000; | 205 | int loops = 10000; |
206 | 206 | ||
207 | while (sbd_receive_ready(sport) && loops--) | 207 | while (sbd_receive_ready(sport) && --loops) |
208 | read_sbdchn(sport, R_DUART_RX_HOLD); | 208 | read_sbdchn(sport, R_DUART_RX_HOLD); |
209 | return loops; | 209 | return loops; |
210 | } | 210 | } |
@@ -218,7 +218,7 @@ static int __maybe_unused sbd_transmit_drain(struct sbd_port *sport) | |||
218 | { | 218 | { |
219 | int loops = 10000; | 219 | int loops = 10000; |
220 | 220 | ||
221 | while (!sbd_transmit_ready(sport) && loops--) | 221 | while (!sbd_transmit_ready(sport) && --loops) |
222 | udelay(2); | 222 | udelay(2); |
223 | return loops; | 223 | return loops; |
224 | } | 224 | } |
@@ -232,7 +232,7 @@ static int sbd_line_drain(struct sbd_port *sport) | |||
232 | { | 232 | { |
233 | int loops = 10000; | 233 | int loops = 10000; |
234 | 234 | ||
235 | while (!sbd_transmit_empty(sport) && loops--) | 235 | while (!sbd_transmit_empty(sport) && --loops) |
236 | udelay(2); | 236 | udelay(2); |
237 | return loops; | 237 | return loops; |
238 | } | 238 | } |