From: wei.fang@oss.nxp.com
To: xiaoning.wang@nxp.com, andrew@lunn.ch, olteanv@gmail.com,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
richardcochran@gmail.com, linusw@kernel.org,
linux@armlinux.org.uk
Cc: wei.fang@nxp.com, imx@lists.linux.dev, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 net-next 4/8] net: dsa: netc: use entry ID instead of pointer to track host flood rule
Date: Fri, 18 Sep 2026 15:28:48 +0800 [thread overview]
Message-ID: <20260918072852.501420-5-wei.fang@oss.nxp.com> (raw)
In-Reply-To: <20260918072852.501420-1-wei.fang@oss.nxp.com>
From: Wei Fang <wei.fang@nxp.com>
Replace the struct ipft_entry_data pointer in struct netc_port with a
plain u32 entry ID (ipft_hf_eid), using NTMP_NULL_ENTRY_ID as the
sentinel value. The ipft_entry_data allocation is now freed immediately
inside netc_port_add_host_flood_rule() after the hardware entry is
committed, so no heap memory survives beyond that function. As a result,
netc_free_host_flood_rules() is no longer needed and can be removed.
Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
drivers/net/dsa/netc/netc_main.c | 62 +++++++++++-------------------
drivers/net/dsa/netc/netc_switch.h | 2 +-
2 files changed, 24 insertions(+), 40 deletions(-)
diff --git a/drivers/net/dsa/netc/netc_main.c b/drivers/net/dsa/netc/netc_main.c
index 77077352c1a5..c590931a4e1b 100644
--- a/drivers/net/dsa/netc/netc_main.c
+++ b/drivers/net/dsa/netc/netc_main.c
@@ -266,6 +266,11 @@ static int netc_init_all_ports(struct netc_switch *priv)
np->switch_priv = priv;
np->iobase = priv->regs.port + PORT_IOBASE(i);
+ /* The ipft_hf_eid is initialized to an invalid entry
+ * ID because the host flood rule (IPFT entry) has not
+ * been created.
+ */
+ np->ipft_hf_eid = NTMP_NULL_ENTRY_ID;
netc_port_get_capability(np);
priv->ports[i] = np;
}
@@ -938,30 +943,12 @@ static void netc_destroy_all_lists(struct netc_switch *priv)
mutex_destroy(&priv->vft_lock);
}
-static void netc_free_host_flood_rules(struct netc_switch *priv)
-{
- struct dsa_port *dp;
-
- dsa_switch_for_each_user_port(dp, priv->ds) {
- struct netc_port *np = priv->ports[dp->index];
-
- /* No need to clear the hardware IPFT entry. Because PCIe
- * FLR will be performed when the switch is re-registered,
- * it will reset hardware state. So only need to free the
- * memory to avoid memory leak.
- */
- kfree(np->host_flood);
- np->host_flood = NULL;
- }
-}
-
static void netc_teardown(struct dsa_switch *ds)
{
struct netc_switch *priv = ds->priv;
disable_delayed_work_sync(&priv->fdbt_ageing_work);
netc_destroy_all_lists(priv);
- netc_free_host_flood_rules(priv);
netc_free_ntmp_user(priv);
}
@@ -1759,37 +1746,36 @@ static int netc_port_add_host_flood_rule(struct netc_port *np,
cfge->cfg = cpu_to_le32(cfg);
err = ntmp_ipft_add_entry(&priv->ntmp, host_flood);
- if (err) {
- kfree(host_flood);
- return err;
- }
+ if (err)
+ goto free_host_flood;
np->uc = uc;
np->mc = mc;
- np->host_flood = host_flood;
+ np->ipft_hf_eid = host_flood->entry_id;
/* Enable ingress port filter table lookup */
netc_port_wr(np, NETC_PIPFCR, PIPFCR_EN);
- return 0;
+free_host_flood:
+ kfree(host_flood);
+
+ return err;
}
-static void netc_port_remove_host_flood(struct netc_port *np,
- struct ipft_entry_data *host_flood)
+static void netc_port_remove_host_flood(struct netc_port *np, u32 entry_id)
{
struct netc_switch *priv = np->switch_priv;
bool disable_host_flood = false;
- if (!host_flood)
+ if (entry_id == NTMP_NULL_ENTRY_ID)
return;
- if (np->host_flood == host_flood)
+ if (np->ipft_hf_eid == entry_id)
disable_host_flood = true;
- ntmp_ipft_delete_entry(&priv->ntmp, host_flood->entry_id);
- kfree(host_flood);
+ ntmp_ipft_delete_entry(&priv->ntmp, entry_id);
if (disable_host_flood) {
- np->host_flood = NULL;
+ np->ipft_hf_eid = NTMP_NULL_ENTRY_ID;
np->uc = false;
np->mc = false;
netc_port_wr(np, NETC_PIPFCR, 0);
@@ -1800,7 +1786,7 @@ static void netc_port_set_host_flood(struct dsa_switch *ds, int port,
bool uc, bool mc)
{
struct netc_port *np = NETC_PORT(ds, port);
- struct ipft_entry_data *old_host_flood;
+ u32 old_entry_id;
/* Do not add host flood rule to ingress port filter table when
* the port has joined a bridge. Otherwise, the ingress frames
@@ -1808,7 +1794,7 @@ static void netc_port_set_host_flood(struct dsa_switch *ds, int port,
* will be redirected directly to the CPU port.
*/
if (dsa_port_bridge_dev_get(np->dp)) {
- netc_port_remove_host_flood(np, np->host_flood);
+ netc_port_remove_host_flood(np, np->ipft_hf_eid);
return;
}
@@ -1818,20 +1804,18 @@ static void netc_port_set_host_flood(struct dsa_switch *ds, int port,
/* IPFT does not support in-place updates to the KEYE element,
* we need to add a new entry and then delete the old one. So
- * save the old entry first.
+ * save the old entry ID first.
*/
- old_host_flood = np->host_flood;
- np->host_flood = NULL;
+ old_entry_id = np->ipft_hf_eid;
if (netc_port_add_host_flood_rule(np, uc, mc)) {
- np->host_flood = old_host_flood;
dev_err(ds->dev, "Failed to add host flood rule on port %d\n",
port);
return;
}
/* Remove the old host flood entry */
- netc_port_remove_host_flood(np, old_host_flood);
+ netc_port_remove_host_flood(np, old_entry_id);
}
static int netc_single_vlan_aware_bridge(struct dsa_switch *ds,
@@ -2020,7 +2004,7 @@ static int netc_port_bridge_join(struct dsa_switch *ds, int port,
netc_port_set_pvid(np, vlan_unaware_pvid);
out:
- netc_port_remove_host_flood(np, np->host_flood);
+ netc_port_remove_host_flood(np, np->ipft_hf_eid);
if (atomic_inc_return(&priv->br_cnt) == 1)
schedule_delayed_work(&priv->fdbt_ageing_work,
diff --git a/drivers/net/dsa/netc/netc_switch.h b/drivers/net/dsa/netc/netc_switch.h
index 305f2a92e2f9..aeb08e6eda09 100644
--- a/drivers/net/dsa/netc/netc_switch.h
+++ b/drivers/net/dsa/netc/netc_switch.h
@@ -84,7 +84,7 @@ struct netc_port {
u16 uc:1;
u16 mc:1;
u16 pvid;
- struct ipft_entry_data *host_flood;
+ u32 ipft_hf_eid; /* Must be initialized to NTMP_NULL_ENTRY_ID */
};
struct netc_switch_regs {
--
2.34.1
next prev parent reply other threads:[~2026-09-18 7:25 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-18 7:28 [PATCH v4 net-next 0/8] net: dsa: netc: add PTP support for NETC switch wei.fang
2026-09-18 7:28 ` [PATCH v4 net-next 1/8] ptp: netc: use ioread64_lo_hi/iowrite64_lo_hi for 64-bit register access wei.fang
2026-09-30 13:26 ` Linus Walleij
2026-09-18 7:28 ` [PATCH v4 net-next 2/8] ptp: netc: remove unnecessary pcie_flr() call in probe wei.fang
2026-09-18 7:28 ` [PATCH v4 net-next 3/8] ptp: netc: export netc_timer_get_current_time() for cross-driver use wei.fang
2026-09-22 8:25 ` netdev-bot+sashiko
2026-09-22 9:48 ` Wei Fang
2026-09-18 7:28 ` wei.fang [this message]
2026-09-18 7:28 ` [PATCH v4 net-next 5/8] net: dsa: netc: check return value of ntmp_ipft_delete_entry() wei.fang
2026-09-22 8:25 ` netdev-bot+sashiko
2026-09-22 10:34 ` Wei Fang
2026-09-18 7:28 ` [PATCH v4 net-next 6/8] net: dsa: netc: enable ingress port filtering lookup by default wei.fang
2026-09-18 7:28 ` [PATCH v4 net-next 7/8] net: dsa: netc: add PTP two-step timestamping support wei.fang
2026-09-22 8:25 ` netdev-bot+sashiko
2026-09-23 2:43 ` Wei Fang
2026-09-18 7:28 ` [PATCH v4 net-next 8/8] net: dsa: netc: add PTP one-step " wei.fang
2026-09-19 7:26 ` sashiko-bot
2026-09-21 2:31 ` Wei Fang (OSS)
2026-09-22 8:25 ` netdev-bot+sashiko
2026-09-23 6:11 ` Wei Fang
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=20260918072852.501420-5-wei.fang@oss.nxp.com \
--to=wei.fang@oss.nxp.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=imx@lists.linux.dev \
--cc=kuba@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=wei.fang@nxp.com \
--cc=xiaoning.wang@nxp.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 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.