From: Andrew Morton <akpm@linux-foundation.org>
To: David Miller <davem@davemloft.net>
Cc: roel.kluin@gmail.com, linux-scsi@vger.kernel.org
Subject: Re: [PATCH] qlogicpti: Add missing parentheses
Date: Thu, 19 Feb 2009 13:01:42 -0800 [thread overview]
Message-ID: <20090219130142.4442c1a5.akpm@linux-foundation.org> (raw)
In-Reply-To: <20090218.143916.50840604.davem@davemloft.net>
On Wed, 18 Feb 2009 14:39:16 -0800 (PST)
David Miller <davem@davemloft.net> wrote:
> From: Roel Kluin <roel.kluin@gmail.com>
> Date: Wed, 18 Feb 2009 13:48:11 +0100
>
> > Add missing parentheses
> >
> > Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
>
> So what bug does this cause?
>
> > #define QLOGICPTI_REQ_QUEUE_LEN 255 /* must be power of two - 1 */
> > -#define QLOGICPTI_MAX_SG(ql) (4 + ((ql) > 0) ? 7*((ql) - 1) : 0)
> > +#define QLOGICPTI_MAX_SG(ql) (4 + (((ql) > 0) ? 7*((ql) - 1) : 0))
>
> The "ql > 0" bids to the "?" operator, so this expression
> does the right thing as-is as far as I can tell.
>
> Do you think that "4 + ((ql > 0)" binds to "?", I don't think
> it does.
The code is crap, and buggy if passed an expression with side-effects.
Let's turn it into the way it _should_ have been written.
yes, "+" has higher precedence than ?:, so the current code is:
static inline int qlogicpti_max_sg(int ql)
{
if (4 + (ql > 0))
return 7 * (ql - 1);
else
return 0;
}
Now, 4 plus a boolean can only ever evaluate to 4 or 5, so this
function can never return zero. So yeah, I assume that this was meant:
static inline int qlogicpti_max_sg(int ql)
{
if (ql > 0)
return 7 * (ql - 1) + 4;
else
return 4;
}
next prev parent reply other threads:[~2009-02-19 21:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-18 12:48 [PATCH] qlogicpti: Add missing parentheses Roel Kluin
2009-02-18 22:39 ` David Miller
2009-02-19 21:01 ` Andrew Morton [this message]
2009-02-20 8:51 ` David Miller
-- strict thread matches above, loose matches on Subject: below --
2009-11-03 23:38 [PATCH] qlogicpti: add " Roel Kluin
2009-11-03 23:51 ` James Bottomley
2009-11-04 0:19 ` David Miller
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=20090219130142.4442c1a5.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=davem@davemloft.net \
--cc=linux-scsi@vger.kernel.org \
--cc=roel.kluin@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox