From patchwork Thu Mar 2 23:43:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomas Henzl X-Patchwork-Id: 13158066 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3AB52C7EE33 for ; Thu, 2 Mar 2023 23:44:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229919AbjCBXoe (ORCPT ); Thu, 2 Mar 2023 18:44:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230006AbjCBXoa (ORCPT ); Thu, 2 Mar 2023 18:44:30 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67CB4F94D for ; Thu, 2 Mar 2023 15:43:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677800622; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2k+GP5w/mW8CW/5OpAFEff9AAlcLynxkVrT/Xx5WWIw=; b=bRL/qQTlFjetHO+/5suyezqtaNG7LXlje7RjavretnjaT3gB6hYmxsJR60t8AeCQBHue38 gRTnr9z9V94NAn6YDmaxpWqmhEpSfst6tkuAiO34WA4VIh1YkHTAxSdoYG6kRmbFXkzkId 2+VbrKKtwbIJUu+YAMbJOLiHssWFnHk= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-135-VyW2eRu7NkWjkppiMPYgXg-1; Thu, 02 Mar 2023 18:43:39 -0500 X-MC-Unique: VyW2eRu7NkWjkppiMPYgXg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 15D773C0CD43; Thu, 2 Mar 2023 23:43:39 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.45.225.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63D2B140EBF6; Thu, 2 Mar 2023 23:43:38 +0000 (UTC) From: Tomas Henzl To: linux-scsi@vger.kernel.org Cc: sreekanth.reddy@broadcom.com, sathya.prakash@broadcom.com, ranjan.kumar@broadcom.com Subject: [PATCH v2 1/6] scsi: mpi3mr: fix a memory leak Date: Fri, 3 Mar 2023 00:43:31 +0100 Message-Id: <20230302234336.25456-2-thenzl@redhat.com> In-Reply-To: <20230302234336.25456-1-thenzl@redhat.com> References: <20230302234336.25456-1-thenzl@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add a missing kfree. Fixes: f10af057325c ("scsi: mpi3mr: Resource Based Metering") Signed-off-by: Tomas Henzl --- drivers/scsi/mpi3mr/mpi3mr_fw.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c index ab8326b532e7..b632e1bb1007 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_fw.c +++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c @@ -4403,6 +4403,9 @@ void mpi3mr_free_mem(struct mpi3mr_ioc *mrioc) mrioc->pel_seqnum_virt = NULL; } + kfree(mrioc->throttle_groups); + mrioc->throttle_groups = NULL; + kfree(mrioc->logdata_buf); mrioc->logdata_buf = NULL; From patchwork Thu Mar 2 23:43:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomas Henzl X-Patchwork-Id: 13158064 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60927C6FA8E for ; Thu, 2 Mar 2023 23:44:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230039AbjCBXoc (ORCPT ); Thu, 2 Mar 2023 18:44:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229995AbjCBXoa (ORCPT ); Thu, 2 Mar 2023 18:44:30 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6645317147 for ; Thu, 2 Mar 2023 15:43:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677800623; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H93esuvA4JaKC7HBC5maYBDA3al7sKvyeix+fTRm7DQ=; b=MXgliXUqGLGUEmdes0FYWnjq9YfFRkllyAN0Sw8R0KzIgyrs5oOrd4smF0sfwaffzAV4dU JEhhEwUaJbGE3wZc8MiowT56PYuR9DFQVYWEcU5ZFYx2KkgPxtVKJ8RVnVcyBMcRFOaAbo +/CR9SRsogHG84eft414vBgNnFv6Fy8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-206-y92H4oRJN02sY6Nxcy9a0w-1; Thu, 02 Mar 2023 18:43:40 -0500 X-MC-Unique: y92H4oRJN02sY6Nxcy9a0w-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F022F100F908; Thu, 2 Mar 2023 23:43:39 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.45.225.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4AA81140EBF6; Thu, 2 Mar 2023 23:43:39 +0000 (UTC) From: Tomas Henzl To: linux-scsi@vger.kernel.org Cc: sreekanth.reddy@broadcom.com, sathya.prakash@broadcom.com, ranjan.kumar@broadcom.com Subject: [PATCH v2 2/6] scsi: mpi3mr: fix a dma memory leak Date: Fri, 3 Mar 2023 00:43:32 +0100 Message-Id: <20230302234336.25456-3-thenzl@redhat.com> In-Reply-To: <20230302234336.25456-1-thenzl@redhat.com> References: <20230302234336.25456-1-thenzl@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org A fix for: DMA-API: pci 0000:83:00.0: device driver has pending DMA allocations while released from device [count=1] Fixes: 32d457d5a2af ("scsi: mpi3mr: Add framework to issue config requests") Signed-off-by: Tomas Henzl --- drivers/scsi/mpi3mr/mpi3mr_fw.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c index b632e1bb1007..fa62991f5aee 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_fw.c +++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c @@ -4396,7 +4396,11 @@ void mpi3mr_free_mem(struct mpi3mr_ioc *mrioc) mrioc->admin_req_base, mrioc->admin_req_dma); mrioc->admin_req_base = NULL; } - + if (mrioc->cfg_page) { + dma_free_coherent(&mrioc->pdev->dev, mrioc->cfg_page_sz, + mrioc->cfg_page, mrioc->cfg_page_dma); + mrioc->cfg_page = NULL; + } if (mrioc->pel_seqnum_virt) { dma_free_coherent(&mrioc->pdev->dev, mrioc->pel_seqnum_sz, mrioc->pel_seqnum_virt, mrioc->pel_seqnum_dma); From patchwork Thu Mar 2 23:43:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomas Henzl X-Patchwork-Id: 13158065 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11B40C7EE30 for ; Thu, 2 Mar 2023 23:44:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230048AbjCBXod (ORCPT ); Thu, 2 Mar 2023 18:44:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230019AbjCBXoa (ORCPT ); Thu, 2 Mar 2023 18:44:30 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC253193CB for ; Thu, 2 Mar 2023 15:43:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677800624; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=44Bqd6yotCCK5/7jBJ/mmuc4gWLU35hi5f1+zPBfLeo=; b=FCoNErtrHI/rMLoC+eD/c8pkjWPj4i90aZRfB9JB+OydsrGTuFm/zpTiKc6C44VUYCJ8En vQzIC+XYUswRaSvjZqMSmgmuI1gJ9yAyt/atmfiFfNK9lW5mvF5lDnKVcTwYXEg3Wi/Lu+ ZTzrXpggp/2/h/yfmfSYTMWJjznNGkE= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-479-Yu_j-P8FNbOuQxCCNl8Ubg-1; Thu, 02 Mar 2023 18:43:41 -0500 X-MC-Unique: Yu_j-P8FNbOuQxCCNl8Ubg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D5E7C3C0CD46; Thu, 2 Mar 2023 23:43:40 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.45.225.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30692140EBF6; Thu, 2 Mar 2023 23:43:40 +0000 (UTC) From: Tomas Henzl To: linux-scsi@vger.kernel.org Cc: sreekanth.reddy@broadcom.com, sathya.prakash@broadcom.com, ranjan.kumar@broadcom.com Subject: [PATCH v2 3/6] scsi: mpi3mr: fix a memory leak Date: Fri, 3 Mar 2023 00:43:33 +0100 Message-Id: <20230302234336.25456-4-thenzl@redhat.com> In-Reply-To: <20230302234336.25456-1-thenzl@redhat.com> References: <20230302234336.25456-1-thenzl@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Free mpi3mr_hba_port at .remove. Fixes: 42fc9fee116f ("scsi: mpi3mr: Add helper functions to manage device's port") Signed-off-by: Tomas Henzl --- drivers/scsi/mpi3mr/mpi3mr_os.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c index 6f9230a079c3..85bd45563686 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_os.c +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c @@ -5112,6 +5112,7 @@ static void mpi3mr_remove(struct pci_dev *pdev) struct workqueue_struct *wq; unsigned long flags; struct mpi3mr_tgt_dev *tgtdev, *tgtdev_next; + struct mpi3mr_hba_port *port, *hba_port_next; if (!shost) return; @@ -5151,6 +5152,16 @@ static void mpi3mr_remove(struct pci_dev *pdev) mpi3mr_free_mem(mrioc); mpi3mr_cleanup_resources(mrioc); + spin_lock_irqsave(&mrioc->sas_node_lock, flags); + list_for_each_entry_safe(port, hba_port_next, &mrioc->hba_port_table_list, list) { + ioc_info(mrioc, + "removing hba_port entry: %p port: %d from hba_port list\n", + port, port->port_id); + list_del(&port->list); + kfree(port); + } + spin_unlock_irqrestore(&mrioc->sas_node_lock, flags); + spin_lock(&mrioc_list_lock); list_del(&mrioc->list); spin_unlock(&mrioc_list_lock); From patchwork Thu Mar 2 23:43:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomas Henzl X-Patchwork-Id: 13158063 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5F78C678D4 for ; Thu, 2 Mar 2023 23:44:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230037AbjCBXob (ORCPT ); Thu, 2 Mar 2023 18:44:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229986AbjCBXoa (ORCPT ); Thu, 2 Mar 2023 18:44:30 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 542A816AEE for ; Thu, 2 Mar 2023 15:43:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677800623; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JhUYLyZwZuUhpnWFnebVE++9cb4qmQcum/DaC5jAenI=; b=ToTMzC6eC8kzLw4p04z1GpJtcPwA2SMH7lRRLLoHSFhslDzYPCBLD98WTDdCNdtEEH7kbj SbzgjXwvcseDz06ezFpwg23v8dXqk/izUMIdAMqJTbSqdjR4JioQA/VpioSvS68ZWSV7G/ MjFAhE2c+2Zv0M0ynLzcwh531jselzM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-190-jwcqX96nOXWEcUoKROWUug-1; Thu, 02 Mar 2023 18:43:42 -0500 X-MC-Unique: jwcqX96nOXWEcUoKROWUug-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BBCAB100F908; Thu, 2 Mar 2023 23:43:41 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.45.225.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 15D37140EBF6; Thu, 2 Mar 2023 23:43:40 +0000 (UTC) From: Tomas Henzl To: linux-scsi@vger.kernel.org Cc: sreekanth.reddy@broadcom.com, sathya.prakash@broadcom.com, ranjan.kumar@broadcom.com Subject: [PATCH v2 4/6] scsi: mpi3mr: fix a memory leak Date: Fri, 3 Mar 2023 00:43:34 +0100 Message-Id: <20230302234336.25456-5-thenzl@redhat.com> In-Reply-To: <20230302234336.25456-1-thenzl@redhat.com> References: <20230302234336.25456-1-thenzl@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Free mrioc->sas_hba.phy at .remove. Fixes: 42fc9fee116f ("scsi: mpi3mr: Add helper functions to manage device's port") Signed-off-by: Tomas Henzl --- drivers/scsi/mpi3mr/mpi3mr_os.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c index 85bd45563686..8f17a7953eb4 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_os.c +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c @@ -5162,6 +5162,12 @@ static void mpi3mr_remove(struct pci_dev *pdev) } spin_unlock_irqrestore(&mrioc->sas_node_lock, flags); + if (mrioc->sas_hba.num_phys) { + kfree(mrioc->sas_hba.phy); + mrioc->sas_hba.phy = NULL; + mrioc->sas_hba.num_phys = 0; + } + spin_lock(&mrioc_list_lock); list_del(&mrioc->list); spin_unlock(&mrioc_list_lock); From patchwork Thu Mar 2 23:43:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomas Henzl X-Patchwork-Id: 13158068 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4FE77C6FA8E for ; Thu, 2 Mar 2023 23:45:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229586AbjCBXpM (ORCPT ); Thu, 2 Mar 2023 18:45:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230006AbjCBXpK (ORCPT ); Thu, 2 Mar 2023 18:45:10 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F06EC1E2A4 for ; Thu, 2 Mar 2023 15:43:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677800628; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nPZrBx/6dV+/Sn4fLfhXgkf/cQwKCEfzZ3JUOeUGUKU=; b=cwkYpBMyBfXeqwR8pMCJm5kZhzr8F8thGmLEyGQBTSNyaC0N+FY4qNI8VlFbqtGgOVAZ7i /C/nMVBfZGULX0B3uNUBdqqGu5hm24apaupiVRqdRJVelWvCkFyYN1YXmIxFnE3aHShZq3 j60wWDvaePlCGMFjBoHyoNgqCT1QXnk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-266-9gzNEtgJP8qwvSLI1Zkobw-1; Thu, 02 Mar 2023 18:43:43 -0500 X-MC-Unique: 9gzNEtgJP8qwvSLI1Zkobw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A254E100F90C; Thu, 2 Mar 2023 23:43:42 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.45.225.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id F005A140EBF6; Thu, 2 Mar 2023 23:43:41 +0000 (UTC) From: Tomas Henzl To: linux-scsi@vger.kernel.org Cc: sreekanth.reddy@broadcom.com, sathya.prakash@broadcom.com, ranjan.kumar@broadcom.com Subject: [PATCH v2 5/6] scsi: mpi3mr: fix a memory leak Date: Fri, 3 Mar 2023 00:43:35 +0100 Message-Id: <20230302234336.25456-6-thenzl@redhat.com> In-Reply-To: <20230302234336.25456-1-thenzl@redhat.com> References: <20230302234336.25456-1-thenzl@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Don't allocate memory again in next loop(s). Fixes: fe6db6151565 ("scsi: mpi3mr: Handle offline FW activation in graceful manner") Signed-off-by: Tomas Henzl --- V2 - mpi3mr_create_op_queues may be called repeatedly and without it it interferes with mpi3mr_memset_buffers So let drop the changes around it. drivers/scsi/mpi3mr/mpi3mr_fw.c | 41 ++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c index fa62991f5aee..081512b46538 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_fw.c +++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c @@ -3852,29 +3852,34 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc) mpi3mr_print_ioc_info(mrioc); - dprint_init(mrioc, "allocating config page buffers\n"); - mrioc->cfg_page = dma_alloc_coherent(&mrioc->pdev->dev, - MPI3MR_DEFAULT_CFG_PAGE_SZ, &mrioc->cfg_page_dma, GFP_KERNEL); if (!mrioc->cfg_page) { - retval = -1; - goto out_failed_noretry; + dprint_init(mrioc, "allocating config page buffers\n"); + mrioc->cfg_page_sz = MPI3MR_DEFAULT_CFG_PAGE_SZ; + mrioc->cfg_page = dma_alloc_coherent(&mrioc->pdev->dev, + mrioc->cfg_page_sz, &mrioc->cfg_page_dma, GFP_KERNEL); + if (!mrioc->cfg_page) { + retval = -1; + goto out_failed_noretry; + } } - mrioc->cfg_page_sz = MPI3MR_DEFAULT_CFG_PAGE_SZ; - - retval = mpi3mr_alloc_reply_sense_bufs(mrioc); - if (retval) { - ioc_err(mrioc, - "%s :Failed to allocated reply sense buffers %d\n", - __func__, retval); - goto out_failed_noretry; + if (!mrioc->init_cmds.reply) { + retval = mpi3mr_alloc_reply_sense_bufs(mrioc); + if (retval) { + ioc_err(mrioc, + "%s :Failed to allocated reply sense buffers %d\n", + __func__, retval); + goto out_failed_noretry; + } } - retval = mpi3mr_alloc_chain_bufs(mrioc); - if (retval) { - ioc_err(mrioc, "Failed to allocated chain buffers %d\n", - retval); - goto out_failed_noretry; + if (!mrioc->chain_sgl_list) { + retval = mpi3mr_alloc_chain_bufs(mrioc); + if (retval) { + ioc_err(mrioc, "Failed to allocated chain buffers %d\n", + retval); + goto out_failed_noretry; + } } retval = mpi3mr_issue_iocinit(mrioc); From patchwork Thu Mar 2 23:43:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomas Henzl X-Patchwork-Id: 13158069 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F294EC678D4 for ; Thu, 2 Mar 2023 23:45:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230037AbjCBXpO (ORCPT ); Thu, 2 Mar 2023 18:45:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjCBXpM (ORCPT ); Thu, 2 Mar 2023 18:45:12 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7782A1F93B for ; Thu, 2 Mar 2023 15:43:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677800627; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ls4YhmUjGqxUvqm44RrzLr1gLS3axmc0i7vDEP5J7PY=; b=HY/ZAydSU3itvN9iRgyERuEwK5sMfxtq4k8DK1wqvODCWOoOEqYrqEBpnvYxCEFF+CX9Mv M/+gkl/EmVtjCz20xtpiTAjfNDTAi6V4DEt7uP2G+5XW7HPbb9ocW7kPbhP4rNQwj6O/CU QbJvpQ2x/Otj+U4B/MQCY6egNxAN+ZY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-304--MhFKkORPfqFZKSvA4YAkw-1; Thu, 02 Mar 2023 18:43:43 -0500 X-MC-Unique: -MhFKkORPfqFZKSvA4YAkw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8771580D185; Thu, 2 Mar 2023 23:43:43 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.45.225.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id D608E140EBF6; Thu, 2 Mar 2023 23:43:42 +0000 (UTC) From: Tomas Henzl To: linux-scsi@vger.kernel.org Cc: sreekanth.reddy@broadcom.com, sathya.prakash@broadcom.com, ranjan.kumar@broadcom.com Subject: [PATCH v2 6/6] scsi: mpi3mr: fix a memory leak Date: Fri, 3 Mar 2023 00:43:36 +0100 Message-Id: <20230302234336.25456-7-thenzl@redhat.com> In-Reply-To: <20230302234336.25456-1-thenzl@redhat.com> References: <20230302234336.25456-1-thenzl@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add a missing resource clean up in .remove. Fixes: e22bae30667a ("scsi: mpi3mr: Add expander devices to STL") Signed-off-by: Tomas Henzl --- drivers/scsi/mpi3mr/mpi3mr.h | 2 ++ drivers/scsi/mpi3mr/mpi3mr_os.c | 7 +++++++ drivers/scsi/mpi3mr/mpi3mr_transport.c | 5 +---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h index e6a9c81bba33..c5347a004cd5 100644 --- a/drivers/scsi/mpi3mr/mpi3mr.h +++ b/drivers/scsi/mpi3mr/mpi3mr.h @@ -1407,4 +1407,6 @@ void mpi3mr_flush_drv_cmds(struct mpi3mr_ioc *mrioc); void mpi3mr_flush_cmds_for_unrecovered_controller(struct mpi3mr_ioc *mrioc); void mpi3mr_free_enclosure_list(struct mpi3mr_ioc *mrioc); int mpi3mr_process_admin_reply_q(struct mpi3mr_ioc *mrioc); +void mpi3mr_expander_node_remove(struct mpi3mr_ioc *mrioc, + struct mpi3mr_sas_node *sas_expander); #endif /*MPI3MR_H_INCLUDED*/ diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c index 8f17a7953eb4..b329e1ee46dc 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_os.c +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c @@ -5113,6 +5113,7 @@ static void mpi3mr_remove(struct pci_dev *pdev) unsigned long flags; struct mpi3mr_tgt_dev *tgtdev, *tgtdev_next; struct mpi3mr_hba_port *port, *hba_port_next; + struct mpi3mr_sas_node *sas_expander, *sas_expander_next; if (!shost) return; @@ -5153,6 +5154,12 @@ static void mpi3mr_remove(struct pci_dev *pdev) mpi3mr_cleanup_resources(mrioc); spin_lock_irqsave(&mrioc->sas_node_lock, flags); + list_for_each_entry_safe_reverse(sas_expander, sas_expander_next, + &mrioc->sas_expander_list, list) { + spin_unlock_irqrestore(&mrioc->sas_node_lock, flags); + mpi3mr_expander_node_remove(mrioc, sas_expander); + spin_lock_irqsave(&mrioc->sas_node_lock, flags); + } list_for_each_entry_safe(port, hba_port_next, &mrioc->hba_port_table_list, list) { ioc_info(mrioc, "removing hba_port entry: %p port: %d from hba_port list\n", diff --git a/drivers/scsi/mpi3mr/mpi3mr_transport.c b/drivers/scsi/mpi3mr/mpi3mr_transport.c index 121fae310692..4d84d5bd173f 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_transport.c +++ b/drivers/scsi/mpi3mr/mpi3mr_transport.c @@ -9,9 +9,6 @@ #include "mpi3mr.h" -static void mpi3mr_expander_node_remove(struct mpi3mr_ioc *mrioc, - struct mpi3mr_sas_node *sas_expander); - /** * mpi3mr_post_transport_req - Issue transport requests and wait * @mrioc: Adapter instance reference @@ -2164,7 +2161,7 @@ int mpi3mr_expander_add(struct mpi3mr_ioc *mrioc, u16 handle) * * Return nothing. */ -static void mpi3mr_expander_node_remove(struct mpi3mr_ioc *mrioc, +void mpi3mr_expander_node_remove(struct mpi3mr_ioc *mrioc, struct mpi3mr_sas_node *sas_expander) { struct mpi3mr_sas_port *mr_sas_port, *next;