Commit 8f76d151 authored by Dave Hansen's avatar Dave Hansen Committed by James Bottomley

[SCSI] fix sign extension with 1.5TB usb-storage LBD=y

Shifting an unsigned char implicitly casts it to a signed int.  This
caused 'lba' to sign-extend and Linux would then try READ CAPACITY 16
which was not supported by at least one drive.  Using the
get_unaligned_be*() helpers keeps us from having to worry about how the
extension might occur.
Signed-off-by: default avatarDave Hansen <dave@linux.vnet.ibm.com>
Reviewed-by: default avatarMatthew Wilcox <willy@linux.intel.com>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@HansenPartnership.com>
parent dd406ef8
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#include <linux/string_helpers.h> #include <linux/string_helpers.h>
#include <linux/async.h> #include <linux/async.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/unaligned.h>
#include <scsi/scsi.h> #include <scsi/scsi.h>
#include <scsi/scsi_cmnd.h> #include <scsi/scsi_cmnd.h>
...@@ -1344,12 +1345,8 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp, ...@@ -1344,12 +1345,8 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
return -EINVAL; return -EINVAL;
} }
sector_size = (buffer[8] << 24) | (buffer[9] << 16) | sector_size = get_unaligned_be32(&buffer[8]);
(buffer[10] << 8) | buffer[11]; lba = get_unaligned_be64(&buffer[0]);
lba = (((u64)buffer[0] << 56) | ((u64)buffer[1] << 48) |
((u64)buffer[2] << 40) | ((u64)buffer[3] << 32) |
((u64)buffer[4] << 24) | ((u64)buffer[5] << 16) |
((u64)buffer[6] << 8) | (u64)buffer[7]);
sd_read_protection_type(sdkp, buffer); sd_read_protection_type(sdkp, buffer);
...@@ -1400,10 +1397,8 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp, ...@@ -1400,10 +1397,8 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp,
return -EINVAL; return -EINVAL;
} }
sector_size = (buffer[4] << 24) | (buffer[5] << 16) | sector_size = get_unaligned_be32(&buffer[4]);
(buffer[6] << 8) | buffer[7]; lba = get_unaligned_be32(&buffer[0]);
lba = (buffer[0] << 24) | (buffer[1] << 16) |
(buffer[2] << 8) | buffer[3];
if ((sizeof(sdkp->capacity) == 4) && (lba == 0xffffffff)) { if ((sizeof(sdkp->capacity) == 4) && (lba == 0xffffffff)) {
sd_printk(KERN_ERR, sdkp, "Too big for this kernel. Use a " sd_printk(KERN_ERR, sdkp, "Too big for this kernel. Use a "
......
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