aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/ide-cd.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ide/ide-cd.c')
-rw-r--r--drivers/ide/ide-cd.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index e617cf08aef6..89a112d513ad 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -66,11 +66,11 @@ static struct cdrom_info *ide_cd_get(struct gendisk *disk)
66 mutex_lock(&idecd_ref_mutex); 66 mutex_lock(&idecd_ref_mutex);
67 cd = ide_cd_g(disk); 67 cd = ide_cd_g(disk);
68 if (cd) { 68 if (cd) {
69 kref_get(&cd->kref); 69 if (ide_device_get(cd->drive))
70 if (ide_device_get(cd->drive)) {
71 kref_put(&cd->kref, ide_cd_release);
72 cd = NULL; 70 cd = NULL;
73 } 71 else
72 kref_get(&cd->kref);
73
74 } 74 }
75 mutex_unlock(&idecd_ref_mutex); 75 mutex_unlock(&idecd_ref_mutex);
76 return cd; 76 return cd;
@@ -78,9 +78,11 @@ static struct cdrom_info *ide_cd_get(struct gendisk *disk)
78 78
79static void ide_cd_put(struct cdrom_info *cd) 79static void ide_cd_put(struct cdrom_info *cd)
80{ 80{
81 ide_drive_t *drive = cd->drive;
82
81 mutex_lock(&idecd_ref_mutex); 83 mutex_lock(&idecd_ref_mutex);
82 ide_device_put(cd->drive);
83 kref_put(&cd->kref, ide_cd_release); 84 kref_put(&cd->kref, ide_cd_release);
85 ide_device_put(drive);
84 mutex_unlock(&idecd_ref_mutex); 86 mutex_unlock(&idecd_ref_mutex);
85} 87}
86 88
@@ -1305,6 +1307,7 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
1305 int stat; 1307 int stat;
1306 unsigned char cmd[BLK_MAX_CDB]; 1308 unsigned char cmd[BLK_MAX_CDB];
1307 unsigned len = sizeof(capbuf); 1309 unsigned len = sizeof(capbuf);
1310 u32 blocklen;
1308 1311
1309 memset(cmd, 0, BLK_MAX_CDB); 1312 memset(cmd, 0, BLK_MAX_CDB);
1310 cmd[0] = GPCMD_READ_CDVD_CAPACITY; 1313 cmd[0] = GPCMD_READ_CDVD_CAPACITY;
@@ -1317,23 +1320,24 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
1317 /* 1320 /*
1318 * Sanity check the given block size 1321 * Sanity check the given block size
1319 */ 1322 */
1320 switch (capbuf.blocklen) { 1323 blocklen = be32_to_cpu(capbuf.blocklen);
1321 case __constant_cpu_to_be32(512): 1324 switch (blocklen) {
1322 case __constant_cpu_to_be32(1024): 1325 case 512:
1323 case __constant_cpu_to_be32(2048): 1326 case 1024:
1324 case __constant_cpu_to_be32(4096): 1327 case 2048:
1328 case 4096:
1325 break; 1329 break;
1326 default: 1330 default:
1327 printk(KERN_ERR "%s: weird block size %u\n", 1331 printk(KERN_ERR "%s: weird block size %u\n",
1328 drive->name, capbuf.blocklen); 1332 drive->name, blocklen);
1329 printk(KERN_ERR "%s: default to 2kb block size\n", 1333 printk(KERN_ERR "%s: default to 2kb block size\n",
1330 drive->name); 1334 drive->name);
1331 capbuf.blocklen = __constant_cpu_to_be32(2048); 1335 blocklen = 2048;
1332 break; 1336 break;
1333 } 1337 }
1334 1338
1335 *capacity = 1 + be32_to_cpu(capbuf.lba); 1339 *capacity = 1 + be32_to_cpu(capbuf.lba);
1336 *sectors_per_frame = be32_to_cpu(capbuf.blocklen) >> SECTOR_BITS; 1340 *sectors_per_frame = blocklen >> SECTOR_BITS;
1337 return 0; 1341 return 0;
1338} 1342}
1339 1343