Subject: Re: [PATCH v2 net 03/11] octeontx2-af: npc: cn20k: Propagate errors in defrag MCAM alloc rollback

From: Simon Horman <[email-masked]>
Date: Thu, 23 Apr 2026 12:13:03 +0100

On Mon, Apr 20, 2026 at 08:04:34AM +0530, Ratheesh Kannoth wrote:
> npc_defrag_alloc_free_slots() allocates MCAM indexes in up to two passes
> on bank0 then bank1.  On failure it rolls back by freeing entries already
> placed in save[].
> 
> __npc_subbank_alloc() can return a negative errno while only part of the
> indexes are valid.  The rollback loop used rc for
> npc_mcam_idx_2_subbank_idx() as well, so a successful lookup stored zero
> in rc and a later __npc_subbank_free() failure could still end with
> return 0 when the allocation path had also left rc at zero
> (for example shortfall after zero return values from the alloc helpers).
> 
> Jump to the rollback path immediately when either __npc_subbank_alloc()
> call fails, preserving its errno.  If both calls succeed but the total
> allocated count is still less than cnt, set rc to -ENOSPC before rollback.
> Use a separate err variable for npc_mcam_idx_2_subbank_idx() so a
> successful lookup no longer clears a non-zero rc from the allocation
> phase.
> 
> Cc: Dan Carpenter <[email-masked]>
> Fixes: 645c6e3c1999 ("octeontx2-af: npc: cn20k: virtual index support")
> Link: https://lore.kernel.org/netdev/[email-masked]/
> Signed-off-by: Ratheesh Kannoth <[email-masked]>

Reviewed-by: Simon Horman <[email-masked]>

Sashiko has generated a review of this patch. I believe that the concerns
raised there are all pre-existing issues that can be looked at in the
context of potential follow-up; I do not believe they should block
progress of this patchset.

...