From patchwork Wed Jun 14 09:17:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13280173 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D5B58EB64D8 for ; Wed, 14 Jun 2023 15:53:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=+4BDyVJlEyciULhzaVuST5hYCCRis1f/OzbeObpDkkY=; b=DUSxl1mylSqBwg 4rWRNDxcDb3Ht1LKxO3vYeY9X7GnwbKdxIm23eOpAtbRCh5mOOcy1heO+mXlh6Sp59hB0U83xlISQ vqR3GhSz7i0UVliwHz3vwAP4p7B5h0uRe0tOg0UzwonmOpid+eZujuI4fueREk/QBXu8LXMneGfNd jFcr/7Uarwa3kLty4+Ihuyst2W7IKNTwHuO7quoRocVGAYIml9cjlIFHEuiMJ9rI2jsiq1MStfz9u OVilSTYvkpgvCUf7XrT5kAbp+zuR2yPMlTdrZH52CZz5mc9Pw0zdVyJ+D9EfZHx7TUJERM2zc6ocm CVh1WCMPrsY5Dx4Fib6w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q9SoC-00C7sD-2p; Wed, 14 Jun 2023 15:53:20 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q9SoA-00C7rm-2f for linux-arm-kernel@lists.infradead.org; Wed, 14 Jun 2023 15:53:20 +0000 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-310e6e6a8d4so811226f8f.2 for ; Wed, 14 Jun 2023 08:53:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686757996; x=1689349996; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Bhq/y0fc8NtbiDoPoE9MBpAtCqUXLlZMCwX6567Us4w=; b=rplArsRTqX0QzO+acxEngNYJNMVt6u5lBMTiEmCMCN9MqpTtL0AOdInFSf3QEQLis6 K5KkbNP4lva6SBLQxaan7MYME6CwT+/F/2PjeGakSkgz/g6LjoMls6tNrT93DmmuqUYp eM7vKCdL9B9IniqP7BNSdJ2M3pJGOhnw1kLHPVw0U3w8EiIf3SjvjswZAapm1gZkRGfB T1wShgwmoRF8B3ByF/Asxs2lnS1aXAzaJAm2Vi7W6UzoeBlnrUf5KQH7+EivQN0p4lpA 6MF436FcsaG8uPOLPAmwDLyVZQlcRj4rpfJ61dbRO1SPl8NmSDSP3QDYR7JRmEdaASX4 N3sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686757996; x=1689349996; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Bhq/y0fc8NtbiDoPoE9MBpAtCqUXLlZMCwX6567Us4w=; b=YKz8OD9xpqVtedEg0rLFNMCXEZRtk/uwgmAh7JGPQ68m9p0Lb7KKygI75l5w+iJGKy 1Ad7bWBfXkah1nDk17NB0i3B1b0GJp3rM23YjVxHYZac2kTT5HfWXmfHfalsPlQn32rv LgG9sScb68YzCM52kGGA4sucI/LeULqQimUABIwGEtSCdWWxAcdWjJ6mtshJAVAVDfh4 cBoHgBGZjEneeWYd9ULsRHXBX5Y33YLCqvyYOZ8opt7A22E7l9soTe1t2l6skGVG3vWo l3LTl1uy32/h5atGhrrJvjq5Tz34onLJurG6maJkEiaB2UcNCu9OZWdt/B4s7ulNkhIM FbYg== X-Gm-Message-State: AC+VfDy14N4gh8rnEa3gx3NuzmZNqUsp4SSRFKeBX7e+7cy7+sHaKVaT 97iDGD0DkMMJlY1WCYNqlpk= X-Google-Smtp-Source: ACHHUZ4bgrLvAW+bLWRMhNWCLyEUy8rjxDhrz/ugqbtaLYWSlkDAiCpdxMZXxKqgVabsYT+IRO3eww== X-Received: by 2002:adf:f5d2:0:b0:30f:d0e7:ef31 with SMTP id k18-20020adff5d2000000b0030fd0e7ef31mr3459559wrp.44.1686757996142; Wed, 14 Jun 2023 08:53:16 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id m6-20020a5d6246000000b0030e52d4c1bcsm18752199wrv.71.2023.06.14.08.53.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 08:53:15 -0700 (PDT) From: Christian Marangi To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Russell King , Christian Marangi , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Jose Abreu , stable@vger.kernel.org Subject: [net PATCH v2] net: ethernet: stmicro: stmmac: fix possible memory leak in __stmmac_open Date: Wed, 14 Jun 2023 11:17:14 +0200 Message-Id: <20230614091714.15912-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230614_085318_866389_7E72DEDB X-CRM114-Status: GOOD ( 12.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Fix a possible memory leak in __stmmac_open when stmmac_init_phy fails. It's also needed to free everything allocated by stmmac_setup_dma_desc and not just the dma_conf struct. Drop free_dma_desc_resources from __stmmac_open and correctly call free_dma_desc_resources on each user of __stmmac_open on error. Reported-by: Jose Abreu Fixes: ba39b344e924 ("net: ethernet: stmicro: stmmac: generate stmmac dma conf before open") Signed-off-by: Christian Marangi Cc: stable@vger.kernel.org Reviewed-by: Simon Horman Reviewed-by: Jose Abreu --- Changes v2: - Move free_dma_desc_resources to each user of __stmmac_open drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index fa07b0d50b46..5c645b6d5660 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -3877,7 +3877,6 @@ static int __stmmac_open(struct net_device *dev, stmmac_hw_teardown(dev); init_error: - free_dma_desc_resources(priv, &priv->dma_conf); phylink_disconnect_phy(priv->phylink); init_phy_error: pm_runtime_put(priv->device); @@ -3895,6 +3894,9 @@ static int stmmac_open(struct net_device *dev) return PTR_ERR(dma_conf); ret = __stmmac_open(dev, dma_conf); + if (ret) + free_dma_desc_resources(priv, dma_conf); + kfree(dma_conf); return ret; } @@ -5637,12 +5639,15 @@ static int stmmac_change_mtu(struct net_device *dev, int new_mtu) stmmac_release(dev); ret = __stmmac_open(dev, dma_conf); - kfree(dma_conf); if (ret) { + free_dma_desc_resources(priv, dma_conf); + kfree(dma_conf); netdev_err(priv->dev, "failed reopening the interface after MTU change\n"); return ret; } + kfree(dma_conf); + stmmac_set_rx_mode(dev); }