From patchwork Wed May 9 15:10:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 135292 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp5760210lji; Wed, 9 May 2018 08:12:23 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpwvxhgbbIBmZHZwztdaWvWzsXtbmEyT3yPEqf5xuERW2zVdBZmzIiZtnq5JffTFkpdttCH X-Received: by 2002:a17:902:28e8:: with SMTP id f95-v6mr46950351plb.250.1525878742957; Wed, 09 May 2018 08:12:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525878742; cv=none; d=google.com; s=arc-20160816; b=xpH5H7IVLLyhj1lmHGmljE4h30ifgWNegeewwxz5jsXMLQQ61UeQ6hIuiy3XKM8Pjf 7lmalfSQYP9yHvcdnMLiELcLPLSRLjcNOaaUcWGmG5VpIG59hCEKREPh+OqcoF/dDm11 4QxPSSQhh3G8P70Ul+k868CmRhLrvR89sLWixru+gw3nf98iheH6j/JHG2/qXP9DFWoe 4HrdVdmKf0UHslM/8xtVpYbKKxLPCftfyxl/LaS95BM0o965XCBE0Z3tcTdKReGc8RN6 iZ0McGTDjwbTJqhAjFGK71Dj3uYi6/2nyU4VyhbGWSPWf+C5xaM5Tj68D4y48cfZX7JY mIhg== 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:arc-authentication-results; bh=5nRjd+Bjs5Su0qjEV/LSMMw6wTB2PdLVPxadhLTDGx0=; b=IkT4r4zQhWoz6rlP1c7aaYZ1CkUZvl7mXRrif4GuhgAjvnppXZm/NrPH28jE9oUFNO iqmnMWluSsC3k18/imFWGC/UuoBIqKm/u70ESFtMu5PExFaiFbwp+r28Ifc9hB3xsAyk onOLLJwCPJUcuEhKZUFqio8gj0Sy6Du+GuyyJeuUz/KcxpCis8+kr3QyD6+ekFw+115f /fGhp7p/qsDLTToompbgLPRAxjWEuIMVnSSObetnxumnuyuf9+fdDMM3TH+EPXkBVYwu A1VG1sxu5C6PtLQCsOjp2DB2UxdWP3PTMz8YFw8z4wbTQMoKYUqpVQMj4Czkf2RRzc9B bL+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 b73-v6si27036357pli.305.2018.05.09.08.12.22; Wed, 09 May 2018 08:12:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964886AbeEIPMS (ORCPT + 29 others); Wed, 9 May 2018 11:12:18 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:47084 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S964834AbeEIPMN (ORCPT ); Wed, 9 May 2018 11:12:13 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 221E068715EE8; Wed, 9 May 2018 23:12:08 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.361.1; Wed, 9 May 2018 23:12:01 +0800 From: John Garry To: , CC: , , , Xiaofei Tan , "John Garry" Subject: [PATCH 6/6] scsi: hisi_sas: add check of device in hisi_sas_task_exec() Date: Wed, 9 May 2018 23:10:50 +0800 Message-ID: <1525878650-213087-7-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525878650-213087-1-git-send-email-john.garry@huawei.com> References: <1525878650-213087-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiaofei Tan Currently we don't check that device is not gone before dereferencing it's elements in the function hisi_sas_task_exec() (specifically, the DQ pointer). This patch fixes this issue by filling in the DQ pointer in hisi_sas_task_prep(), after we check that the device pointer is still safe to reference. Signed-off-by: Xiaofei Tan Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_main.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 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 a451625..39f694e 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -310,12 +310,13 @@ static void hisi_sas_slot_abort(struct work_struct *work) task->task_done(task); } -static int hisi_sas_task_prep(struct sas_task *task, struct hisi_sas_dq *dq, +static int hisi_sas_task_prep(struct sas_task *task, + struct hisi_sas_dq **dq_pointer, int is_tmf, struct hisi_sas_tmf_task *tmf, int *pass) { - struct hisi_hba *hisi_hba = dq->hisi_hba; struct domain_device *device = task->dev; + 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; @@ -323,8 +324,9 @@ static int hisi_sas_task_prep(struct sas_task *task, struct hisi_sas_dq *dq, struct asd_sas_port *sas_port = device->port; 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; + int n_elem = 0, n_elem_req = 0, n_elem_resp = 0; unsigned long flags, flags_dq; + struct hisi_sas_dq *dq; int wr_q_index; if (!sas_port) { @@ -352,6 +354,8 @@ static int hisi_sas_task_prep(struct sas_task *task, struct hisi_sas_dq *dq, return -ECOMM; } + *dq_pointer = dq = sas_dev->dq; + port = to_hisi_sas_port(sas_port); if (port && !port->port_attached) { dev_info(dev, "task prep: %s port%d not attach device\n", @@ -520,22 +524,21 @@ static int hisi_sas_task_exec(struct sas_task *task, gfp_t gfp_flags, unsigned long flags; struct hisi_hba *hisi_hba = dev_to_hisi_hba(task->dev); struct device *dev = hisi_hba->dev; - struct domain_device *device = task->dev; - struct hisi_sas_device *sas_dev = device->lldd_dev; - struct hisi_sas_dq *dq = sas_dev->dq; + struct hisi_sas_dq *dq = NULL; if (unlikely(test_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags))) return -EINVAL; /* protect task_prep and start_delivery sequence */ - rc = hisi_sas_task_prep(task, dq, is_tmf, tmf, &pass); + rc = hisi_sas_task_prep(task, &dq, is_tmf, tmf, &pass); if (rc) dev_err(dev, "task exec: failed[%d]!\n", rc); - spin_lock_irqsave(&dq->lock, flags); - if (likely(pass)) + if (likely(pass)) { + spin_lock_irqsave(&dq->lock, flags); hisi_hba->hw->start_delivery(dq); - spin_unlock_irqrestore(&dq->lock, flags); + spin_unlock_irqrestore(&dq->lock, flags); + } return rc; }