From 8ce7779445132181c591f2012e17c3aa527997eb Mon Sep 17 00:00:00 2001 From: lly Date: Sun, 20 Mar 2011 06:32:33 -0400 Subject: [PATCH] [SCSI] sd: fixes from upstream kernel.org commits 8f76d151b010980d137bfdc736d1d8f64b489165 [SCSI] fix sign extension with 1.5TB usb-storage LBD=y f27bac2761cab5a2e212dea602d22457a9aa6943 [SCSI] sd: update index allocation and use ida instead of idr --- release/src-rt/linux/linux-2.6/drivers/scsi/sd.c | 50 ++++++++++-------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/release/src-rt/linux/linux-2.6/drivers/scsi/sd.c b/release/src-rt/linux/linux-2.6/drivers/scsi/sd.c index 996926cbbf..2e5d9d4374 100644 --- a/release/src-rt/linux/linux-2.6/drivers/scsi/sd.c +++ b/release/src-rt/linux/linux-2.6/drivers/scsi/sd.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -102,8 +103,7 @@ static void scsi_disk_release(struct class_device *cdev); static void sd_print_sense_hdr(struct scsi_disk *, struct scsi_sense_hdr *); static void sd_print_result(struct scsi_disk *, int); -static DEFINE_IDR(sd_index_idr); -static DEFINE_SPINLOCK(sd_index_lock); +static DEFINE_IDA(sd_index_ida); /* This semaphore is used to mediate the 0->1 reference get in the * face of object destruction (i.e. we can't allow a get on an @@ -1227,8 +1227,7 @@ repeat: } if (!longrc) { - sector_size = (buffer[4] << 24) | - (buffer[5] << 16) | (buffer[6] << 8) | buffer[7]; + sector_size = get_unaligned_be32(&buffer[4]); if (buffer[0] == 0xff && buffer[1] == 0xff && buffer[2] == 0xff && buffer[3] == 0xff) { if(sizeof(sdkp->capacity) > 4) { @@ -1243,22 +1242,11 @@ repeat: sdkp->capacity = 0; goto got_data; } - sdkp->capacity = 1 + (((sector_t)buffer[0] << 24) | - (buffer[1] << 16) | - (buffer[2] << 8) | - buffer[3]); + sdkp->capacity = 1 + (sector_t)get_unaligned_be32(&buffer[0]); } else { - sdkp->capacity = 1 + (((u64)buffer[0] << 56) | - ((u64)buffer[1] << 48) | - ((u64)buffer[2] << 40) | - ((u64)buffer[3] << 32) | - ((sector_t)buffer[4] << 24) | - ((sector_t)buffer[5] << 16) | - ((sector_t)buffer[6] << 8) | - (sector_t)buffer[7]); - - sector_size = (buffer[8] << 24) | - (buffer[9] << 16) | (buffer[10] << 8) | buffer[11]; + sdkp->capacity = 1 + get_unaligned_be64(&buffer[0]); + + sector_size = get_unaligned_be32(&buffer[8]); } /* Some devices are known to return the total number of blocks, @@ -1639,18 +1627,20 @@ static int sd_probe(struct device *dev) if (!gd) goto out_free; - if (!idr_pre_get(&sd_index_idr, GFP_KERNEL)) - goto out_put; + do { + if (!ida_pre_get(&sd_index_ida, GFP_KERNEL)) + goto out_put; - spin_lock(&sd_index_lock); - error = idr_get_new(&sd_index_idr, NULL, &index); - spin_unlock(&sd_index_lock); + error = ida_get_new(&sd_index_ida, &index); + } while (error == -EAGAIN); - if (index >= SD_MAX_DISKS) - error = -EBUSY; if (error) goto out_put; + error = -EBUSY; + if (index >= SD_MAX_DISKS) + goto out_free_index; + sdkp->device = sdp; sdkp->driver = &sd_template; sdkp->disk = gd; @@ -1670,7 +1660,7 @@ static int sd_probe(struct device *dev) strncpy(sdkp->cdev.class_id, sdp->sdev_gendev.bus_id, BUS_ID_SIZE); if (class_device_add(&sdkp->cdev)) - goto out_put; + goto out_free_index; get_device(&sdp->sdev_gendev); @@ -1719,6 +1709,8 @@ static int sd_probe(struct device *dev) return 0; + out_free_index: + ida_remove(&sd_index_ida, index); out_put: put_disk(gd); out_free: @@ -1768,9 +1760,7 @@ static void scsi_disk_release(struct class_device *cdev) struct scsi_disk *sdkp = to_scsi_disk(cdev); struct gendisk *disk = sdkp->disk; - spin_lock(&sd_index_lock); - idr_remove(&sd_index_idr, sdkp->index); - spin_unlock(&sd_index_lock); + ida_remove(&sd_index_ida, sdkp->index); disk->private_data = NULL; put_disk(disk); -- 2.11.4.GIT