scsi: pm80xx: Fix TMF task completion race condition
authorIgor Pylypiv <ipylypiv@google.com>
Wed, 7 Jul 2021 18:59:45 +0000 (11:59 -0700)
committerSasha Levin <sashal@kernel.org>
Thu, 26 Aug 2021 12:35:36 +0000 (08:35 -0400)
commit968ee9176a4489ce6d5ee54ff88dadfbff9b95f4
treee2840b742f4ea7a5fc2e3483b7caab5f91f3bf98
parentb353028aed9231214e45dd21274c444870c68dc2
scsi: pm80xx: Fix TMF task completion race condition

[ Upstream commit d712d3fb484b7fa8d1d57e9ca6f134bb9d8c18b1 ]

The TMF timeout timer may trigger at the same time when the response from a
controller is being handled. When this happens the SAS task may get freed
before the response processing is finished.

Fix this by calling complete() only when SAS_TASK_STATE_DONE is not set.

A similar race condition was fixed in commit b90cd6f2b905 ("scsi: libsas:
fix a race condition when smp task timeout")

Link: https://lore.kernel.org/r/20210707185945.35559-1-ipylypiv@google.com
Reviewed-by: Vishakha Channapattan <vishakhavc@google.com>
Acked-by: Jack Wang <jinpu.wang@ionos.com>
Signed-off-by: Igor Pylypiv <ipylypiv@google.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/scsi/pm8001/pm8001_sas.c