From patchwork Fri Nov 9 14:06:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 150648 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp210616ljp; Fri, 9 Nov 2018 06:06:00 -0800 (PST) X-Google-Smtp-Source: AJdET5djyGQZdNdomZ29CYmJt0PVfGQdo82bcgxp3O9+0L88QN7E5og/1pCA4T2PuLL1OZHRB4L5 X-Received: by 2002:a62:34c5:: with SMTP id b188-v6mr9539126pfa.65.1541772360341; Fri, 09 Nov 2018 06:06:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541772360; cv=none; d=google.com; s=arc-20160816; b=qd+KkOdtd2YdRGK9zDd1yZo9zVmQmdfsXbMDjlL1Q1Q8Pqi8mooanDOJIlQEy367/3 +kA1EUNAmYdMPz6wTsw0hCcSu1uhljHj3FAf7sO46pz2ejdBluq4QyWd4JV6O3D+Peen sdCZJ05LWq3UwHQEXeADiHXU9GzIbb4YNwDzUNnMsNlqewOuL90bKLPIjoH05dxIBBlK TsRnGlT6a3CTI90EQ+HNil84pcItrgto9HL6jskDW5UJLkr+qjfiAL73E//NsEo4830e 0qcmW68ZT9jbie+KYol+snyOazS8gUKIbrS8xJKhPasg8HAqA5QfFZfo6RkxH7/jNCB0 6Qtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=ONrGvP2eAMApFCEmnbVPzIMKsBRAMi3UOv1oSx4lC4U=; b=pUjUBkgdTGz3DETqbthMzpPhHwEUUFPWU2VK0b4U8sLi9bgVHBiGhDaayepPKBf6nE 6PZkwn6cNWVu4VjMGFNiqHKeISb3w2+kFscICss+sKyYs6ml0BbLWAPsjAlaG7UNMcfw O0m2ClST+2v7K6wK291rGpTTivg7CkywCYp9tRPK/vjNsUOM6Qz1wxZrIXlPkPKuTa2i JwYB1rvhXH1VxKInRt3M6xD59fnggQ5CdPhmav7JblqBFcFvoGGq4e+cV4jVuhjF6JRy dVSzppzGhZejWRpCpPExvpeInt/dATB08mhNtUyqdO4rSppERmFXTrB1iO7E9lH/+WHT +Rzw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-scsi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l184si6806759pgd.523.2018.11.09.06.06.00; Fri, 09 Nov 2018 06:06:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-scsi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-scsi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728299AbeKIXpx (ORCPT + 1 other); Fri, 9 Nov 2018 18:45:53 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:47746 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728237AbeKIXpx (ORCPT ); Fri, 9 Nov 2018 18:45:53 -0500 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id E644027BFF968; Fri, 9 Nov 2018 22:05:04 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.408.0; Fri, 9 Nov 2018 22:04:56 +0800 From: John Garry To: , CC: , , , Xiang Chen , John Garry Subject: [PATCH 4/5] scsi: hisi_sas: Relocate some codes to avoid an unused check Date: Fri, 9 Nov 2018 22:06:35 +0800 Message-ID: <1541772396-161814-5-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1541772396-161814-1-git-send-email-john.garry@huawei.com> References: <1541772396-161814-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Xiang Chen In function hisi_sas_task_prep(), we check asd_sas_port, but in function hisi_sas_task_exec(), we already refer to asd_sas_port by using function dev_to_hisi_hba() implicitly. So to avoid this possible invalid dereference, relocate the check to function hisi_sas_task_prep(). Signed-off-by: Xiang Chen Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_main.c | 44 ++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 21 deletions(-) -- 1.9.1 diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c index 8633ff9..65dc749 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -302,36 +302,19 @@ static int hisi_sas_task_prep(struct sas_task *task, int *pass) { struct domain_device *device = task->dev; - struct hisi_hba *hisi_hba; + struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); 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; + struct device *dev = hisi_hba->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; unsigned long flags; int wr_q_index; - if (!sas_port) { - struct task_status_struct *ts = &task->task_status; - - ts->resp = SAS_TASK_UNDELIVERED; - ts->stat = SAS_PHY_DOWN; - /* - * libsas will use dev->port, should - * not call task_done for sata - */ - if (device->dev_type != SAS_SATA_DEV) - task->task_done(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", @@ -506,10 +489,29 @@ static int hisi_sas_task_exec(struct sas_task *task, gfp_t gfp_flags, u32 rc; u32 pass = 0; unsigned long flags; - struct hisi_hba *hisi_hba = dev_to_hisi_hba(task->dev); - struct device *dev = hisi_hba->dev; + struct hisi_hba *hisi_hba; + struct device *dev; + struct domain_device *device = task->dev; + struct asd_sas_port *sas_port = device->port; struct hisi_sas_dq *dq = NULL; + if (!sas_port) { + struct task_status_struct *ts = &task->task_status; + + ts->resp = SAS_TASK_UNDELIVERED; + ts->stat = SAS_PHY_DOWN; + /* + * libsas will use dev->port, should + * not call task_done for sata + */ + if (device->dev_type != SAS_SATA_DEV) + task->task_done(task); + return -ECOMM; + } + + hisi_hba = dev_to_hisi_hba(device); + dev = hisi_hba->dev; + if (unlikely(test_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags))) { if (in_softirq()) return -EINVAL;