From 308d30fbf49c0e7745e0fa0cb5e708b82bb75519 Mon Sep 17 00:00:00 2001 From: luojiaxing Date: Wed, 29 Aug 2018 10:43:47 +0800 Subject: [PATCH] scsi: hisi_sas: Fix the code logic issue of NULL pointer check about sas_port in func:hisi_sas_task_prep sas_port is a pointer passed by device->port,it accept non-zero check before running ahead to prevent a null pointer to be passed on. but some logic issue exist here that sas_port(device->port) was used before non-zero check,such as func: dev_to_hisi_hba lay on line 290 290 struct hisi_hba #hisi_hba = dev_to_hisi_hba(device) ^ The code of function:dev_to_hisi_hib is as blow: return device->port->ha->lldd_ha; Obviously,device->port is used before non-zero check for non-zero check begin at line 303 but dev_to_hisi_hba lay on line 290; so,to fix this bug,I need to shift some code and make sure sas_port which was used after non-zero check. Signed-off-by: luojiaxing Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c index de624c7f83d6..9252f0301022 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -303,13 +303,13 @@ static int hisi_sas_task_prep(struct sas_task *task, int *pass) { struct domain_device *device = task->dev; - struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); + struct hisi_hba *hisi_hba; struct hisi_sas_device *sas_dev = device->lldd_dev; struct hisi_sas_port *port; struct hisi_sas_slot *slot; struct hisi_sas_cmd_hdr *cmd_hdr_base; struct asd_sas_port *sas_port = device->port; - struct device *dev = hisi_hba->dev; + struct device *dev; int dlvry_queue_slot, dlvry_queue, rc, slot_idx; int n_elem = 0, n_elem_req = 0, n_elem_resp = 0; struct hisi_sas_dq *dq; @@ -330,6 +330,9 @@ static int hisi_sas_task_prep(struct sas_task *task, return -ECOMM; } + hisi_hba = dev_to_hisi_hba(device); + dev = hisi_hba->dev; + if (DEV_IS_GONE(sas_dev)) { if (sas_dev) dev_info(dev, "task prep: device %d not ready\n", -- GitLab