qlogicpti: Add missing parentheses
PATCH 1/1 qlogicpti: Add missing parentheses
Add missing parentheses
---
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),
drivers/scsi/qlogicpti.h +1 -1
@@ -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
From: Roel Kluin <[email protected]>
Date: Wed, 18 Feb 2009 13:48:11 +0100
Quoted 3 lines
Add missing parentheses
Signed-off-by Roel Kluin <[email protected]>
So what bug does this cause?
drivers/scsi/qlogicpti.h line 46
Quoted 3 lines
#define
QLOGICPTI_REQ_QUEUE_LEN255 /* must be power of two - 1 */drivers/scsi/qlogicpti.h +1
-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.
Quoted 16 lines · On Wed, 18 Feb 2009 14:39:16 -0800 (PST) David Miller <[email protected]>…
From: Roel Kluin <[email protected]>
Date: Wed, 18 Feb 2009 13:48:11 +0100Quoted 3 lines
Add missing parentheses
Signed-off-by Roel Kluin <[email protected]>So what bug does this cause?
drivers/scsi/qlogicpti.h line 46
Quoted 3 lines
#define
QLOGICPTI_REQ_QUEUE_LEN255 /* must be power of two - 1 */drivers/scsi/qlogicpti.h +1
-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.
Quoted 2 lines
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;
}From: Andrew Morton <[email protected]>
Date: Thu, 19 Feb 2009 13:01:42 -0800
Quoted 19 lines
Quoted 16 lines · On Wed, 18 Feb 2009 14:39:16 -0800 (PST) David Miller <[email protected]>…
From: Roel Kluin <[email protected]>
Date: Wed, 18 Feb 2009 13:48:11 +0100Quoted 3 lines
Add missing parentheses
Signed-off-by Roel Kluin <[email protected]>So what bug does this cause?
drivers/scsi/qlogicpti.h line 46
Quoted 3 lines
#define
QLOGICPTI_REQ_QUEUE_LEN255 /* must be power of two - 1 */drivers/scsi/qlogicpti.h +1
-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.
Quoted 4 lines
Quoted 2 lines
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 :-)
Quoted 11 lines
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().