From patchwork Fri Mar 30 09:37:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitra P B X-Patchwork-Id: 10317477 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D7E1A60467 for ; Fri, 30 Mar 2018 09:40:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8A362A577 for ; Fri, 30 Mar 2018 09:40:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD2672A579; Fri, 30 Mar 2018 09:40:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BF762A577 for ; Fri, 30 Mar 2018 09:40:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751198AbeC3JkM (ORCPT ); Fri, 30 Mar 2018 05:40:12 -0400 Received: from mail-qk0-f195.google.com ([209.85.220.195]:41327 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752075AbeC3JjC (ORCPT ); Fri, 30 Mar 2018 05:39:02 -0400 Received: by mail-qk0-f195.google.com with SMTP id s78so8636708qkl.8 for ; Fri, 30 Mar 2018 02:39:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9vdZIh2HMwBd9RttGcrG/Ue9U/Gd7uzh4P6yyyJc9S4=; b=B8a3rCIFPqUnDbeLoZazSksCzv8aaAqe+Vh5B6PjJTuNk5P9wnKN9yzTNUIoVUugT4 ltfolUsw3R8RD32MD8bb9vOp47UF1xPFZGWBKX50EW/QEFVTiyTeYL4IN3Y+z445hVp2 oJKxvuJDkJfUNudToKKQ//jS+aSFobyFrhLN8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9vdZIh2HMwBd9RttGcrG/Ue9U/Gd7uzh4P6yyyJc9S4=; b=qKY/QRI3Pge6jwNnVifdOXXHxYnd8T2482asZn1r/MWV149rR1fSGQkUEb/1EiTYmK n7XJ9LBr1dNHL1/uobBIQr8KvVSVP3FRwpZKCI2TAAqk/hLefNO3RauBvK97zAeGPqLz 1UB5hZIVBNK3YKYreo49q+8eULCjx8C88Vy5aKQoSZy4XLWMAixHeAsHXPq+xhgnNvTm Iz0hRdQuMofKfdaVZc0ng6sGzhxt/0Zu8XwaT1sTu049Qn2uUs8VCO8hIihDcwOCCaMJ IQKQct4kdL+W4mTaQlVemwj0/5vnVuJjZWVK4+fqgWutY8DwSkNo7acD55KiELtjVXpy 7z/w== X-Gm-Message-State: ALQs6tCdSRyitxOOkD5sWbR0SIu0KgaHd2ljHcXFlu7qZYVMUOeEv7/e opJhM2jVDNbw+5TQCZJcwrkPT4op X-Google-Smtp-Source: AIpwx48AdpvGStKzc73NqHf5GYtiBjGSFY3jWkCxDNywasvGSn0oqJAow/3sgviLnf3tph4+gBBpVw== X-Received: by 10.55.214.150 with SMTP id p22mr15842324qkl.223.1522402741654; Fri, 30 Mar 2018 02:39:01 -0700 (PDT) Received: from dhcp-10-122-86-193.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id n4sm1125526qkf.29.2018.03.30.02.38.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Mar 2018 02:39:01 -0700 (PDT) From: Chaitra P B To: linux-scsi@vger.kernel.org, stable@vger.kernel.org Cc: suganath-prabu.subramani@broadcom.com, Sathya.Prakash@broadcom.com, sreekanth.reddy@broadcom.com, Chaitra P B Subject: [PATCH 03/15] mpt3sas: Add sanity checks for scsi tracker before accessing it. Date: Fri, 30 Mar 2018 15:07:12 +0530 Message-Id: <1522402644-3016-4-git-send-email-chaitra.basappa@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1522402644-3016-1-git-send-email-chaitra.basappa@broadcom.com> References: <1522402644-3016-1-git-send-email-chaitra.basappa@broadcom.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Check scsi tracker for NULL before accessing it. And in some places there are possibilities for getting valid st but still other fields are not set. Signed-off-by: Chaitra P B Signed-off-by: Suganath Prabu S --- drivers/scsi/mpt3sas/mpt3sas_ctl.c | 5 ++++- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c index c1b17d6..2f27d5c 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c +++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c @@ -590,7 +590,8 @@ _ctl_set_task_mid(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command *karg, struct scsiio_tracker *st; scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid); - if (!scmd) + if (scmd == NULL || scmd->device == NULL || + scmd->device->hostdata == NULL) continue; if (lun != scmd->device->lun) continue; @@ -600,6 +601,8 @@ _ctl_set_task_mid(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command *karg, if (priv_data->sas_target->handle != handle) continue; st = scsi_cmd_priv(scmd); + if ((!st) || (st->smid == 0)) + continue; tm_request->TaskMID = cpu_to_le16(st->smid); found = 1; } diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c index c9cce65..6b1aaa0 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -1465,7 +1465,7 @@ mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid) scmd = scsi_host_find_tag(ioc->shost, unique_tag); if (scmd) { st = scsi_cmd_priv(scmd); - if (st->cb_idx == 0xFF) + if ((!st) || (st->cb_idx == 0xFF) || (st->smid == 0)) scmd = NULL; } } @@ -4451,6 +4451,13 @@ _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc) count++; _scsih_set_satl_pending(scmd, false); st = scsi_cmd_priv(scmd); + /* + * It may be possible that SCSI scmd got prepared by SML + * but it has not issued to the driver, for these type of + * scmd's don't do anything" + */ + if (st && st->smid == 0) + continue; mpt3sas_base_clear_st(ioc, st); scsi_dma_unmap(scmd); if (ioc->pci_error_recovery)