All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roel Kluin <roel.kluin@gmail.com>
To: "Juha Leppänen" <juha_motorsportcom@luukku.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org,
	Jarek Poplawski <jarkao2@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: IRDA: mcs7780.c
Date: Fri, 13 Feb 2009 14:14:17 +0100	[thread overview]
Message-ID: <49957229.9060401@gmail.com> (raw)
In-Reply-To: <1234514947203.juha_motorsportcom.12982.AOyeEm8k4zVzAxDijub1SA@luukku.com>

Juha Leppänen wrote:
> Hi,
> 
> In recent patch to file
> 
> drivers/net/irda/mcs7780.c

That's this one:
http://www.spinics.net/lists/netdev/msg88746.html

[PATCH] IRDA: cnt is off by 1

> I noticed when checking the code around the patch ...
> In worst case do {...} while loop is executed
> 101 times --> mcs_get_reg() is executed 101 times...
> But rval is checked only 100 times.

Right, thanks.

> If you change the order of the && expressions inside while () to
> 
> -        } while(cnt++ < 100 && (rval & MCS_IRINTX));
> +        } while((rval & MCS_IRINTX) && cnt++ < 100);

> If you also want exactly 100 maximum mcs_get_reg()
> tries ( now it is 101 ) ...

I don't think it really matters, does it?

> Happy hacking,
> 
> Mr. Juha Leppänen
> Kuopio, Finland

You too.

------------------------------>8----------------8<------------------------------
If no prior break occurs, cnt reaches 101 after the loop, so we are still able
to change speed when cnt has become 100.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
diff --git a/drivers/net/irda/mcs7780.c b/drivers/net/irda/mcs7780.c
index 7eafdca..8fdfb5a 100644
--- a/drivers/net/irda/mcs7780.c
+++ b/drivers/net/irda/mcs7780.c
@@ -583,9 +583,9 @@ static int mcs_speed_change(struct mcs_cb *mcs)
 
 	do {
 		mcs_get_reg(mcs, MCS_RESV_REG, &rval);
-	} while(cnt++ < 100 && (rval & MCS_IRINTX));
+	} while((rval & MCS_IRINTX) && cnt++ < 100);
 
-	if(cnt >= 100) {
+	if (cnt > 100) {
 		IRDA_ERROR("unable to change speed\n");
 		ret = -EIO;
 		goto error;

       reply	other threads:[~2009-02-13 13:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1234514947203.juha_motorsportcom.12982.AOyeEm8k4zVzAxDijub1SA@luukku.com>
2009-02-13 13:14 ` Roel Kluin [this message]
2009-02-13 19:05   ` IRDA: mcs7780.c Jarek Poplawski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49957229.9060401@gmail.com \
    --to=roel.kluin@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=jarkao2@gmail.com \
    --cc=juha_motorsportcom@luukku.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.