Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4885154pjb; Mon, 27 Jul 2020 07:34:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqa3YV+hTEmpr7ROfEjyf0clLykhXvLErTtaVcxeACkUQvATtCM2oZZDbiEdDLByvecR7E X-Received: by 2002:aa7:cd08:: with SMTP id b8mr5207401edw.228.1595860492873; Mon, 27 Jul 2020 07:34:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595860492; cv=none; d=google.com; s=arc-20160816; b=yzgSkXBabSWNO+8ss3uPZ4UH7w4zSF7J+bf4A8IuRa6diRGJYe2HDJslSjMmgTGxz2 wQVLq6CNL4/L742VMNDjG5OPeT+n/gvMuVmiXd6KyCoTlGZybRqZ5vsHUZTfTobOMchv BdyeY4s3Twv9E74HmBTlFNsc97iGoMHQEFaKyo/ZYb+ZsSsOMOVPqyh8yGACN1visBkw N/0aIp6x/axXHzZmrsxrUeLngCq+kAGmsK5OdTWjdClsHBgOLue2T6yx9poAre5U/vIL agIkW0OTPTFzfcgBN6zrQ/xvG6Y74Udg+7nG130LRP+sG98a0XIOWHQLTg/CkwzcwT3P DeFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ORk2wWZVgR9b9zgmBmg5IIqHk7nXqoZPTlDqnLmXEiM=; b=TyY6NZu3rOXQBKn5psS2WgrMI457IJW6qxGYwJofF3SV3bFqZtTLtyox8MWcJDYsmr 9GRH4xLfx9oNuiTZ6q9QpEI1WXRwS6hzly/V54FeUE89zOUWDWdWJQCv1j+mwmp2MOqp IkUTdKlRb5FjbQ692k4EntJi8qp1uoWnDEfdRm0ylqEyYSGlMwiFvcD4hLkNszhPENS5 PjvSnPJT/CRz0Y7wpsDljbrtpT7pCBAXWbyFiSpfldZLajk3gUILGgNwoC7+t25Q0jgD dXV2SrQm9SAe916fub3Vzh7cYR9uECEUW2NZdAPugfCcezCEJEiBxRkIvuIIOI1OcFj/ qEXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qifkfn3A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u8si1662643eda.396.2020.07.27.07.34.30; Mon, 27 Jul 2020 07:34:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qifkfn3A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732839AbgG0OcR (ORCPT + 99 others); Mon, 27 Jul 2020 10:32:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:47058 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730406AbgG0OTN (ORCPT ); Mon, 27 Jul 2020 10:19:13 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 03AD020775; Mon, 27 Jul 2020 14:19:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859552; bh=GAFcz6VMhCl4x1qHq3sS9k3Cf5CjbBVOHTbT3FSCZ9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qifkfn3AjvJ1KHOMBhHG8nrWhBDVYb01Rqa2hc9BQ3QpsItHvjN0hbxJAbFEz64+r gewkA4Yos29Bjb5th47buwpdqd+phDFBl2gieVwL5JSJCh1jrk7iNZldFRZcmeRH9t 9KiyOS9esKLlIaaBB8ipfzJe1hwEtNR734ulXUJY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Damien Le Moal , Sreekanth Reddy , Johannes Thumshirn , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.7 015/179] scsi: mpt3sas: Fix error returns in BRM_status_show Date: Mon, 27 Jul 2020 16:03:10 +0200 Message-Id: <20200727134933.416219782@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134932.659499757@linuxfoundation.org> References: <20200727134932.659499757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johannes Thumshirn [ Upstream commit 0fd181456aa0826057adbfb6c79c40f4083cfd75 ] BRM_status_show() has several error branches, but none of them record the error in the error return. Also while at it remove the manual mutex_unlock() of the pci_access_mutex in case of an ongoing pci error recovery or host removal and jump to the cleanup label instead. Note: We can safely jump to out from here as io_unit_pg3 is initialized to NULL and if it hasn't been allocated, kfree() skips the NULL pointer. [mkp: compilation warning] Link: https://lore.kernel.org/r/20200701131454.5255-1-johannes.thumshirn@wdc.com Reviewed-by: Damien Le Moal Acked-by: Sreekanth Reddy Signed-off-by: Johannes Thumshirn Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/mpt3sas/mpt3sas_ctl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c index e94e72de2fc68..983e568ff2317 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c +++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c @@ -3149,15 +3149,14 @@ BRM_status_show(struct device *cdev, struct device_attribute *attr, } /* pci_access_mutex lock acquired by sysfs show path */ mutex_lock(&ioc->pci_access_mutex); - if (ioc->pci_error_recovery || ioc->remove_host) { - mutex_unlock(&ioc->pci_access_mutex); - return 0; - } + if (ioc->pci_error_recovery || ioc->remove_host) + goto out; /* allocate upto GPIOVal 36 entries */ sz = offsetof(Mpi2IOUnitPage3_t, GPIOVal) + (sizeof(u16) * 36); io_unit_pg3 = kzalloc(sz, GFP_KERNEL); if (!io_unit_pg3) { + rc = -ENOMEM; ioc_err(ioc, "%s: failed allocating memory for iounit_pg3: (%d) bytes\n", __func__, sz); goto out; @@ -3167,6 +3166,7 @@ BRM_status_show(struct device *cdev, struct device_attribute *attr, 0) { ioc_err(ioc, "%s: failed reading iounit_pg3\n", __func__); + rc = -EINVAL; goto out; } @@ -3174,12 +3174,14 @@ BRM_status_show(struct device *cdev, struct device_attribute *attr, if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { ioc_err(ioc, "%s: iounit_pg3 failed with ioc_status(0x%04x)\n", __func__, ioc_status); + rc = -EINVAL; goto out; } if (io_unit_pg3->GPIOCount < 25) { ioc_err(ioc, "%s: iounit_pg3->GPIOCount less than 25 entries, detected (%d) entries\n", __func__, io_unit_pg3->GPIOCount); + rc = -EINVAL; goto out; } -- 2.25.1