Re: [PATCH] [SCSI] arcmsr: &/| confusion in arcmsr_build_ccb()

Previous thread: [PATCH] staging: spectra: don't read past array in Conv_Spare_Data_Log2Phy_Format() by roel kluin on Saturday, January 1, 2011 - 9:24 am. (1 message)

Next thread: [PATCH] microblaze: correct PVR access macros by roel kluin on Saturday, January 1, 2011 - 10:17 am. (2 messages)
From: roel kluin
Date: Saturday, January 1, 2011 - 9:45 am

The WRITE_{6,10,12} are defined numbers, so the branch was always taken.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
 drivers/scsi/arcmsr/arcmsr_hba.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

See include/scsi/scsi.h:58-123 for
#define WRITE_6               0x0a
#define WRITE_10              0x2a
#define WRITE_12              0xaa

diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 17e3df4..a6e5222 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -1171,7 +1171,8 @@ static int arcmsr_build_ccb(struct AdapterControlBlock *acb,
 	arcmsr_cdb->msgPages = arccdbsize/0x100 + (arccdbsize % 0x100 ? 1 : 0);
 	if ( arccdbsize > 256)
 		arcmsr_cdb->Flags |= ARCMSR_CDB_FLAG_SGL_BSIZE;
-	if (pcmd->cmnd[0]|WRITE_6 || pcmd->cmnd[0]|WRITE_10 || pcmd->cmnd[0]|WRITE_12 ){
+	if (pcmd->cmnd[0] & WRITE_6 || pcmd->cmnd[0] & WRITE_10 ||
+			pcmd->cmnd[0] & WRITE_12 ){
 		arcmsr_cdb->Flags |= ARCMSR_CDB_FLAG_WRITE;
 	}
 	ccb->arc_cdb_size = arccdbsize;
--

From: Matthew Wilcox
Date: Saturday, January 1, 2011 - 10:08 am

You're right, but even this will basically always set the write flag,
since some bits will be set the same, even for reads.  Eg:

#define READ_10               0x28
#define WRITE_10              0x2a


That will of course miss other commands which do writes, such as UNMAP
and WRITE_32.  So we should do it properly:

	if (pcmd->sc_data_direction == DMA_TO_DEVICE)
		arcmsr_cdb->Flags |= ARCMSR_CDB_FLAG_WRITE;


-- 
Matthew Wilcox				Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."
--

From: Torsten Kaiser
Date: Saturday, January 1, 2011 - 10:28 am

<http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=ae52e7f09ff509df11cd408eabe90132b6be1231;hp=f034260db330bb3ffc815fcb682b1c84aca09591#patch2>
@@ -1034,10 +1075,10 @@ static int arcmsr_build_ccb(struct
AdapterControlBlock *acb,
                }
                arcmsr_cdb->sgcount = (uint8_t)cdb_sgcount;
                arcmsr_cdb->DataLength = scsi_bufflen(pcmd);
+       arcmsr_cdb->msgPages = arccdbsize/0x100 + (arccdbsize % 0x100 ? 1 : 0);
                if ( arccdbsize > 256)
                        arcmsr_cdb->Flags |= ARCMSR_CDB_FLAG_SGL_BSIZE;
-       }
-       if (pcmd->sc_data_direction == DMA_TO_DEVICE ) {
+       if (pcmd->cmnd[0]|WRITE_6 || pcmd->cmnd[0] | WRITE_10 ||
pcmd->cmnd[0]|WRITE_12) {
                arcmsr_cdb->Flags |= ARCMSR_CDB_FLAG_WRITE;
                ccb->ccb_flags |= CCB_FLAG_WRITE;
        }

Until June 2010 it was that way...
--

From: Matthew Wilcox
Date: Saturday, January 1, 2011 - 4:34 pm

So it was.  Nick, why did you make this change?  Your commit message is
less than informative, partly because you're making such huge changes
in a single commit.

-- 
Matthew Wilcox				Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."
--

From: roel kluin
Date: Saturday, January 1, 2011 - 11:40 am

Make sure no other command which does a write, such as UNMAP and WRITE_32, is missed.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
 drivers/scsi/arcmsr/arcmsr_hba.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

If you agree this is the right fix, please ack.

diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 17e3df4..a5acedc 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -1171,7 +1171,7 @@ static int arcmsr_build_ccb(struct AdapterControlBlock *acb,
 	arcmsr_cdb->msgPages = arccdbsize/0x100 + (arccdbsize % 0x100 ? 1 : 0);
 	if ( arccdbsize > 256)
 		arcmsr_cdb->Flags |= ARCMSR_CDB_FLAG_SGL_BSIZE;
-	if (pcmd->cmnd[0]|WRITE_6 || pcmd->cmnd[0]|WRITE_10 || pcmd->cmnd[0]|WRITE_12 ){
+	if (pcmd->sc_data_direction == DMA_TO_DEVICE)
 		arcmsr_cdb->Flags |= ARCMSR_CDB_FLAG_WRITE;
 	}
 	ccb->arc_cdb_size = arccdbsize;
--

From: NickCheng
Date: Sunday, January 2, 2011 - 7:35 pm

Hi Roel,
Thanks for your reminding.
I agree with you.
This patch is absolutely correct.
-----Original Message-----
From: roel kluin [mailto:roel.kluin@gmail.com] 
Sent: Sunday, January 02, 2011 2:40 AM
To: Matthew Wilcox; just.for.lkml@googlemail.com
Cc: nick.cheng@areca.com.tw; Andrew Morton; LKML; James.Bottomley@suse.de;
linux-scsi@vger.kernel.org
Subject: Re: [PATCH] [SCSI] arcmsr: &/| confusion in arcmsr_build_ccb()

Make sure no other command which does a write, such as UNMAP and WRITE_32,
is missed.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
 drivers/scsi/arcmsr/arcmsr_hba.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

If you agree this is the right fix, please ack.

diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c
b/drivers/scsi/arcmsr/arcmsr_hba.c
index 17e3df4..a5acedc 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -1171,7 +1171,7 @@ static int arcmsr_build_ccb(struct AdapterControlBlock
*acb,
 	arcmsr_cdb->msgPages = arccdbsize/0x100 + (arccdbsize % 0x100 ? 1 :
0);
 	if ( arccdbsize > 256)
 		arcmsr_cdb->Flags |= ARCMSR_CDB_FLAG_SGL_BSIZE;
-	if (pcmd->cmnd[0]|WRITE_6 || pcmd->cmnd[0]|WRITE_10 ||
pcmd->cmnd[0]|WRITE_12 ){
+	if (pcmd->sc_data_direction == DMA_TO_DEVICE)
 		arcmsr_cdb->Flags |= ARCMSR_CDB_FLAG_WRITE;
 	}
 	ccb->arc_cdb_size = arccdbsize;

--

From: Torsten Kaiser
Date: Sunday, January 2, 2011 - 10:22 pm

From: James Bottomley
Date: Monday, January 3, 2011 - 9:43 am

Compile checking patches you send in next time would be most welcome:

  CC [M]  drivers/scsi/arcmsr/arcmsr_hba.o
drivers/scsi/arcmsr/arcmsr_hba.c:1177:5: error: expected ‘=’, ‘,’, ‘;’,
‘asm’ or ‘__attribute__’ before ‘->’ token
drivers/scsi/arcmsr/arcmsr_hba.c:1178:2: error: expected identifier or
‘(’ before ‘return’
drivers/scsi/arcmsr/arcmsr_hba.c:1179:1: error: expected identifier or
‘(’ before ‘}’ token
drivers/scsi/arcmsr/arcmsr_hba.c: In function ‘arcmsr_build_ccb’:
drivers/scsi/arcmsr/arcmsr_hba.c:1176:2: warning: control reaches end of
non-void function

James


--

From: Torsten Kaiser
Date: Saturday, January 1, 2011 - 10:12 am

I'm not sure, if the compiler will optimize this anyway, but would it
look better this way:
if (pcmd->cmnd[0] & (WRITE_6 | WRITE_10 | WRITE_12)){

And that would open the question what really was meant, as that will
be equal to:
if (pcmd->cmnd[0] & WRITE_12){

(if you look at the constants, you can skip WRITE_6 and _10 as there
--

Previous thread: [PATCH] staging: spectra: don't read past array in Conv_Spare_Data_Log2Phy_Format() by roel kluin on Saturday, January 1, 2011 - 9:24 am. (1 message)

Next thread: [PATCH] microblaze: correct PVR access macros by roel kluin on Saturday, January 1, 2011 - 10:17 am. (2 messages)