* [PATCH] serial: off by one
@ 2009-06-03 23:20 Roel Kluin
2009-06-04 4:18 ` David Miller
2009-06-04 12:04 ` Maciej W. Rozycki
0 siblings, 2 replies; 3+ messages in thread
From: Roel Kluin @ 2009-06-03 23:20 UTC (permalink / raw)
To: davem, macro; +Cc: lkml, Andrew Morton
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>
---
drivers/serial/sb1250-duart.c | 6 +++---
drivers/serial/sunhv.c | 2 +-
drivers/serial/zs.c | 6 +++---
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/serial/sb1250-duart.c b/drivers/serial/sb1250-duart.c
index a4fb343..319e8b8 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)
{
int loops = 10000;
- while (sbd_receive_ready(sport) && loops--)
+ while (sbd_receive_ready(sport) && --loops)
read_sbdchn(sport, R_DUART_RX_HOLD);
return loops;
}
@@ -218,7 +218,7 @@ static int __maybe_unused sbd_transmit_drain(struct sbd_port *sport)
{
int loops = 10000;
- while (!sbd_transmit_ready(sport) && loops--)
+ while (!sbd_transmit_ready(sport) && --loops)
udelay(2);
return loops;
}
@@ -232,7 +232,7 @@ static int sbd_line_drain(struct sbd_port *sport)
{
int loops = 10000;
- while (!sbd_transmit_empty(sport) && loops--)
+ while (!sbd_transmit_empty(sport) && --loops)
udelay(2);
return loops;
}
diff --git a/drivers/serial/sunhv.c b/drivers/serial/sunhv.c
index a94a2ab..1df5325 100644
--- a/drivers/serial/sunhv.c
+++ b/drivers/serial/sunhv.c
@@ -461,7 +461,7 @@ static void sunhv_console_write_paged(struct console *con, const char *s, unsign
break;
udelay(1);
}
- if (limit <= 0)
+ if (limit < 0)
break;
page_bytes -= written;
ra += written;
diff --git a/drivers/serial/zs.c b/drivers/serial/zs.c
index 9e6a873..d8c2809 100644
--- a/drivers/serial/zs.c
+++ b/drivers/serial/zs.c
@@ -231,7 +231,7 @@ static int zs_receive_drain(struct zs_port *zport)
{
int loops = 10000;
- while ((read_zsreg(zport, R0) & Rx_CH_AV) && loops--)
+ while ((read_zsreg(zport, R0) & Rx_CH_AV) && --loops)
read_zsdata(zport);
return loops;
}
@@ -241,7 +241,7 @@ static int zs_transmit_drain(struct zs_port *zport, int irq)
struct zs_scc *scc = zport->scc;
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);
udelay(2);
zs_spin_lock_cond_irq(&scc->zlock, irq);
@@ -254,7 +254,7 @@ static int zs_line_drain(struct zs_port *zport, int irq)
struct zs_scc *scc = zport->scc;
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);
udelay(2);
zs_spin_lock_cond_irq(&scc->zlock, irq);
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] serial: off by one
2009-06-03 23:20 [PATCH] serial: off by one Roel Kluin
@ 2009-06-04 4:18 ` David Miller
2009-06-04 12:04 ` Maciej W. Rozycki
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2009-06-04 4:18 UTC (permalink / raw)
To: roel.kluin; +Cc: macro, linux-kernel, akpm
From: Roel Kluin <roel.kluin@gmail.com>
Date: Thu, 04 Jun 2009 01:20:33 +0200
> 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>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] serial: off by one
2009-06-03 23:20 [PATCH] serial: off by one Roel Kluin
2009-06-04 4:18 ` David Miller
@ 2009-06-04 12:04 ` Maciej W. Rozycki
1 sibling, 0 replies; 3+ messages in thread
From: Maciej W. Rozycki @ 2009-06-04 12:04 UTC (permalink / raw)
To: Roel Kluin; +Cc: davem, lkml, Andrew Morton
On Thu, 4 Jun 2009, Roel Kluin wrote:
> 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: Maciej W. Rozycki <macro@linux-mips.org>
Maciej
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-06-04 12:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-03 23:20 [PATCH] serial: off by one Roel Kluin
2009-06-04 4:18 ` David Miller
2009-06-04 12:04 ` Maciej W. Rozycki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox