public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] serial: Z85C30: BCM1480: loops should end at 0
@ 2009-02-08 15:40 Roel Kluin
  2009-02-10  0:03 ` Maciej W. Rozycki
  0 siblings, 1 reply; 2+ messages in thread
From: Roel Kluin @ 2009-02-08 15:40 UTC (permalink / raw)
  To: Maciej W. Rozycki, lkml

With a postfix decrement 'loops' reach -1, not 0, which is subsequently
returned. In drivers/serial/zs.c, line 1137 it is considered as a boolean with 0
as failure:

if (zs_transmit_drain(zport, irq))
                write_zsdata(zport, ch);

so to use it as such loops should end at 0 after the loop rather than -1.
This also fix similar issues in other functions.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
Another solution would be to change the test at drivers/serial/zs.c, line 1137:

if (zs_transmit_drain(zport, irq) == -1)

Is that preferred?

 drivers/serial/sb1250-duart.c |    6 +++---
 drivers/serial/zs.c           |    6 +++---
 2 files changed, 6 insertions(+), 6 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/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] 2+ messages in thread

* Re: [PATCH] serial: Z85C30: BCM1480: loops should end at 0
  2009-02-08 15:40 [PATCH] serial: Z85C30: BCM1480: loops should end at 0 Roel Kluin
@ 2009-02-10  0:03 ` Maciej W. Rozycki
  0 siblings, 0 replies; 2+ messages in thread
From: Maciej W. Rozycki @ 2009-02-10  0:03 UTC (permalink / raw)
  To: Roel Kluin; +Cc: lkml

On Sun, 8 Feb 2009, Roel Kluin wrote:

> With a postfix decrement 'loops' reach -1, not 0, which is subsequently
> returned. In drivers/serial/zs.c, line 1137 it is considered as a boolean with 0
> as failure:
> 
> if (zs_transmit_drain(zport, irq))
>                 write_zsdata(zport, ch);
> 
> so to use it as such loops should end at 0 after the loop rather than -1.
> This also fix similar issues in other functions.
> 
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> ---
> Another solution would be to change the test at drivers/serial/zs.c, line 1137:
> 
> if (zs_transmit_drain(zport, irq) == -1)
> 
> Is that preferred?

 I'm tempted to rewrite these as do {} while loops instead.  Thanks for 
the report -- I'm running out of disk space on my development system 
again, so please allow me a couple of days to make a clean-up before I get 
back to your report.  The change has to be split into two separate 
patches, BTW.

  Maciej

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-02-10  0:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-08 15:40 [PATCH] serial: Z85C30: BCM1480: loops should end at 0 Roel Kluin
2009-02-10  0:03 ` 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