]> Pileus Git - ~andy/linux/blobdiff - drivers/scsi/scsi_lib.c
[PATCH] dvb: Fix integer overflow bug
[~andy/linux] / drivers / scsi / scsi_lib.c
index 0c6924eecf59e6a34b34dd46479feb9ba7ed3aac..e40c8b66da40fe80ab6a1167ed29b1e9e62fa3d9 100644 (file)
@@ -97,7 +97,6 @@ int scsi_insert_special_req(struct scsi_request *sreq, int at_head)
 }
 
 static void scsi_run_queue(struct request_queue *q);
-static void scsi_release_buffers(struct scsi_cmnd *cmd);
 
 /*
  * Function:   scsi_unprep_request()
@@ -118,7 +117,6 @@ static void scsi_unprep_request(struct request *req)
        req->flags &= ~REQ_DONTPREP;
        req->special = (req->flags & REQ_SPECIAL) ? cmd->sc_request : NULL;
 
-       scsi_release_buffers(cmd);
        scsi_put_command(cmd);
 }
 
@@ -448,7 +446,7 @@ void scsi_device_unbusy(struct scsi_device *sdev)
 
        spin_lock_irqsave(shost->host_lock, flags);
        shost->host_busy--;
-       if (unlikely((shost->shost_state == SHOST_RECOVERY) &&
+       if (unlikely(scsi_host_in_recovery(shost) &&
                     shost->host_failed))
                scsi_eh_wakeup(shost);
        spin_unlock(shost->host_lock);
@@ -679,7 +677,7 @@ static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int uptodate,
        return NULL;
 }
 
-static struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *cmd, int gfp_mask)
+static struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *cmd, gfp_t gfp_mask)
 {
        struct scsi_host_sg_pool *sgp;
        struct scatterlist *sgl;
@@ -953,15 +951,13 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes,
                                return;
                        }
                        if (!(req->flags & REQ_QUIET))
-                               dev_printk(KERN_INFO,
-                                          &cmd->device->sdev_gendev,
+                               scmd_printk(KERN_INFO, cmd,
                                           "Device not ready.\n");
                        scsi_end_request(cmd, 0, this_count, 1);
                        return;
                case VOLUME_OVERFLOW:
                        if (!(req->flags & REQ_QUIET)) {
-                               dev_printk(KERN_INFO,
-                                          &cmd->device->sdev_gendev,
+                               scmd_printk(KERN_INFO, cmd,
                                           "Volume overflow, CDB: ");
                                __scsi_print_command(cmd->data_cmnd);
                                scsi_print_sense("", cmd);
@@ -983,7 +979,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes,
        }
        if (result) {
                if (!(req->flags & REQ_QUIET)) {
-                       dev_printk(KERN_INFO, &cmd->device->sdev_gendev,
+                       scmd_printk(KERN_INFO, cmd,
                                   "SCSI error: return code = 0x%x\n", result);
 
                        if (driver_byte(result) & DRIVER_SENSE)
@@ -1041,8 +1037,10 @@ static int scsi_init_io(struct scsi_cmnd *cmd)
         * if sg table allocation fails, requeue request later.
         */
        sgpnt = scsi_alloc_sgtable(cmd, GFP_ATOMIC);
-       if (unlikely(!sgpnt))
+       if (unlikely(!sgpnt)) {
+               scsi_unprep_request(req);
                return BLKPREP_DEFER;
+       }
 
        cmd->request_buffer = (char *) sgpnt;
        cmd->request_bufflen = req->nr_sectors << 9;
