* [PATCH] qlogicpti: Add missing parentheses
@ 2009-02-18 12:48 Roel Kluin
2009-02-18 22:39 ` David Miller
0 siblings, 1 reply; 7+ messages in thread
From: Roel Kluin @ 2009-02-18 12:48 UTC (permalink / raw)
To: David S. Miller; +Cc: linux-scsi, Andrew Morton
Add missing parentheses
Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
This was used at drivers/scsi/qlogicpti.c:
946: host->sg_tablesize = QLOGICPTI_MAX_SG(num_free);
1270: .sg_tablesize = QLOGICPTI_MAX_SG(QLOGICPTI_REQ_QUEUE_LEN),
diff --git a/drivers/scsi/qlogicpti.h b/drivers/scsi/qlogicpti.h
index 9c053bb..e3c74d1 100644
--- a/drivers/scsi/qlogicpti.h
+++ b/drivers/scsi/qlogicpti.h
@@ -43,7 +43,7 @@
* determined for each queue request anew.
*/
#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))
/* mailbox command complete status codes */
#define MBOX_COMMAND_COMPLETE 0x4000
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] qlogicpti: Add missing parentheses
2009-02-18 12:48 [PATCH] qlogicpti: Add " Roel Kluin
@ 2009-02-18 22:39 ` David Miller
2009-02-19 21:01 ` Andrew Morton
0 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2009-02-18 22:39 UTC (permalink / raw)
To: roel.kluin; +Cc: linux-scsi, akpm
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] qlogicpti: Add missing parentheses
2009-02-18 22:39 ` David Miller
@ 2009-02-19 21:01 ` Andrew Morton
2009-02-20 8:51 ` David Miller
0 siblings, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2009-02-19 21:01 UTC (permalink / raw)
To: David Miller; +Cc: roel.kluin, linux-scsi
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;
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] qlogicpti: Add missing parentheses
2009-02-19 21:01 ` Andrew Morton
@ 2009-02-20 8:51 ` David Miller
0 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2009-02-20 8:51 UTC (permalink / raw)
To: akpm; +Cc: roel.kluin, linux-scsi
From: Andrew Morton <akpm@linux-foundation.org>
Date: Thu, 19 Feb 2009 13:01:42 -0800
> 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.
Thank got it never is called that way :-)
> 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;
> }
>
I think this doesn't even match the intention, and I wrote
the code so...
We want to return 0 if the queue has no free entries.
But if it does have free slots, we want "4 + xxx"
These problems probably explain the mysterious workaround
in update_can_queue().
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] qlogicpti: add missing parentheses
@ 2009-11-03 23:38 Roel Kluin
2009-11-03 23:51 ` James Bottomley
0 siblings, 1 reply; 7+ messages in thread
From: Roel Kluin @ 2009-11-03 23:38 UTC (permalink / raw)
To: James E.J. Bottomley, linux-scsi, Andrew Morton, LKML
`+' has a higher precedence than `?' so the condition always
evaluates to true and this is preprocessed to `7*((ql) - 1)'
Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
drivers/scsi/qlogicpti.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
This one must be right, I think.
QLOGICPTI_MAX_SG is used here:
drivers/scsi/qlogicpti.c:964: host->sg_tablesize = QLOGICPTI_MAX_SG(num_free);
drivers/scsi/qlogicpti.c:1288: .sg_tablesize = QLOGICPTI_MAX_SG(QLOGICPTI_REQ_QUEUE_LEN),
Thanks, Roel
diff --git a/drivers/scsi/qlogicpti.h b/drivers/scsi/qlogicpti.h
index 9c053bb..e3c74d1 100644
--- a/drivers/scsi/qlogicpti.h
+++ b/drivers/scsi/qlogicpti.h
@@ -43,7 +43,7 @@
* determined for each queue request anew.
*/
#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))
/* mailbox command complete status codes */
#define MBOX_COMMAND_COMPLETE 0x4000
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] qlogicpti: add missing parentheses
2009-11-03 23:38 [PATCH] qlogicpti: add missing parentheses Roel Kluin
@ 2009-11-03 23:51 ` James Bottomley
2009-11-04 0:19 ` David Miller
0 siblings, 1 reply; 7+ messages in thread
From: James Bottomley @ 2009-11-03 23:51 UTC (permalink / raw)
To: Roel Kluin; +Cc: linux-scsi, Andrew Morton, LKML
On Wed, 2009-11-04 at 00:38 +0100, Roel Kluin wrote:
> `+' has a higher precedence than `?' so the condition always
> evaluates to true and this is preprocessed to `7*((ql) - 1)'
>
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> ---
> drivers/scsi/qlogicpti.h | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> This one must be right, I think.
It looks plausible ... but it will increase the mailbox segment length
by 4 ... someone needs to verify that this increase will actually work
and won't run off the end of the mailbox table.
James
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] qlogicpti: add missing parentheses
2009-11-03 23:51 ` James Bottomley
@ 2009-11-04 0:19 ` David Miller
0 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2009-11-04 0:19 UTC (permalink / raw)
To: James.Bottomley; +Cc: roel.kluin, linux-scsi, akpm, linux-kernel
From: James Bottomley <James.Bottomley@suse.de>
Date: Tue, 03 Nov 2009 17:51:49 -0600
> On Wed, 2009-11-04 at 00:38 +0100, Roel Kluin wrote:
>> `+' has a higher precedence than `?' so the condition always
>> evaluates to true and this is preprocessed to `7*((ql) - 1)'
>>
>> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
>> ---
>> drivers/scsi/qlogicpti.h | 2 +-
>> 1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> This one must be right, I think.
>
> It looks plausible ... but it will increase the mailbox segment length
> by 4 ... someone needs to verify that this increase will actually work
> and won't run off the end of the mailbox table.
It should be fine, good find Roel.
Acked-by: David S. Miller <davem@davemloft.net>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-11-04 0:19 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-03 23:38 [PATCH] qlogicpti: add missing parentheses Roel Kluin
2009-11-03 23:51 ` James Bottomley
2009-11-04 0:19 ` David Miller
-- strict thread matches above, loose matches on Subject: below --
2009-02-18 12:48 [PATCH] qlogicpti: Add " Roel Kluin
2009-02-18 22:39 ` David Miller
2009-02-19 21:01 ` Andrew Morton
2009-02-20 8:51 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox