[SCSI] scsi_lib: fix potential NULL dereference
authorJiri Slaby <jirislaby@gmail.com>
Wed, 23 Sep 2009 14:15:35 +0000 (16:15 +0200)
committerJames Bottomley <James.Bottomley@suse.de>
Fri, 4 Dec 2009 18:00:51 +0000 (12:00 -0600)
Stanse found a potential NULL dereference in scsi_kill_request.

Instead of triggering BUG() in 'if (unlikely(cmd == NULL))' branch,
the kernel will Oops earlier on cmd dereference.

Move the dereferences after the if.

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
drivers/scsi/scsi_lib.c

index 108655230b59d3d55eb4593d16c9d7f22a566980..e495d3813948900bed56c497ba1649c73be889d3 100644 (file)
@@ -1359,9 +1359,9 @@ static int scsi_lld_busy(struct request_queue *q)
 static void scsi_kill_request(struct request *req, struct request_queue *q)
 {
        struct scsi_cmnd *cmd = req->special;
-       struct scsi_device *sdev = cmd->device;
-       struct scsi_target *starget = scsi_target(sdev);
-       struct Scsi_Host *shost = sdev->host;
+       struct scsi_device *sdev;
+       struct scsi_target *starget;
+       struct Scsi_Host *shost;
 
        blk_start_request(req);
 
@@ -1371,6 +1371,9 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
                BUG();
        }
 
+       sdev = cmd->device;
+       starget = scsi_target(sdev);
+       shost = sdev->host;
        scsi_init_cmd_errh(cmd);
        cmd->result = DID_NO_CONNECT << 16;
        atomic_inc(&cmd->device->iorequest_cnt);