netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Markus Elfring <Markus.Elfring@web.de>
Cc: Abdun Nihaal <abdun.nihaal@gmail.com>,
	netdev@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Potnuri Bharat Teja <bharat@chelsio.com>,
	Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>,
	Vishal Kulkarni <vishal@chelsio.com>
Subject: Re: [PATCH net-next] cxgb4: fix memory leak in cxgb4_init_ethtool_filters() error path
Date: Fri, 11 Apr 2025 15:57:34 +0100	[thread overview]
Message-ID: <20250411145734.GH395307@horms.kernel.org> (raw)
In-Reply-To: <5cb34dde-fb40-4654-806f-50e0c2ee3579@web.de>

On Wed, Apr 09, 2025 at 05:47:46PM +0200, Markus Elfring wrote:
> …
> > +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c
> > @@ -2270,6 +2270,7 @@ int cxgb4_init_ethtool_filters(struct adapter *adap)
> >  		eth_filter->port[i].bmap = bitmap_zalloc(nentries, GFP_KERNEL);
> >  		if (!eth_filter->port[i].bmap) {
> >  			ret = -ENOMEM;
> > +			kvfree(eth_filter->port[i].loc_array);
> >  			goto free_eth_finfo;
> >  		}
> >  	}
> 
> How do you think about to move the shown error code assignment behind the mentioned label
> (so that another bit of duplicate source code could be avoided)?

Hi Markus,

If you mean something like the following. Then I agree that it
is both in keeping with the existing error handling in this function
and addresses the problem at hand.

diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c
index 7f3f5afa864f..df26d3388c00 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c
@@ -2270,13 +2270,15 @@ int cxgb4_init_ethtool_filters(struct adapter *adap)
                eth_filter->port[i].bmap = bitmap_zalloc(nentries, GFP_KERNEL);
                if (!eth_filter->port[i].bmap) {
                        ret = -ENOMEM;
-                       goto free_eth_finfo;
+                       goto free_eth_finfo_loc_array;
                }
        }

        adap->ethtool_filters = eth_filter;
        return 0;

+free_eth_finfo_loc_array:
+       kvfree(eth_filter->port[i].loc_array);
 free_eth_finfo:
        while (i-- > 0) {
                bitmap_free(eth_filter->port[i].bmap);


> 
> Regards,
> Markus
> 

  reply	other threads:[~2025-04-11 14:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-09  5:43 [PATCH net-next] cxgb4: fix memory leak in cxgb4_init_ethtool_filters() error path Abdun Nihaal
2025-04-09 15:47 ` Markus Elfring
2025-04-11 14:57   ` Simon Horman [this message]
2025-04-11 16:22     ` Abdun Nihaal
2025-04-11 18:50       ` [PATCH] " Markus Elfring
2025-04-14 14:56       ` [PATCH net-next] " Simon Horman
2025-04-14 14:59         ` Simon Horman
2025-04-14 16:53           ` Abdun Nihaal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250411145734.GH395307@horms.kernel.org \
    --to=horms@kernel.org \
    --cc=Markus.Elfring@web.de \
    --cc=abdun.nihaal@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=bharat@chelsio.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rahul.lakkireddy@chelsio.com \
    --cc=vishal@chelsio.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).