All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Wentao Liang <vulab@iscas.ac.cn>
Cc: UNGLinuxDriver@microchip.com, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	pabeni@redhat.com, vladimir.oltean@nxp.com,
	stable@vger.kernel.org
Subject: Re: [PATCH] net: mscc: ocelot: Fix mirror reference leak on VCAP aux resource error
Date: Mon, 21 Sep 2026 11:46:24 +0100	[thread overview]
Message-ID: <20260921104624.GI13925@horms.kernel.org> (raw)
In-Reply-To: <20260917113444.2149183-1-vulab@iscas.ac.cn>

On Thu, Sep 17, 2026 at 11:34:44AM +0000, Wentao Liang wrote:
> When ocelot_vcap_policer_add() fails, the aux resource setup returns
> without releasing the mirror reference taken earlier by
> ocelot_mirror_get(). The caller drops the filter without calling
> ocelot_vcap_filter_del_aux_resources(), so the reference is leaked.
> 
> Release the mirror reference before returning the error.
> 
> Fixes: c3d427eac90f ("net: mscc: ocelot: establish functions for handling VCAP aux resources")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>  drivers/net/ethernet/mscc/ocelot_vcap.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mscc/ocelot_vcap.c b/drivers/net/ethernet/mscc/ocelot_vcap.c
> index 25e533e91d71..c479af2a423f 100644
> --- a/drivers/net/ethernet/mscc/ocelot_vcap.c
> +++ b/drivers/net/ethernet/mscc/ocelot_vcap.c
> @@ -970,8 +970,11 @@ ocelot_vcap_filter_add_aux_resources(struct ocelot *ocelot,
>  	if (filter->block_id == VCAP_IS2 && filter->action.police_ena) {
>  		ret = ocelot_vcap_policer_add(ocelot, filter->action.pol_ix,
>  					      &filter->action.pol);
> -		if (ret)
> +		if (ret) {
> +			if (filter->action.mirror_ena)
> +				ocelot_mirror_put(ocelot);
>  			return ret;
> +		}
>  	}
>  
>  	return 0;

I think this change would be somewhat more robust against future changes to
this function if it was implemented using a goto-driven unwind ladder,
which is the generally preferred in Networking code.

Something like this (compile tested only!):

diff --git a/drivers/net/ethernet/mscc/ocelot_vcap.c b/drivers/net/ethernet/mscc/ocelot_vcap.c
index 25e533e91d71..ce4a3da38c58 100644
--- a/drivers/net/ethernet/mscc/ocelot_vcap.c
+++ b/drivers/net/ethernet/mscc/ocelot_vcap.c
@@ -957,7 +957,7 @@ ocelot_vcap_filter_add_aux_resources(struct ocelot *ocelot,
 				     struct ocelot_vcap_filter *filter,
 				     struct netlink_ext_ack *extack)
 {
-	struct ocelot_mirror *m;
+	struct ocelot_mirror *m = NULL;
 	int ret;
 
 	if (filter->block_id == VCAP_IS2 && filter->action.mirror_ena) {
@@ -971,10 +971,15 @@ ocelot_vcap_filter_add_aux_resources(struct ocelot *ocelot,
 		ret = ocelot_vcap_policer_add(ocelot, filter->action.pol_ix,
 					      &filter->action.pol);
 		if (ret)
-			return ret;
+			goto err_mirror_put;
 	}
 
 	return 0;
+
+err_mirror_put:
+	if (m)
+		ocelot_mirror_put(ocelot);
+	return ret;
 }
 
 static void

-- 
pw-bot: changes-requested

      reply	other threads:[~2026-09-21 10:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 11:34 [PATCH] net: mscc: ocelot: Fix mirror reference leak on VCAP aux resource error Wentao Liang
2026-09-21 10:46 ` Simon Horman [this message]

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=20260921104624.GI13925@horms.kernel.org \
    --to=horms@kernel.org \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=andrew+netdev@lunn.ch \
    --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=stable@vger.kernel.org \
    --cc=vladimir.oltean@nxp.com \
    --cc=vulab@iscas.ac.cn \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.