From 65d2e9804a7ccd7e52321c9f1803afdfbbecad8e Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Wed, 23 Sep 2009 16:15:35 +0200 Subject: [PATCH] SCSI: scsi_lib: fix potential NULL dereference commit 03b147083a2f9a2a3fbbd2505fa88ffa3c6ab194 upstream. 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. [ WT: starget is not set in 2.6.27 ] Signed-off-by: Jiri Slaby Signed-off-by: James Bottomley Signed-off-by: Greg Kroah-Hartman Signed-off-by: Willy Tarreau --- drivers/scsi/scsi_lib.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 9899f6e4c5e86..88ed1eea273c5 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1389,8 +1389,8 @@ static inline int scsi_host_queue_ready(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_Host *shost = sdev->host; + struct scsi_device *sdev; + struct Scsi_Host *shost; blkdev_dequeue_request(req); @@ -1402,6 +1402,8 @@ static void scsi_kill_request(struct request *req, struct request_queue *q) scmd_printk(KERN_INFO, cmd, "killing request\n"); + sdev = cmd->device; + shost = sdev->host; scsi_init_cmd_errh(cmd); cmd->result = DID_NO_CONNECT << 16; atomic_inc(&cmd->device->iorequest_cnt); -- 2.47.2