Linux Headquarters
[ Register ]
[ About us ] [ Home Page ]

Advertisement
[ Kernel ] [ Documentation ] [ Links ] [ Books ]

Advertisement

Kernel v2.6.24.4 /drivers/scsi/sd.c

Filename:/drivers/scsi/sd.c
Lines Added:16
Lines Deleted:18
Also changed in: (Previous) 2.6.24.3  2.6.24.3-rc1  2.6.24-git22  2.6.24-git21  2.6.24-git20  2.6.24-git19 
(Following) 2.6.24.5  2.6.24.6  2.6.24.7  2.6.25-rc6-git8  2.6.25-rc7  2.6.25-rc8 

Location
[  2.6.24.4
  [  drivers
    [  scsi
       o  sd.c

Patch

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index a69b155..cfd859a 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -907,6 +907,7 @@ static int sd_done(struct scsi_cmnd *SCpnt)
     unsigned int xfer_size = SCpnt->request_bufflen;
     unsigned int good_bytes = result ? 0 : xfer_size;
     u64 start_lba = SCpnt->request->sector;
+   u64 end_lba = SCpnt->request->sector + (xfer_size / 512);
     u64 bad_lba;
    struct scsi_sense_hdr sshdr;
    int sense_valid = 0;
@@ -945,26 +946,23 @@ static int sd_done(struct scsi_cmnd *SCpnt)
          goto out;
       if (xfer_size <= SCpnt->device->sector_size)
          goto out;
-      switch (SCpnt->device->sector_size) {
-      case 256:
+      if (SCpnt->device->sector_size < 512) {
+         /* only legitimate sector_size here is 256 */
          start_lba <<= 1;
-         break;
-      case 512:
-         break;
-      case 1024:
-         start_lba >>= 1;
-         break;
-      case 2048:
-         start_lba >>= 2;
-         break;
-      case 4096:
-         start_lba >>= 3;
-         break;
-      default:
-         /* Print something here with limiting frequency. */
-         goto out;
-         break;
+         end_lba <<= 1;
+      } else {
+         /* be careful ... don't want any overflows */
+         u64 factor = SCpnt->device->sector_size / 512;
+         do_div(start_lba, factor);
+         do_div(end_lba, factor);
       }
+
+      if (bad_lba < start_lba  || bad_lba >= end_lba)
+         /* the bad lba was reported incorrectly, we have
+          * no idea where the error is
+          */
+         goto out;
+
       /* This computation should always be done in terms of
        * the resolution of the device's medium.
        */


Comments: webmaster (at) linuxhq.com.
Advertising: banners (at) linuxhq.com.
Compilation ©1998-2008 Linux Headquarters, Inc.