@@ -1141,8 +1139,8 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)
         * online before trying any recovery commands
         */
        if (unlikely(!scsi_device_online(sdev))) {
-               printk(KERN_ERR "scsi%d (%d:%d): rejecting I/O to offline device\n",
-                      sdev->host->host_no, sdev->id, sdev->lun);
+               sdev_printk(KERN_ERR, sdev,
+                           "rejecting I/O to offline device\n");
                goto kill;
        }
        if (unlikely(sdev->sdev_state != SDEV_RUNNING)) {
@@ -1151,8 +1149,8 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)
                if (sdev->sdev_state == SDEV_DEL) {
                        /* Device is fully deleted, no commands
                         * at all allowed down */
-                       printk(KERN_ERR "scsi%d (%d:%d): rejecting I/O to dead device\n",
-                              sdev->host->host_no, sdev->id, sdev->lun);
+                       sdev_printk(KERN_ERR, sdev,
+                                   "rejecting I/O to dead device\n");
                        goto kill;
                }
                /* OK, we only allow special commands (i.e. not
@@ -1187,8 +1185,8 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)
                                        specials_only == SDEV_BLOCK)
                                goto defer;
                        
-                       printk(KERN_ERR "scsi%d (%d:%d): rejecting I/O to device being removed\n",
-                              sdev->host->host_no, sdev->id, sdev->lun);
+                       sdev_printk(KERN_ERR, sdev,
+                                   "rejecting I/O to device being removed\n");
                        goto kill;
                }
                        
@@ -1246,8 +1244,8 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)
                 */
                ret = scsi_init_io(cmd);
                switch(ret) {
+                       /* For BLKPREP_KILL/DEFER the cmd was released */
                case BLKPREP_KILL:
-                       /* BLKPREP_KILL return also releases the command */
                        goto kill;
                case BLKPREP_DEFER:
                        goto defer;
@@ -1315,9 +1313,8 @@ static inline int scsi_dev_queue_ready(struct request_queue *q,
                 */
                if (--sdev->device_blocked == 0) {
                        SCSI_LOG_MLQUEUE(3,
-                               printk("scsi%d (%d:%d) unblocking device at"
-                                      " zero depth\n", sdev->host->host_no,
-                                      sdev->id, sdev->lun));
+                                  sdev_printk(KERN_INFO, sdev,
+                                  "unblocking device at zero depth\n"));
                } else {
                        blk_plug_device(q);
                        return 0;
@@ -1340,7 +1337,7 @@ static inline int scsi_host_queue_ready(struct request_queue *q,
                                   struct Scsi_Host *shost,
                                   struct scsi_device *sdev)
 {
-       if (shost->shost_state == SHOST_RECOVERY)
+       if (scsi_host_in_recovery(shost))
                return 0;
        if (shost->host_busy == 0 && shost->host_blocked) {
                /*
@@ -1436,8 +1433,8 @@ static void scsi_request_fn(struct request_queue *q)
                        break;
 
                if (unlikely(!scsi_device_online(sdev))) {
-                       printk(KERN_ERR "scsi%d (%d:%d): rejecting I/O to offline device\n",
-                              sdev->host->host_no, sdev->id, sdev->lun);
+                       sdev_printk(KERN_ERR, sdev,
+                                   "rejecting I/O to offline device\n");
                        scsi_kill_request(req, q);
                        continue;
                }
@@ -1512,7 +1509,6 @@ static void scsi_request_fn(struct request_queue *q)
         * cases (host limits or settings) should run the queue at some
         * later time.
         */
-       scsi_unprep_request(req);
        spin_lock_irq(q->queue_lock);
        blk_requeue_request(q, req);
        sdev->device_busy--;
@@ -1894,10 +1890,10 @@ scsi_device_set_state(struct scsi_device *sdev, enum scsi_device_state state)
 
  illegal:
        SCSI_LOG_ERROR_RECOVERY(1, 
-                               dev_printk(KERN_ERR, &sdev->sdev_gendev,
-                                          "Illegal state transition %s->%s\n",
-                                          scsi_device_state_name(oldstate),
-                                          scsi_device_state_name(state))
+                               sdev_printk(KERN_ERR, sdev,
+                                           "Illegal state transition %s->%s\n",
+                                           scsi_device_state_name(oldstate),
+                                           scsi_device_state_name(state))
                                );
        return -EINVAL;
 }