From: Tomas Henzl Date: Thu, 1 Aug 2013 13:14:00 +0000 (+0200) Subject: [SCSI] hpsa: fix a race in cmd_free/scsi_done X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=2cc5bfaf854463d9d1aa52091f60110fbf102a96;p=sagit-ice-cold%2Fkernel_xiaomi_msm8998.git [SCSI] hpsa: fix a race in cmd_free/scsi_done When the driver calls scsi_done and after that frees it's internal preallocated memory it can happen that a new job is enqueud before the memory is freed. The allocation fails and the message "cmd_alloc returned NULL" is shown. Patch below fixes it by moving cmd->scsi_done after cmd_free. Signed-off-by: Tomas Henzl Acked-by: Stephen M. Cameron Signed-off-by: James Bottomley --- diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c index 7f4f790a3d71..21fd2b182ec9 100644 --- a/drivers/scsi/hpsa.c +++ b/drivers/scsi/hpsa.c @@ -1205,8 +1205,8 @@ static void complete_scsi_command(struct CommandList *cp) scsi_set_resid(cmd, ei->ResidualCnt); if (ei->CommandStatus == 0) { - cmd->scsi_done(cmd); cmd_free(h, cp); + cmd->scsi_done(cmd); return; } @@ -1379,8 +1379,8 @@ static void complete_scsi_command(struct CommandList *cp) dev_warn(&h->pdev->dev, "cp %p returned unknown status %x\n", cp, ei->CommandStatus); } - cmd->scsi_done(cmd); cmd_free(h, cp); + cmd->scsi_done(cmd); } static void hpsa_pci_unmap(struct pci_dev *pdev,