From patchwork Tue Oct 10 13:11:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sreekanth Reddy X-Patchwork-Id: 9996115 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 EAEAC603B5 for ; Tue, 10 Oct 2017 13:15:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB547285CE for ; Tue, 10 Oct 2017 13:15:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFDEA285D1; Tue, 10 Oct 2017 13:15:29 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM autolearn=unavailable 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 64202285CE for ; Tue, 10 Oct 2017 13:15:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756255AbdJJNMK (ORCPT ); Tue, 10 Oct 2017 09:12:10 -0400 Received: from mail-qt0-f169.google.com ([209.85.216.169]:53336 "EHLO mail-qt0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756234AbdJJNMH (ORCPT ); Tue, 10 Oct 2017 09:12:07 -0400 Received: by mail-qt0-f169.google.com with SMTP id n61so22962743qte.10 for ; Tue, 10 Oct 2017 06:12:07 -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=RuAdJ5HUNZepGk2AlO7FqLHoh0nSyrUOxD9tLffAg5o=; b=Xf5ONsESQiutyUxmO6pUv17ZEVfEGyxKVrJlqCGj6W4v9Rq5GxKdfE/e7+IfLdMwZG VxDEkTWgLg0QIvdtooSxu95k4tRwZB6dejVivjYJspn8hwBsHO7xXswIJtf5BNCJWSPH xQN7Vp+6kTjAPebtMsuNgYbI5wEnLVq6y8M+U= 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=RuAdJ5HUNZepGk2AlO7FqLHoh0nSyrUOxD9tLffAg5o=; b=VEV8RkplBqf0n8ZoRK7Qjr1aVqqMcvwPqLYgptrk6jeWHpI9m0FgPj/Pn0iImifKNg jBKzSYJMwyxo3P6n4NJXB7xigoHPtZBFaWAcX/Q9evpw9E+rMOZZjeHNFaWGSAjds6Hs rQsZYkho8GPEtmQTNWTRIaYAwXV4/Fcu/2gWVPHiAAvqpZbIehMloYiE/r57ZjWM1NvD At3I2kud47ClYZbiST4X3EXPKdbNRINNC8nXdjdrpI9bdDAb80vUrvv28gt/+PvFVwnW 3gioWvIkkUtP9EB9K3Rp80o9rM1fd6bNeNKa60VQuGRUMDmNq7WFFRUS2gHwhBe9ZNUR zw5g== X-Gm-Message-State: AMCzsaXBroNxJjSe6bGLMjQciImwaotjISK+agIJplADZf4GhLqtTZiX 4jXf+Za/HeaIWZnTIo6TjGbNKXPx X-Google-Smtp-Source: AOwi7QDtq6rSa3vBI97Ckt3DqTHh31BtbCZuiKcH4husu0cerEFybxYF2aPRiCfTVcYr8jV9b27TdA== X-Received: by 10.55.197.9 with SMTP id p9mr14223920qki.113.1507641126541; Tue, 10 Oct 2017 06:12:06 -0700 (PDT) Received: from host1.dhcp.avagotech.net ([192.19.239.250]) by smtp.gmail.com with ESMTPSA id h135sm634004qke.5.2017.10.10.06.12.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 06:12:05 -0700 (PDT) From: Sreekanth Reddy X-Google-Original-From: Sreekanth Reddy To: linux-scsi@vger.kernel.org, hch@infradead.org Cc: martin.petersen@oracle.com, JBottomley@Parallels.com, Sathya.Prakash@broadcom.com, linux-kernel@vger.kernel.org, Sreekanth Reddy Subject: [PATCH 02/10] mpt3sas: Fixed memory leaks in driver Date: Tue, 10 Oct 2017 18:41:15 +0530 Message-Id: <1507641083-20207-3-git-send-email-Sreekanth.Reddy@broadcom.com> X-Mailer: git-send-email 2.0.2 In-Reply-To: <1507641083-20207-1-git-send-email-Sreekanth.Reddy@broadcom.com> References: <1507641083-20207-1-git-send-email-Sreekanth.Reddy@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 Fixed below memory leak in driver, * While removing Expander devices - we are removing expander device entry from the list before freeing it's child devices, so while freeing child device we are finding its parent device node as NULL and so we are not freeing the child device's allocated data structures. Updated the driver to remove the expander device from the list only after freeing all its child devices. Signed-off-by: Sreekanth Reddy Signed-off-by: Tomas Henzl --- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c index 9594166..600e8ef 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -5274,8 +5274,6 @@ mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) spin_lock_irqsave(&ioc->sas_node_lock, flags); sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, sas_address); - if (sas_expander) - list_del(&sas_expander->list); spin_unlock_irqrestore(&ioc->sas_node_lock, flags); if (sas_expander) _scsih_expander_node_remove(ioc, sas_expander); @@ -7476,7 +7474,6 @@ _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc) spin_unlock_irqrestore(&ioc->sas_node_lock, flags); list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list, list) { - list_del(&sas_expander->list); _scsih_expander_node_remove(ioc, sas_expander); } @@ -8102,7 +8099,6 @@ mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index, * _scsih_expander_node_remove - removing expander device from list. * @ioc: per adapter object * @sas_expander: the sas_device object - * Context: Calling function should acquire ioc->sas_node_lock. * * Removing object and freeing associated memory from the * ioc->sas_expander_list. @@ -8114,6 +8110,7 @@ _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, struct _sas_node *sas_expander) { struct _sas_port *mpt3sas_port, *next; + unsigned long flags; /* remove sibling ports attached to this expander */ list_for_each_entry_safe(mpt3sas_port, next, @@ -8141,6 +8138,10 @@ _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, sas_expander->handle, (unsigned long long) sas_expander->sas_address); + spin_lock_irqsave(&ioc->sas_node_lock, flags); + list_del(&sas_expander->list); + spin_unlock_irqrestore(&ioc->sas_node_lock, flags); + kfree(sas_expander->phy); kfree(sas_expander); }