Re: [PATCH net] net: microchip: vcap api: Fix possible memory leak in vcap_decode_rule()

From: Joe Damato

Date: Mon Jul 27 2026 - 13:40:53 EST


On Mon, Jul 27, 2026 at 06:27:55PM +0530, Abdun Nihaal wrote:
> The memory allocated for struct vcap_rule_internal, keyfields and
> actionfields inside vcap_dup_rule() are not freed in some of the error
> paths in vcap_decode_rule(). Fix that by calling vcap_free_rule().
>
> Fixes: 610c32b2ce66 ("net: microchip: vcap: Add vcap_get_rule")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Abdun Nihaal <nihaal@xxxxxxxxxxxxxx>
> ---
> Compile tested only. Issue found using static analysis.
>
> drivers/net/ethernet/microchip/vcap/vcap_api.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c
> index ff86cde11a32..0cc0db7b641b 100644
> --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c
> +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c
> @@ -2427,18 +2427,21 @@ struct vcap_rule *vcap_decode_rule(struct vcap_rule_internal *elem)
>
> err = vcap_read_rule(ri);
> if (err)
> - return ERR_PTR(err);
> + goto err;
>
> err = vcap_decode_keyset(ri);
> if (err)
> - return ERR_PTR(err);
> + goto err;
>
> err = vcap_decode_actionset(ri);
> if (err)
> - return ERR_PTR(err);
> + goto err;
>
> out:
> return &ri->data;
> +err:
> + vcap_free_rule(&ri->data);
> + return ERR_PTR(err);
> }

Not sure what the style guidelines say, but the label err and the local
variable err having the same name is a bit confusing.

Maybe you could make the label "out_err" and update the gotos instead?

Either way, the code looks right other than the style nit, so if you resend
you can apply my tag:

Reviewed-by: Joe Damato <joe@xxxxxxx>