Commit abd184cb authored by Linus Torvalds's avatar Linus Torvalds

sd.c: be more cautious in asking for mode page 8 data,

sanity-checking the information more carefully. 

The old code basically just used a random-number approach
to determine how much to read.
parent dd7937d3
...@@ -1108,14 +1108,26 @@ sd_read_cache_type(struct scsi_disk *sdkp, char *diskname, ...@@ -1108,14 +1108,26 @@ sd_read_cache_type(struct scsi_disk *sdkp, char *diskname,
/* cautiously ask */ /* cautiously ask */
res = sd_do_mode_sense(SRpnt, dbd, modepage, buffer, 4, &data); res = sd_do_mode_sense(SRpnt, dbd, modepage, buffer, 4, &data);
if (scsi_status_is_good(res)) { if (!scsi_status_is_good(res))
goto bad_sense;
/* that went OK, now ask for the proper length */ /* that went OK, now ask for the proper length */
len = data.length; len = data.length;
if (len > 128)
len = 128; /*
res = sd_do_mode_sense(SRpnt, dbd, modepage, buffer, * We're only interested in the first three bytes, actually.
len, &data); * But the data cache page is defined for the first 20.
} */
if (len < 3)
goto bad_sense;
if (len > 20)
len = 20;
/* Take headers and block descriptors into account */
len += data.header_length + data.block_descriptor_length;
/* Get the data */
res = sd_do_mode_sense(SRpnt, dbd, modepage, buffer, len, &data);
if (scsi_status_is_good(res)) { if (scsi_status_is_good(res)) {
const char *types[] = { const char *types[] = {
...@@ -1133,7 +1145,11 @@ sd_read_cache_type(struct scsi_disk *sdkp, char *diskname, ...@@ -1133,7 +1145,11 @@ sd_read_cache_type(struct scsi_disk *sdkp, char *diskname,
printk(KERN_NOTICE "SCSI device %s: drive cache: %s\n", printk(KERN_NOTICE "SCSI device %s: drive cache: %s\n",
diskname, types[ct]); diskname, types[ct]);
} else {
return;
}
bad_sense:
if ((SRpnt->sr_sense_buffer[0] & 0x70) == 0x70 if ((SRpnt->sr_sense_buffer[0] & 0x70) == 0x70
&& (SRpnt->sr_sense_buffer[2] & 0x0f) == ILLEGAL_REQUEST && (SRpnt->sr_sense_buffer[2] & 0x0f) == ILLEGAL_REQUEST
/* ASC 0x24 ASCQ 0x00: Invalid field in CDB */ /* ASC 0x24 ASCQ 0x00: Invalid field in CDB */
...@@ -1149,7 +1165,6 @@ sd_read_cache_type(struct scsi_disk *sdkp, char *diskname, ...@@ -1149,7 +1165,6 @@ sd_read_cache_type(struct scsi_disk *sdkp, char *diskname,
diskname); diskname);
sdkp->WCE = 0; sdkp->WCE = 0;
sdkp->RCD = 0; sdkp->RCD = 0;
}
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment