Skip to contentSkip to conversation

clear garbage after CDBs on SG_IO

PATCH In review Tejun Heo 3 participants 4 messages Nov 16, 2006

Subsystems (3)
lore
Share & tools
lore

Tejun Heo

author
#0 lore raw

PATCH 1/1 clear garbage after CDBs on SG_IO

ATAPI devices transfer fixed number of bytes for CDBs (12 or 16). Some ATAPI devices choke when shorter CDB is used and the left bytes contain garbage. Block SG_IO cleared left bytes but SCSI SG_IO didn't. This patch makes SCSI SG_IO clear it and simplify CDB clearing in block SG_IO.

Cc Mathieu Fluhr <[email protected]>
block/scsi_ioctl.c +1 -2
index 2dc3264..cac7f18 100644
@@ -286,9 +286,8 @@ static int sg_io(struct file *file, requ
 	 * fill in request structure
 	 */
 	rq->cmd_len = hdr->cmd_len;
+	memset(req->cmd, 0, BLK_MAX_CDB); /* ATAPI hates garbage after CDB */
 	memcpy(rq->cmd, cmd, hdr->cmd_len);
-	if (sizeof(rq->cmd) != hdr->cmd_len)
-		memset(rq->cmd + hdr->cmd_len, 0, sizeof(rq->cmd) - hdr->cmd_len);
 
 	memset(sense, 0, sizeof(sense));
 	rq->sense = sense;
drivers/scsi/scsi_lib.c +1 -0
index d2c02df..3ac4890 100644
@@ -410,6 +410,7 @@ int scsi_execute_async(struct scsi_devic
 		goto free_req;
 
 	req->cmd_len = cmd_len;
+	memset(req->cmd, 0, BLK_MAX_CDB); /* ATAPI hates garbage after CDB */
 	memcpy(req->cmd, cmd, req->cmd_len);
 	req->sense = sioc->sense;
 	req->sense_len = 0;
#1 lore raw
Quoted 8 lines · Tejun Heo

ATAPI devices transfer fixed number of bytes for CDBs (12 or 16). Some ATAPI devices choke when shorter CDB is used and the left bytes contain garbage. Block SG_IO cleared left bytes but SCSI SG_IO didn't. This patch makes SCSI SG_IO clear it and simplify CDB clearing in block SG_IO.

Cc Mathieu Fluhr <[email protected]>

ACK

#2 lore raw
In reply to Tejun Heo
Quoted 14 lines · On Thu, 16 Nov 2006 09:52:27 +0900 Tejun Heo <[email protected]> wrote:

ATAPI devices transfer fixed number of bytes for CDBs (12 or 16). Some ATAPI devices choke when shorter CDB is used and the left bytes contain garbage. Block SG_IO cleared left bytes but SCSI SG_IO didn't. This patch makes SCSI SG_IO clear it and simplify CDB clearing in block SG_IO.

Cc Mathieu Fluhr <[email protected]>
block/scsi_ioctl.c +0 -0
index 2dc3264..cac7f18 100644

block/scsi_ioctl.c static int sg_io(struct file *file, requ · line 289

Quoted 4 lines
block/scsi_ioctl.c +1 -0
@@ -286,9 +286,8 @@ static int sg_io(struct file *file, requ
 	 * fill in request structure
 	 */
 	rq->cmd_len = hdr->cmd_len;
+	memset(req->cmd, 0, BLK_MAX_CDB); /* ATAPI hates garbage after CDB */

s/req/rq/ makes the compiler happier there.

author
#3 lore raw
Quoted 12 lines · Andrew Morton
Quoted 9 lines · On Thu, 16 Nov 2006 09:52:27 +0900 Tejun Heo <[email protected]> wrote:

ATAPI devices transfer fixed number of bytes for CDBs (12 or 16). Some ATAPI devices choke when shorter CDB is used and the left bytes contain garbage. Block SG_IO cleared left bytes but SCSI SG_IO didn't. This patch makes SCSI SG_IO clear it and simplify CDB clearing in block SG_IO.

Cc Mathieu Fluhr <[email protected]>
Quoted 11 lines

block/scsi_ioctl.c static int sg_io(struct file *file, requ · line 289

Quoted 9 lines
block/scsi_ioctl.c +1 -0
index 2dc3264..cac7f18 100644
@@ -286,9 +286,8 @@ static int sg_io(struct file *file, requ
 	 * fill in request structure
 	 */
 	rq->cmd_len = hdr->cmd_len;
+	memset(req->cmd, 0, BLK_MAX_CDB); /* ATAPI hates garbage after CDB */

s/req/rq/ makes the compiler happier there.

Yeap, apparently. Sorry. Last minute copy and paste w/ comment. Arggh... No change is ever safe.

Signature · 1 line
tejun