Commit 52e3632e authored by Roel Kluin's avatar Roel Kluin Committed by Linus Torvalds

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: default avatarRoel Kluin <roel.kluin@gmail.com>
Acked-by: default avatarDavid S. Miller <davem@davemloft.net>
Acked-by: default avatarMaciej W. Rozycki <macro@linux-mips.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarAlan Cox <alan@linux.intel.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 607c268e
...@@ -204,7 +204,7 @@ static int sbd_receive_drain(struct sbd_port *sport) ...@@ -204,7 +204,7 @@ static int sbd_receive_drain(struct sbd_port *sport)
{ {
int loops = 10000; int loops = 10000;
while (sbd_receive_ready(sport) && loops--) while (sbd_receive_ready(sport) && --loops)
read_sbdchn(sport, R_DUART_RX_HOLD); read_sbdchn(sport, R_DUART_RX_HOLD);
return loops; return loops;
} }
...@@ -218,7 +218,7 @@ static int __maybe_unused sbd_transmit_drain(struct sbd_port *sport) ...@@ -218,7 +218,7 @@ static int __maybe_unused sbd_transmit_drain(struct sbd_port *sport)
{ {
int loops = 10000; int loops = 10000;
while (!sbd_transmit_ready(sport) && loops--) while (!sbd_transmit_ready(sport) && --loops)
udelay(2); udelay(2);
return loops; return loops;
} }
...@@ -232,7 +232,7 @@ static int sbd_line_drain(struct sbd_port *sport) ...@@ -232,7 +232,7 @@ static int sbd_line_drain(struct sbd_port *sport)
{ {
int loops = 10000; int loops = 10000;
while (!sbd_transmit_empty(sport) && loops--) while (!sbd_transmit_empty(sport) && --loops)
udelay(2); udelay(2);
return loops; return loops;
} }
......
...@@ -461,7 +461,7 @@ static void sunhv_console_write_paged(struct console *con, const char *s, unsign ...@@ -461,7 +461,7 @@ static void sunhv_console_write_paged(struct console *con, const char *s, unsign
break; break;
udelay(1); udelay(1);
} }
if (limit <= 0) if (limit < 0)
break; break;
page_bytes -= written; page_bytes -= written;
ra += written; ra += written;
......
...@@ -231,7 +231,7 @@ static int zs_receive_drain(struct zs_port *zport) ...@@ -231,7 +231,7 @@ static int zs_receive_drain(struct zs_port *zport)
{ {
int loops = 10000; int loops = 10000;
while ((read_zsreg(zport, R0) & Rx_CH_AV) && loops--) while ((read_zsreg(zport, R0) & Rx_CH_AV) && --loops)
read_zsdata(zport); read_zsdata(zport);
return loops; return loops;
} }
...@@ -241,7 +241,7 @@ static int zs_transmit_drain(struct zs_port *zport, int irq) ...@@ -241,7 +241,7 @@ static int zs_transmit_drain(struct zs_port *zport, int irq)
struct zs_scc *scc = zport->scc; struct zs_scc *scc = zport->scc;
int loops = 10000; int loops = 10000;
while (!(read_zsreg(zport, R0) & Tx_BUF_EMP) && loops--) { while (!(read_zsreg(zport, R0) & Tx_BUF_EMP) && --loops) {
zs_spin_unlock_cond_irq(&scc->zlock, irq); zs_spin_unlock_cond_irq(&scc->zlock, irq);
udelay(2); udelay(2);
zs_spin_lock_cond_irq(&scc->zlock, irq); zs_spin_lock_cond_irq(&scc->zlock, irq);
...@@ -254,7 +254,7 @@ static int zs_line_drain(struct zs_port *zport, int irq) ...@@ -254,7 +254,7 @@ static int zs_line_drain(struct zs_port *zport, int irq)
struct zs_scc *scc = zport->scc; struct zs_scc *scc = zport->scc;
int loops = 10000; int loops = 10000;
while (!(read_zsreg(zport, R1) & ALL_SNT) && loops--) { while (!(read_zsreg(zport, R1) & ALL_SNT) && --loops) {
zs_spin_unlock_cond_irq(&scc->zlock, irq); zs_spin_unlock_cond_irq(&scc->zlock, irq);
udelay(2); udelay(2);
zs_spin_lock_cond_irq(&scc->zlock, irq); zs_spin_lock_cond_irq(&scc->zlock, irq);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment