Merge git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc
[sfrench/cifs-2.6.git] / drivers / scsi / sr.c
index a4d9be7c6874b471db06fe4a02503db46eb246bb..f9c1192dc15eca635b7d866486956aa5edecc925 100644 (file)
@@ -44,6 +44,7 @@
 #include <linux/interrupt.h>
 #include <linux/init.h>
 #include <linux/blkdev.h>
+#include <linux/mutex.h>
 #include <asm/uaccess.h>
 
 #include <scsi/scsi.h>
 #include "sr.h"
 
 
+MODULE_DESCRIPTION("SCSI cdrom (sr) driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS_BLOCKDEV_MAJOR(SCSI_CDROM_MAJOR);
+
 #define SR_DISKS       256
 
 #define MAX_RETRIES    3
@@ -90,7 +95,7 @@ static DEFINE_SPINLOCK(sr_index_lock);
 /* 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
  * object after last put) */
-static DECLARE_MUTEX(sr_ref_sem);
+static DEFINE_MUTEX(sr_ref_mutex);
 
 static int sr_open(struct cdrom_device_info *, int);
 static void sr_release(struct cdrom_device_info *);
@@ -133,7 +138,7 @@ static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)
 {
        struct scsi_cd *cd = NULL;
 
-       down(&sr_ref_sem);
+       mutex_lock(&sr_ref_mutex);
        if (disk->private_data == NULL)
                goto out;
        cd = scsi_cd(disk);
@@ -146,18 +151,18 @@ static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)
        kref_put(&cd->kref, sr_kref_release);
        cd = NULL;
  out:
-       up(&sr_ref_sem);
+       mutex_unlock(&sr_ref_mutex);
        return cd;
 }
 
-static inline void scsi_cd_put(struct scsi_cd *cd)
+static void scsi_cd_put(struct scsi_cd *cd)
 {
        struct scsi_device *sdev = cd->device;
 
-       down(&sr_ref_sem);
+       mutex_lock(&sr_ref_mutex);
        kref_put(&cd->kref, sr_kref_release);
        scsi_device_put(sdev);
-       up(&sr_ref_sem);
+       mutex_unlock(&sr_ref_mutex);
 }
 
 /*
@@ -237,8 +242,6 @@ static void rw_intr(struct scsi_cmnd * SCpnt)
                case ILLEGAL_REQUEST:
                        if (!(SCpnt->sense_buffer[0] & 0x90))
                                break;
-                       if (!blk_fs_request(SCpnt->request))
-                               break;
                        error_sector = (SCpnt->sense_buffer[3] << 24) |
                                (SCpnt->sense_buffer[4] << 16) |
                                (SCpnt->sense_buffer[5] << 8) |
@@ -316,23 +319,6 @@ static int sr_init_command(struct scsi_cmnd * SCpnt)
                return 0;
        }
 
-       /*
-        * these are already setup, just copy cdb basically
-        */
-       if (SCpnt->request->flags & REQ_BLOCK_PC) {
-               scsi_setup_blk_pc_cmnd(SCpnt);
-
-               if (SCpnt->timeout_per_command)
-                       timeout = SCpnt->timeout_per_command;
-
-               goto queue;
-       }
-
-       if (!(SCpnt->request->flags & REQ_CMD)) {
-               blk_dump_rq_flags(SCpnt->request, "sr unsup command");
-               return 0;
-       }
-
        /*
         * we do lazy blocksize switching (when reading XA sectors,
         * see CDROMREADMODE2 ioctl) 
@@ -421,8 +407,6 @@ static int sr_init_command(struct scsi_cmnd * SCpnt)
         */
        SCpnt->transfersize = cd->device->sector_size;
        SCpnt->underflow = this_count << 9;
-
-queue:
        SCpnt->allowed = MAX_RETRIES;
        SCpnt->timeout_per_command = timeout;
 
@@ -545,10 +529,9 @@ static int sr_probe(struct device *dev)
                goto fail;
 
        error = -ENOMEM;
-       cd = kmalloc(sizeof(*cd), GFP_KERNEL);
+       cd = kzalloc(sizeof(*cd), GFP_KERNEL);
        if (!cd)
                goto fail;
-       memset(cd, 0, sizeof(*cd));
 
        kref_init(&cd->kref);
 
@@ -594,8 +577,6 @@ static int sr_probe(struct device *dev)
        get_capabilities(cd);
        sr_vendor_init(cd);
 
-       snprintf(disk->devfs_name, sizeof(disk->devfs_name),
-                       "%s/cd", sdev->devfs_name);
        disk->driverfs_dev = &sdev->sdev_gendev;
        set_capacity(disk, cd->capacity);
        disk->private_data = &cd->driver;
@@ -762,8 +743,9 @@ static void get_capabilities(struct scsi_cd *cd)
                /* failed, drive doesn't have capabilities mode page */
                cd->cdi.speed = 1;
                cd->cdi.mask |= (CDC_CD_R | CDC_CD_RW | CDC_DVD_R |
-                                        CDC_DVD | CDC_DVD_RAM |
-                                        CDC_SELECT_DISC | CDC_SELECT_SPEED);
+                                CDC_DVD | CDC_DVD_RAM |
+                                CDC_SELECT_DISC | CDC_SELECT_SPEED |
+                                CDC_MRW | CDC_MRW_W | CDC_RAM);
                kfree(buffer);
                printk("%s: scsi-1 drive\n", cd->cdi.name);
                return;
@@ -845,7 +827,7 @@ static int sr_packet(struct cdrom_device_info *cdi,
  *     sr_kref_release - Called to free the scsi_cd structure
  *     @kref: pointer to embedded kref
  *
- *     sr_ref_sem must be held entering this routine.  Because it is
+ *     sr_ref_mutex must be held entering this routine.  Because it is
  *     called on last put, you should always use the scsi_cd_get()
  *     scsi_cd_put() helpers which manipulate the semaphore directly
  *     and never do a direct kref_put().
@@ -874,9 +856,9 @@ static int sr_remove(struct device *dev)
 
        del_gendisk(cd->disk);
 
-       down(&sr_ref_sem);
+       mutex_lock(&sr_ref_mutex);
        kref_put(&cd->kref, sr_kref_release);
-       up(&sr_ref_sem);
+       mutex_unlock(&sr_ref_mutex);
 
        return 0;
 }