Message ID | 20230614073241.6382-1-ansuelsmth@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:640b:b0:12b:d5da:ddc2 with SMTP id f11csp1348981rwh; Wed, 14 Jun 2023 07:46:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ56w1O7a10xqmMxK9kw4N9azAbPDemOmkMG1JgCPJSHIo5vlu21T7Pd2S5TLPiBwEK8nd5E X-Received: by 2002:aa7:d6c3:0:b0:504:b0d2:76c with SMTP id x3-20020aa7d6c3000000b00504b0d2076cmr8880493edr.32.1686753965360; Wed, 14 Jun 2023 07:46:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686753965; cv=none; d=google.com; s=arc-20160816; b=ShfTW4R8To1D4DOHqg/wCo7ne+mY0ZXUzWqApRAqyhsUin6KL2F2oTQedaqbG1w/16 EOfWyuP+VixxPG6si5RjzrvO2sEjQRb9aVFcoZJKJw+XTRm65UAkbDNr4di+3s8ljy31 oWYKiHydJSyVDXerP7UMT7Y3zre71vVNTR/Qzegc6G7UAHmZB3rWT3HcZeJxkDfbKK0v /ZvBHr9K44es46s1q+WVTwYAxTXyXWzXNclFnnIJRY1Dz1fMHzQO6xT4M8uttrgZ72BS 7wwIt0Kzqd5s4+fYHLWtKYZetpXIlGnuun8jzsCh1j/rVBSMMh7hcWYsTZY/sJTSJvP9 aXBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=zXrtZVNtigeKgJSwA8SW/6hEN8pGZI7BArpmacufnTg=; b=CKbTVqX6DlhW+YybFGYPc6Rp+eoIyA6jbA/AX0nJxXmb+f4dPpTqDzeaAbIa3gyzBm Ircn6DPIegPJGZAxud2aTMJQHbFOfHuOOAYr1l8IFele3yxdmu62DU7PK1cL4fTmKqT9 NKRKOszW5cNfstxLlUNtpXZfGsowVR4QSXiBT4x8pwzgN/avIezNcp0TNwuXaDmsozj0 pG/tgKfScrQ4uX6gO5bStJDAhRwzpRAjxl5jw9dXKYK/v5y48iZzXQGd1kGhGyGmw+Gl fnMQehufeAnilB28f3KHUYWOE/fMhlZ3WZA8tPGJJAtN8Dphb32J/9WN7R3hkxqSCe7i xzdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ZvlIhWO+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g7-20020a056402180700b005106ccf84a3si8602507edy.444.2023.06.14.07.45.16; Wed, 14 Jun 2023 07:46:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ZvlIhWO+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245491AbjFNORM (ORCPT <rfc822;n2h9z4@gmail.com> + 99 others); Wed, 14 Jun 2023 10:17:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245526AbjFNOQ5 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 14 Jun 2023 10:16:57 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 713B31BC6; Wed, 14 Jun 2023 07:16:49 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3f8ca80e889so6766425e9.3; Wed, 14 Jun 2023 07:16:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686752208; x=1689344208; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=zXrtZVNtigeKgJSwA8SW/6hEN8pGZI7BArpmacufnTg=; b=ZvlIhWO+UbdEXvtjkfHV7Na2P16yHMVjdBcJ4rDysGC7/aPhxMv4zaZSiGm/ZhK2td UwCJg/2ARuYuOw3iMAbcyZ+es5K4mrPdWEah974xwoTL51Jj7Z5nu0QlR23j2ZuQDsUJ e8P/44csh3nSZRI+/nZBtYpVh3jCekSF28BWITcHCUTcFvMJJSWpgyZul8+XTPZepgSl zXZZ5vAg+ylHT6Mgpke+nVaAOQuRqhkQwrT458KV0vM0lTORfTeVnTu7HM77N/lJOnVR 3ws8iybDCDLn/yh6cBw11r+FD2XeoxcT9eFPbqlmki5v9CsHchOL4bk7498MqGGoD62s GbcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686752208; x=1689344208; 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=zXrtZVNtigeKgJSwA8SW/6hEN8pGZI7BArpmacufnTg=; b=CYO8DHMG0DJK1lQd/ZHt8efq8mI3ckMewOg37JDkniPa4W5ErPlp2GE+ck4Wg2wj2Z 3UszdzJ7Bj3qglwLjqDN9vYidLr96go6NTC6jdR5xhdSF0vZ+HoRATPdQflwgDn1LJhv 3XALIhpfzLxjea8IxNUHwCdv4iODhAfQVrNKRaTsFkteL/jY20nw7TEUvVzuZDRUU2UY 4lB2didL34i7A05D9cjrcDU7qSX6dWHlOMxYv3FReV0ZRQuVXbQ/OBgWVVLA41QpM8QG mc0IKQu78GIEA4DbPN3bqF1d4DJ2baVMrS1Ui8Z13o4F63HnGUX9HgikkxFueGRzr1VS ykug== X-Gm-Message-State: AC+VfDxvH/hygvm2+vEVC/dZ4HOoQVxoQ6NkLoqGmEttb1HUdS2fWELB wut5V0/Qq/Gr5sd6i2NJCGE= X-Received: by 2002:a5d:480f:0:b0:30f:ca3f:64d4 with SMTP id l15-20020a5d480f000000b0030fca3f64d4mr4131734wrq.47.1686752207571; Wed, 14 Jun 2023 07:16:47 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id v13-20020adfebcd000000b00309382eb047sm18509045wrn.112.2023.06.14.07.16.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 07:16:46 -0700 (PDT) From: Christian Marangi <ansuelsmth@gmail.com> To: Giuseppe Cavallaro <peppe.cavallaro@st.com>, Alexandre Torgue <alexandre.torgue@foss.st.com>, Jose Abreu <joabreu@synopsys.com>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Maxime Coquelin <mcoquelin.stm32@gmail.com>, Russell King <linux@armlinux.org.uk>, Christian Marangi <ansuelsmth@gmail.com>, 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 <Jose.Abreu@synopsys.com>, stable@vger.kernel.org Subject: [net PATCH] net: ethernet: stmicro: stmmac: fix possible memory leak in __stmmac_open Date: Wed, 14 Jun 2023 09:32:41 +0200 Message-Id: <20230614073241.6382-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,DATE_IN_PAST_06_12, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768689725692578699?= X-GMAIL-MSGID: =?utf-8?q?1768689725692578699?= |
Series |
[net] net: ethernet: stmicro: stmmac: fix possible memory leak in __stmmac_open
|
|
Commit Message
Christian Marangi
June 14, 2023, 7:32 a.m. UTC
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.
Correctly call free_dma_desc_resources on the new dma_conf passed to
__stmmac_open on error.
Reported-by: Jose Abreu <Jose.Abreu@synopsys.com>
Fixes: ba39b344e924 ("net: ethernet: stmicro: stmmac: generate stmmac dma conf before open")
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Cc: stable@vger.kernel.org
---
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Wed, Jun 14, 2023 at 04:55:10PM +0200, Simon Horman wrote: > On Wed, Jun 14, 2023 at 09:32:41AM +0200, Christian Marangi wrote: > > 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. > > > > Correctly call free_dma_desc_resources on the new dma_conf passed to > > __stmmac_open on error. > > > > Reported-by: Jose Abreu <Jose.Abreu@synopsys.com> > > Fixes: ba39b344e924 ("net: ethernet: stmicro: stmmac: generate stmmac dma conf before open") > > Signed-off-by: Christian Marangi <ansuelsmth@gmail.com> > > Cc: stable@vger.kernel.org > > --- > > drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > > index fa07b0d50b46..0966ab86fde2 100644 > > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > > @@ -3877,10 +3877,10 @@ 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); > > + free_dma_desc_resources(priv, dma_conf); > > Hi Christian, > > Are these resources allocated by the caller? > If so, perhaps it would be clearer if a symmetric approach > was taken and the caller handled freeing them on error. > Yes, they are. Handling in the caller would require some additional delta to this and some duplicated code but if preferred I can implement it. I can provide a v2 shortly if it's ok and you prefer this implementation. > > return ret; > > } > > > > -- > > 2.40.1 > > > >
On Wed, Jun 14, 2023 at 09:32:41AM +0200, Christian Marangi wrote: > 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. > > Correctly call free_dma_desc_resources on the new dma_conf passed to > __stmmac_open on error. > > Reported-by: Jose Abreu <Jose.Abreu@synopsys.com> > Fixes: ba39b344e924 ("net: ethernet: stmicro: stmmac: generate stmmac dma conf before open") > Signed-off-by: Christian Marangi <ansuelsmth@gmail.com> > Cc: stable@vger.kernel.org > --- > drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > index fa07b0d50b46..0966ab86fde2 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > @@ -3877,10 +3877,10 @@ 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); > + free_dma_desc_resources(priv, dma_conf); Hi Christian, Are these resources allocated by the caller? If so, perhaps it would be clearer if a symmetric approach was taken and the caller handled freeing them on error. > return ret; > } > > -- > 2.40.1 > >
On Wed, Jun 14, 2023 at 10:18:20AM +0200, Christian Marangi wrote: > On Wed, Jun 14, 2023 at 04:55:10PM +0200, Simon Horman wrote: > > On Wed, Jun 14, 2023 at 09:32:41AM +0200, Christian Marangi wrote: > > > 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. > > > > > > Correctly call free_dma_desc_resources on the new dma_conf passed to > > > __stmmac_open on error. > > > > > > Reported-by: Jose Abreu <Jose.Abreu@synopsys.com> > > > Fixes: ba39b344e924 ("net: ethernet: stmicro: stmmac: generate stmmac dma conf before open") > > > Signed-off-by: Christian Marangi <ansuelsmth@gmail.com> > > > Cc: stable@vger.kernel.org > > > --- > > > drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > > > index fa07b0d50b46..0966ab86fde2 100644 > > > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > > > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > > > @@ -3877,10 +3877,10 @@ 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); > > > + free_dma_desc_resources(priv, dma_conf); > > > > Hi Christian, > > > > Are these resources allocated by the caller? > > If so, perhaps it would be clearer if a symmetric approach > > was taken and the caller handled freeing them on error. > > > > Yes, they are. Handling in the caller would require some additional > delta to this and some duplicated code but if preferred I can implement > it. I can provide a v2 shortly if it's ok and you prefer this > implementation. Thanks, I think that would be best, unless the new delta is enormous for some reason.
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index fa07b0d50b46..0966ab86fde2 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -3877,10 +3877,10 @@ 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); + free_dma_desc_resources(priv, dma_conf); return ret; }