From: Simon Horman <horms@kernel.org>
To: Ratheesh Kannoth <rkannoth@marvell.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
sgoutham@marvell.com, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, donald.hunter@gmail.com,
jiri@resnulli.us, chuck.lever@oracle.com, matttbe@kernel.org,
cjubran@nvidia.com, shshitrit@nvidia.com
Subject: Re: [PATCH net-next 4/5] cteontx2-af: npc: cn20k: dynamically allocate and free default MCAM entries
Date: Fri, 6 Mar 2026 13:21:41 +0000 [thread overview]
Message-ID: <20260306132141.GC461701@kernel.org> (raw)
In-Reply-To: <20260302085803.2449828-5-rkannoth@marvell.com>
On Mon, Mar 02, 2026 at 02:28:02PM +0530, Ratheesh Kannoth wrote:
...
> @@ -4220,21 +4242,46 @@ void npc_cn20k_dft_rules_free(struct rvu *rvu, u16 pcifunc)
> index = NPC_DFT_RULE_ID_MK(pcifunc, i);
> map = xa_erase(&npc_priv.xa_pf2dfl_rmap, index);
> if (!map)
> - dev_dbg(rvu->dev,
> + dev_err(rvu->dev,
> "%s: Err from delete %s mcam idx from xarray (pcifunc=%#x\n",
> __func__, npc_dft_rule_name[i],
> pcifunc);
> }
>
> free_rules:
> + blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
> + if (blkaddr < 0)
> + return;
>
> - free_req.hdr.pcifunc = pcifunc;
> - free_req.all = 1;
> - rc = rvu_mbox_handler_npc_mcam_free_entry(rvu, &free_req, &rsp);
> - if (rc)
> - dev_err(rvu->dev,
> - "%s: Error deleting default entries (pcifunc=%#x\n",
> - __func__, pcifunc);
> + for (int i = 0; i < 4; i++) {
> + if (ptr[i] == USHRT_MAX)
> + continue;
> +
> + mutex_lock(&mcam->lock);
> + npc_mcam_clear_bit(mcam, ptr[i]);
> + mcam->entry2pfvf_map[ptr[i]] = NPC_MCAM_INVALID_MAP;
> + npc_cn20k_enable_mcam_entry(rvu, blkaddr, ptr[i], false);
> + mcam->entry2target_pffunc[ptr[i]] = 0x0;
> + mutex_unlock(&mcam->lock);
> +
> + rc = npc_cn20k_idx_free(rvu, &ptr[i], 1);
> + if (rc)
> + dev_err(rvu->dev,
> + "%s:%d Error deleting default entries (pcifunc=%#x) mcam_idx=%u\n",
> + __func__, __LINE__, pcifunc, ptr[i]);
> + }
> +
> + mutex_lock(&mcam->lock);
> + list_for_each_entry_safe(rule, tmp, &mcam->mcam_rules, list) {
> + for (int i = 0; i < 4; i++) {
> + if (ptr[i] != rule->entry)
> + continue;
Hi Ratheesh,
I assume that the condition above should match exactly once
for each iteration of the for loop. But if not rule may
either not be freed or freed twice.
Would it make sense to move freeing rule to outside the for loop?
I think this would address both problems. But perhaps it leads
to rule being freed when it should not be.
Alternatively, should there be a break after the call to kfree()?
I think that would address only the (theoretical possibility of) a double
free.
Flagged by Smatch.
> +
> + list_del(&rule->list);
> + kfree(rule);
> + }
> + }
> + mutex_unlock(&mcam->lock);
> }
...
next prev parent reply other threads:[~2026-03-06 13:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-02 8:57 [PATCH net-next 0/5] octeontx2-af: npc: Enhancements Ratheesh Kannoth
2026-03-02 8:57 ` [PATCH net-next 1/5] octeontx2-af: npc: cn20k: debugfs enhancements Ratheesh Kannoth
2026-03-02 8:58 ` [PATCH net-next 2/5] devlink: Implement devlink param multi attribute nested data values Ratheesh Kannoth
2026-03-02 8:58 ` [PATCH net-next 3/5] octeontx2-af: npc: cn20k: add subbank search order control Ratheesh Kannoth
2026-03-02 8:58 ` [PATCH net-next 4/5] cteontx2-af: npc: cn20k: dynamically allocate and free default MCAM entries Ratheesh Kannoth
2026-03-06 13:21 ` Simon Horman [this message]
2026-03-02 8:58 ` [PATCH net-next 5/5] octeontx2-af: Add support for loading custom KPU profile from filesystem Ratheesh Kannoth
2026-03-04 1:09 ` Jakub Kicinski
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=20260306132141.GC461701@kernel.org \
--to=horms@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=cjubran@nvidia.com \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matttbe@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rkannoth@marvell.com \
--cc=sgoutham@marvell.com \
--cc=shshitrit@nvidia.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