Skip to content

Commit f4445bb

Browse files
GustavoARSilvamartinkpetersen
authored andcommitted
scsi: hisi_sas: Fix NULL pointer dereference
There is a NULL pointer dereference in case *slot* happens to be NULL at lines 1053 and 1878: struct hisi_sas_cq *cq = &hisi_hba->cq[slot->dlvry_queue]; Notice that *slot* is being NULL checked at lines 1057 and 1881: if (slot), which implies it may be NULL. Fix this by placing the declaration and definition of variable cq, which contains the pointer dereference slot->dlvry_queue, after slot has been properly NULL checked. Addresses-Coverity-ID: 1474515 ("Dereference before null check") Addresses-Coverity-ID: 1474520 ("Dereference before null check") Fixes: 584f53f ("scsi: hisi_sas: Fix the race between IO completion and timeout for SMP/internal IO") Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Reviewed-by: Xiang Chen <chenxiang66@hisilicon.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent d592dd6 commit f4445bb

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/scsi/hisi_sas/hisi_sas_main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,11 +1050,11 @@ static int hisi_sas_exec_internal_tmf_task(struct domain_device *device,
10501050
if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
10511051
if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
10521052
struct hisi_sas_slot *slot = task->lldd_task;
1053-
struct hisi_sas_cq *cq =
1054-
&hisi_hba->cq[slot->dlvry_queue];
10551053

10561054
dev_err(dev, "abort tmf: TMF task timeout and not done\n");
10571055
if (slot) {
1056+
struct hisi_sas_cq *cq =
1057+
&hisi_hba->cq[slot->dlvry_queue];
10581058
/*
10591059
* flush tasklet to avoid free'ing task
10601060
* before using task in IO completion
@@ -1875,10 +1875,10 @@ hisi_sas_internal_task_abort(struct hisi_hba *hisi_hba,
18751875
if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
18761876
if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
18771877
struct hisi_sas_slot *slot = task->lldd_task;
1878-
struct hisi_sas_cq *cq =
1879-
&hisi_hba->cq[slot->dlvry_queue];
18801878

18811879
if (slot) {
1880+
struct hisi_sas_cq *cq =
1881+
&hisi_hba->cq[slot->dlvry_queue];
18821882
/*
18831883
* flush tasklet to avoid free'ing task
18841884
* before using task in IO completion

0 commit comments

Comments
 (0)