Re: [PATCH v20 net-next 9/9] octeontx2-af: npc: cn20k: Allocate npc_priv and dstats dynamically.

From: Ratheesh Kannoth

Date: Wed Jun 10 2026 - 01:35:49 EST


On 2026-06-09 at 09:34:53, Ratheesh Kannoth (rkannoth@xxxxxxxxxxx) wrote:
> Replace the file-scope static npc_priv with a kcalloc'd struct filled
> from hardware bank/subbank geometry at init (num_banks is no longer a
> const compile-time constant; drop init_done and use a non-NULL
> npc_priv pointer for liveness). Thread npc_priv_get() / pointer access
> through the CN20K NPC code paths, extend teardown to kfree the root
> struct on failure and in npc_cn20k_deinit, and adjust MCAM section
> setup to use the discovered subbank count.
>
> Allocate MCAM debugfs dstats via devm_kzalloc instead of a static matrix,
> and use the allocated backing store consistently when computing deltas
> (including the counter rollover compare).
>
> Signed-off-by: Ratheesh Kannoth <rkannoth@xxxxxxxxxxx>

https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260609040453.711932-1-rkannoth%40marvell.com says:

> - kfree(npc_priv.xa_pf2idx_map);
>> + kfree(npc_priv->xa_pf2idx_map);
>> /* No need to destroy mutex lock as it is
>> * part of subbank structure
>> */
>> - kfree(npc_priv.sb);
>> + kfree(npc_priv->sb);
>> kfree(subbank_srch_order);
>> - bitmap_clear(npc_priv.en_map, 0, MAX_NUM_BANKS * MAX_NUM_SUB_BANKS *
>> + bitmap_clear(npc_priv->en_map, 0, MAX_NUM_BANKS * MAX_NUM_SUB_BANKS *
>> MAX_SUBBANK_DEPTH);
>> + npc_defrag_list_clear();
>> + kfree(npc_priv);
>> + npc_priv = NULL;
>> }
>Now that npc_priv is dynamically allocated, en_map is an embedded
>DECLARE_BITMAP inside the struct that is unconditionally kfree'd two
>lines later:
> bitmap_clear(npc_priv->en_map, 0, MAX_NUM_BANKS * MAX_NUM_SUB_BANKS *
> MAX_SUBBANK_DEPTH);
> npc_defrag_list_clear();
> kfree(npc_priv);
> npc_priv = NULL;
>Does this bitmap_clear still serve a purpose? Pre-patch it cleared
>state on a static struct that persisted across unbind/rebind, but with
>the dynamic allocation it can be removed.
Not needed. But kept as part of graceful shutdown.