aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Bottomley <James.Bottomley@HansenPartnership.com>2008-02-02 17:06:23 -0500
committerJames Bottomley <James.Bottomley@HansenPartnership.com>2008-02-07 19:02:41 -0500
commit366c246de9cec909c5eba4f784c92d1e75b4dc38 (patch)
treef663b49998a338a70ab9601c2b4e64ce12563a3f
parentd7402cd91022fc32522397d3930a3e6587de7c55 (diff)
[SCSI] sd: handle bad lba in sense information
Some devices report medium error locations incorrectly. Add guards to make sure the reported bad lba is actually in the request that caused it. Additionally remove the large case statment for sector sizes and replace it with the proper u64 divisions. Tested-by: Mike Snitzer <snitzer@gmail.com> Cc: Stable Tree <stable@kernel.org> Cc: Tony Battersby <tonyb@cybernetics.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
-rw-r--r--drivers/scsi/sd.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 51a5557f42dd..37df8bbe7f46 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -929,6 +929,7 @@ static int sd_done(struct scsi_cmnd *SCpnt)
929 unsigned int xfer_size = scsi_bufflen(SCpnt); 929 unsigned int xfer_size = scsi_bufflen(SCpnt);
930 unsigned int good_bytes = result ? 0 : xfer_size; 930 unsigned int good_bytes = result ? 0 : xfer_size;
931 u64 start_lba = SCpnt->request->sector; 931 u64 start_lba = SCpnt->request->sector;
932 u64 end_lba = SCpnt->request->sector + (xfer_size / 512);
932 u64 bad_lba; 933 u64 bad_lba;
933 struct scsi_sense_hdr sshdr; 934 struct scsi_sense_hdr sshdr;
934 int sense_valid = 0; 935 int sense_valid = 0;
@@ -967,26 +968,23 @@ static int sd_done(struct scsi_cmnd *SCpnt)
967 goto out; 968 goto out;
968 if (xfer_size <= SCpnt->device->sector_size) 969 if (xfer_size <= SCpnt->device->sector_size)
969 goto out; 970 goto out;
970 switch (SCpnt->device->sector_size) { 971 if (SCpnt->device->sector_size < 512) {
971 case 256: 972 /* only legitimate sector_size here is 256 */
972 start_lba <<= 1; 973 start_lba <<= 1;
973 break; 974 end_lba <<= 1;
974 case 512: 975 } else {
975 break; 976 /* be careful ... don't want any overflows */
976 case 1024: 977 u64 factor = SCpnt->device->sector_size / 512;
977 start_lba >>= 1; 978 do_div(start_lba, factor);
978 break; 979 do_div(end_lba, factor);
979 case 2048:
980 start_lba >>= 2;
981 break;
982 case 4096:
983 start_lba >>= 3;
984 break;
985 default:
986 /* Print something here with limiting frequency. */
987 goto out;
988 break;
989 } 980 }
981
982 if (bad_lba < start_lba || bad_lba >= end_lba)
983 /* the bad lba was reported incorrectly, we have
984 * no idea where the error is
985 */
986 goto out;
987
990 /* This computation should always be done in terms of 988 /* This computation should always be done in terms of
991 * the resolution of the device's medium. 989 * the resolution of the device's medium.
992 */ 990 */