[RFC][PATCH 4/8] Fix a bug in scsi_get_command

Matthew Dobson
2005-11-18T19:41:19Z

[-- Attachment #1: Type: text/plain, Size: 104 bytes --]

Testing this patch series uncovered a small bug in scsi_get_command. This
patch fixes that bug.

-Matt

[-- Attachment #2: scsi_get_command-fix.patch --]
[-- Type: text/x-patch, Size: 958 bytes --]

scsi_get_command() attempts to write into a structure that may not have been
successfully allocated. Move this write inside the if statement that ensures
we won't panic the kernel with a NULL pointer dereference.

Signed-off-by: Matthew Dobson <colpatch@us.ibm.com>

Index: linux-2.6.15-rc1+critical_pool/drivers/scsi/scsi.c
===================================================================
--- linux-2.6.15-rc1+critical_pool.orig/drivers/scsi/scsi.c 2005-11-15 13:45:38.000000000 -0800
+++ linux-2.6.15-rc1+critical_pool/drivers/scsi/scsi.c 2005-11-17 16:49:54.279656112 -0800
@@ -265,10 +265,10 @@ struct scsi_cmnd *scsi_get_command(struc
spin_lock_irqsave(&dev->list_lock, flags);
list_add_tail(&cmd->list, &dev->cmd_list);
spin_unlock_irqrestore(&dev->list_lock, flags);
+ cmd->jiffies_at_alloc = jiffies;
} else
put_device(&dev->sdev_gendev);

- cmd->jiffies_at_alloc = jiffies;
return cmd;
}
EXPORT_SYMBOL(scsi_get_command);