]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commit
scsi: hisi_sas: fix the risk of freeing slot twice
authorXiaofei Tan <tanxiaofei@huawei.com>
Tue, 24 Oct 2017 15:51:38 +0000 (23:51 +0800)
committerMartin K. Petersen <martin.petersen@oracle.com>
Wed, 25 Oct 2017 12:21:04 +0000 (08:21 -0400)
commit6ba0fbc35aa9f3bc8c12be3b4047055c9ce2ac92
treec1d5ddccad7d1372fe708aed3d968ec278d01ae1
parent378c233bcb21dfb2d9c2548b9a1fa6a8d35c78dd
scsi: hisi_sas: fix the risk of freeing slot twice

The function hisi_sas_slot_task_free() is used to free the slot and do
tidy-up of LLDD resources. The LLDD generally should know the state of
a slot and decide when to free it, and it should only be done once.

For some scenarios, we really don't know the state, like when TMF
timeout. In this case, we check task->lldd_task before calling
hisi_sas_slot_task_free().

However, we may miss some scenarios when we should also check
task->lldd_task, and it is not SMP safe to check task->lldd_task as we
don't protect it within spin lock.

This patch is to fix this risk of freeing slot twice, as follows:

  1. Check task->lldd_task in the hisi_sas_slot_task_free(), and give
     up freeing of this time if task->lldd_task is NULL.

  2. Set slot->buf to NULL after it is freed.

Signed-off-by: Xiaofei Tan <tanxiaofei@huawei.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/hisi_sas/hisi_sas_main.c