Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v2 0/5] devlink: Warn on resource ID collision with PARENT_TOP
@ 2026-06-11  7:08 David Yang
  2026-06-11  7:08 ` [PATCH net-next v2 1/5] net: dsa: dsa_loop: avoid devlink resource IDs " David Yang
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: David Yang @ 2026-06-11  7:08 UTC (permalink / raw)
  To: netdev
  Cc: David Yang, Florian Fainelli, Jonas Gorski, Andrew Lunn,
	Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Kurt Kanzenbach, Jiri Pirko, Simon Horman,
	linux-kernel

Filter out the ambiguous case of

enum {
    MY_RESOURCE_ID_A,  /* == DEVLINK_RESOURCE_ID_PARENT_TOP ! */
    MY_RESOURCE_ID_B,
    ...
};

register(..., MY_RESOURCE_ID_A, DEVLINK_RESOURCE_ID_PARENT_TOP, ...);
register(..., MY_RESOURCE_ID_B, MY_RESOURCE_ID_A, ...);

v1: https://lore.kernel.org/r/20260610062554.769892-1-mmyangfl@gmail.com
  - make a patchset

David Yang (5):
  net: dsa: dsa_loop: avoid devlink resource IDs collision with
    PARENT_TOP
  net: dsa: b53: avoid devlink resource IDs collision with PARENT_TOP
  net: dsa: hellcreek: avoid devlink resource IDs collision with
    PARENT_TOP
  net: dsa: mv88e6xxx: Avoid devlink resource IDs collision with
    PARENT_TOP
  devlink: Warn on resource ID collision with PARENT_TOP

 drivers/net/dsa/b53/b53_common.c       | 1 +
 drivers/net/dsa/dsa_loop.c             | 1 +
 drivers/net/dsa/hirschmann/hellcreek.h | 1 +
 drivers/net/dsa/mv88e6xxx/devlink.c    | 9 +++++----
 net/devlink/resource.c                 | 2 ++
 5 files changed, 10 insertions(+), 4 deletions(-)

-- 
2.53.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 1/5] net: dsa: dsa_loop: avoid devlink resource IDs collision with PARENT_TOP
  2026-06-11  7:08 [PATCH net-next v2 0/5] devlink: Warn on resource ID collision with PARENT_TOP David Yang
@ 2026-06-11  7:08 ` David Yang
  2026-06-11  7:08 ` [PATCH net-next v2 2/5] net: dsa: b53: " David Yang
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: David Yang @ 2026-06-11  7:08 UTC (permalink / raw)
  To: netdev
  Cc: David Yang, Florian Fainelli, Jonas Gorski, Andrew Lunn,
	Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Kurt Kanzenbach, Jiri Pirko, Simon Horman,
	linux-kernel

This might not cause real problems, but the dsa_loop devlink resource ID
collides with the sentinel DEVLINK_RESOURCE_ID_PARENT_TOP (0). Avoid it
by keeping the real resource IDs starting at 1.

Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/net/dsa/dsa_loop.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/dsa/dsa_loop.c b/drivers/net/dsa/dsa_loop.c
index 7058faf23592..0e35e9841b9b 100644
--- a/drivers/net/dsa/dsa_loop.c
+++ b/drivers/net/dsa/dsa_loop.c
@@ -75,6 +75,7 @@ static struct phy_device *phydevs[PHY_MAX_ADDR];
 static struct mdio_device *switch_mdiodev;
 
 enum dsa_loop_devlink_resource_id {
+	DSA_LOOP_DEVLINK_PARAM_ID_NONE,  /* DEVLINK_RESOURCE_ID_PARENT_TOP */
 	DSA_LOOP_DEVLINK_PARAM_ID_VTU,
 };
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 2/5] net: dsa: b53: avoid devlink resource IDs collision with PARENT_TOP
  2026-06-11  7:08 [PATCH net-next v2 0/5] devlink: Warn on resource ID collision with PARENT_TOP David Yang
  2026-06-11  7:08 ` [PATCH net-next v2 1/5] net: dsa: dsa_loop: avoid devlink resource IDs " David Yang
@ 2026-06-11  7:08 ` David Yang
  2026-06-11  7:08 ` [PATCH net-next v2 3/5] net: dsa: hellcreek: " David Yang
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: David Yang @ 2026-06-11  7:08 UTC (permalink / raw)
  To: netdev
  Cc: David Yang, Florian Fainelli, Jonas Gorski, Andrew Lunn,
	Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Kurt Kanzenbach, Jiri Pirko, Simon Horman,
	linux-kernel

This might not cause real problems, but the b53 devlink resource ID
collides with the sentinel DEVLINK_RESOURCE_ID_PARENT_TOP (0). Avoid it
by keeping the real resource IDs starting at 1.

Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/net/dsa/b53/b53_common.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index 06b8be8dc4db..3f5b9592794d 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -1225,6 +1225,7 @@ int b53_get_sset_count(struct dsa_switch *ds, int port, int sset)
 EXPORT_SYMBOL(b53_get_sset_count);
 
 enum b53_devlink_resource_id {
+	B53_DEVLINK_PARAM_ID_NONE,  /* DEVLINK_RESOURCE_ID_PARENT_TOP */
 	B53_DEVLINK_PARAM_ID_VLAN_TABLE,
 };
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 3/5] net: dsa: hellcreek: avoid devlink resource IDs collision with PARENT_TOP
  2026-06-11  7:08 [PATCH net-next v2 0/5] devlink: Warn on resource ID collision with PARENT_TOP David Yang
  2026-06-11  7:08 ` [PATCH net-next v2 1/5] net: dsa: dsa_loop: avoid devlink resource IDs " David Yang
  2026-06-11  7:08 ` [PATCH net-next v2 2/5] net: dsa: b53: " David Yang
@ 2026-06-11  7:08 ` David Yang
  2026-06-11  7:39   ` Kurt Kanzenbach
  2026-06-11  7:08 ` [PATCH net-next v2 4/5] net: dsa: mv88e6xxx: Avoid " David Yang
  2026-06-11  7:08 ` [PATCH net-next v2 5/5] devlink: Warn on resource ID " David Yang
  4 siblings, 1 reply; 7+ messages in thread
From: David Yang @ 2026-06-11  7:08 UTC (permalink / raw)
  To: netdev
  Cc: David Yang, Florian Fainelli, Jonas Gorski, Andrew Lunn,
	Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Kurt Kanzenbach, Jiri Pirko, Simon Horman,
	linux-kernel

This might not cause real problems, but the hellcreek devlink resource
ID collides with the sentinel DEVLINK_RESOURCE_ID_PARENT_TOP (0). Avoid
it by keeping the real resource IDs starting at 1.

Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/net/dsa/hirschmann/hellcreek.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/dsa/hirschmann/hellcreek.h b/drivers/net/dsa/hirschmann/hellcreek.h
index bebf0d3ff330..95593b5f002c 100644
--- a/drivers/net/dsa/hirschmann/hellcreek.h
+++ b/drivers/net/dsa/hirschmann/hellcreek.h
@@ -311,6 +311,7 @@ struct hellcreek {
 
 /* Devlink resources */
 enum hellcreek_devlink_resource_id {
+	HELLCREEK_DEVLINK_PARAM_ID_NONE,  /* DEVLINK_RESOURCE_ID_PARENT_TOP */
 	HELLCREEK_DEVLINK_PARAM_ID_VLAN_TABLE,
 	HELLCREEK_DEVLINK_PARAM_ID_FDB_TABLE,
 };
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 4/5] net: dsa: mv88e6xxx: Avoid devlink resource IDs collision with PARENT_TOP
  2026-06-11  7:08 [PATCH net-next v2 0/5] devlink: Warn on resource ID collision with PARENT_TOP David Yang
                   ` (2 preceding siblings ...)
  2026-06-11  7:08 ` [PATCH net-next v2 3/5] net: dsa: hellcreek: " David Yang
@ 2026-06-11  7:08 ` David Yang
  2026-06-11  7:08 ` [PATCH net-next v2 5/5] devlink: Warn on resource ID " David Yang
  4 siblings, 0 replies; 7+ messages in thread
From: David Yang @ 2026-06-11  7:08 UTC (permalink / raw)
  To: netdev
  Cc: David Yang, Florian Fainelli, Jonas Gorski, Andrew Lunn,
	Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Kurt Kanzenbach, Jiri Pirko, Simon Horman,
	linux-kernel

The devlink resource ID for ATU collides with the sentinel
DEVLINK_RESOURCE_ID_PARENT_TOP (0). As a result, ATU_bin_* are
registered as in fact registered as top-level siblings, not as children
of ATU.

Whether intentional or unintentional, clarify it by keeping the real
resource IDs starting at 1. Unfortunately ATU_bin_* are already
registered at top-level, so keep their parent to PARENT_TOP.

Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/net/dsa/mv88e6xxx/devlink.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/net/dsa/mv88e6xxx/devlink.c b/drivers/net/dsa/mv88e6xxx/devlink.c
index 0f84bffc8ef1..6f034841883c 100644
--- a/drivers/net/dsa/mv88e6xxx/devlink.c
+++ b/drivers/net/dsa/mv88e6xxx/devlink.c
@@ -91,6 +91,7 @@ void mv88e6xxx_teardown_devlink_params(struct dsa_switch *ds)
 }
 
 enum mv88e6xxx_devlink_resource_id {
+	MV88E6XXX_RESOURCE_ID_NONE,  /* DEVLINK_RESOURCE_ID_PARENT_TOP */
 	MV88E6XXX_RESOURCE_ID_ATU,
 	MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
 	MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
@@ -200,7 +201,7 @@ int mv88e6xxx_setup_devlink_resources(struct dsa_switch *ds)
 	err = dsa_devlink_resource_register(ds, "ATU_bin_0",
 					    mv88e6xxx_num_macs(chip) / 4,
 					    MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
-					    MV88E6XXX_RESOURCE_ID_ATU,
+					    DEVLINK_RESOURCE_ID_PARENT_TOP,
 					    &size_params);
 	if (err)
 		goto out;
@@ -208,7 +209,7 @@ int mv88e6xxx_setup_devlink_resources(struct dsa_switch *ds)
 	err = dsa_devlink_resource_register(ds, "ATU_bin_1",
 					    mv88e6xxx_num_macs(chip) / 4,
 					    MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
-					    MV88E6XXX_RESOURCE_ID_ATU,
+					    DEVLINK_RESOURCE_ID_PARENT_TOP,
 					    &size_params);
 	if (err)
 		goto out;
@@ -216,7 +217,7 @@ int mv88e6xxx_setup_devlink_resources(struct dsa_switch *ds)
 	err = dsa_devlink_resource_register(ds, "ATU_bin_2",
 					    mv88e6xxx_num_macs(chip) / 4,
 					    MV88E6XXX_RESOURCE_ID_ATU_BIN_2,
-					    MV88E6XXX_RESOURCE_ID_ATU,
+					    DEVLINK_RESOURCE_ID_PARENT_TOP,
 					    &size_params);
 	if (err)
 		goto out;
@@ -224,7 +225,7 @@ int mv88e6xxx_setup_devlink_resources(struct dsa_switch *ds)
 	err = dsa_devlink_resource_register(ds, "ATU_bin_3",
 					    mv88e6xxx_num_macs(chip) / 4,
 					    MV88E6XXX_RESOURCE_ID_ATU_BIN_3,
-					    MV88E6XXX_RESOURCE_ID_ATU,
+					    DEVLINK_RESOURCE_ID_PARENT_TOP,
 					    &size_params);
 	if (err)
 		goto out;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 5/5] devlink: Warn on resource ID collision with PARENT_TOP
  2026-06-11  7:08 [PATCH net-next v2 0/5] devlink: Warn on resource ID collision with PARENT_TOP David Yang
                   ` (3 preceding siblings ...)
  2026-06-11  7:08 ` [PATCH net-next v2 4/5] net: dsa: mv88e6xxx: Avoid " David Yang
@ 2026-06-11  7:08 ` David Yang
  4 siblings, 0 replies; 7+ messages in thread
From: David Yang @ 2026-06-11  7:08 UTC (permalink / raw)
  To: netdev
  Cc: David Yang, Florian Fainelli, Jonas Gorski, Andrew Lunn,
	Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Kurt Kanzenbach, Jiri Pirko, Simon Horman,
	linux-kernel

ID 0 serves as the sentinel DEVLINK_RESOURCE_ID_PARENT_TOP to mark
top-level resources. While it is technically possible to use 0 as a real
resource ID, a user might be tempted to write:

enum {
    MY_RESOURCE_ID_A,  /* == DEVLINK_RESOURCE_ID_PARENT_TOP ! */
    MY_RESOURCE_ID_B,
    MY_RESOURCE_ID_C,
    MY_RESOURCE_ID_D,
    ...
};

register(..., MY_RESOURCE_ID_C, DEVLINK_RESOURCE_ID_PARENT_TOP, ...);
register(..., MY_RESOURCE_ID_D, MY_RESOURCE_ID_C, ...);
/* D is a child of C */

register(..., MY_RESOURCE_ID_A, DEVLINK_RESOURCE_ID_PARENT_TOP, ...);
register(..., MY_RESOURCE_ID_B, MY_RESOURCE_ID_A, ...);
/* Is B intentionally top-level, or is it actually a child of A? */

Add a WARN_ON() to catch this and prevent confusion.

Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 net/devlink/resource.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/devlink/resource.c b/net/devlink/resource.c
index 3d2f42bc2fb5..574108ccfe5d 100644
--- a/net/devlink/resource.c
+++ b/net/devlink/resource.c
@@ -486,6 +486,8 @@ __devl_resource_register(struct devlink *devlink,
 	struct list_head *resource_list;
 	bool top_hierarchy;
 
+	WARN_ON(resource_id == DEVLINK_RESOURCE_ID_PARENT_TOP);
+
 	lockdep_assert_held(&devlink->lock);
 
 	top_hierarchy = parent_resource_id == DEVLINK_RESOURCE_ID_PARENT_TOP;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 3/5] net: dsa: hellcreek: avoid devlink resource IDs collision with PARENT_TOP
  2026-06-11  7:08 ` [PATCH net-next v2 3/5] net: dsa: hellcreek: " David Yang
@ 2026-06-11  7:39   ` Kurt Kanzenbach
  0 siblings, 0 replies; 7+ messages in thread
From: Kurt Kanzenbach @ 2026-06-11  7:39 UTC (permalink / raw)
  To: David Yang, netdev
  Cc: David Yang, Florian Fainelli, Jonas Gorski, Andrew Lunn,
	Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Jiri Pirko, Simon Horman, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 337 bytes --]

On Thu Jun 11 2026, David Yang wrote:
> This might not cause real problems, but the hellcreek devlink resource
> ID collides with the sentinel DEVLINK_RESOURCE_ID_PARENT_TOP (0). Avoid
> it by keeping the real resource IDs starting at 1.
>
> Signed-off-by: David Yang <mmyangfl@gmail.com>

Acked-by: Kurt Kanzenbach <kurt@linutronix.de>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-06-11  7:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-11  7:08 [PATCH net-next v2 0/5] devlink: Warn on resource ID collision with PARENT_TOP David Yang
2026-06-11  7:08 ` [PATCH net-next v2 1/5] net: dsa: dsa_loop: avoid devlink resource IDs " David Yang
2026-06-11  7:08 ` [PATCH net-next v2 2/5] net: dsa: b53: " David Yang
2026-06-11  7:08 ` [PATCH net-next v2 3/5] net: dsa: hellcreek: " David Yang
2026-06-11  7:39   ` Kurt Kanzenbach
2026-06-11  7:08 ` [PATCH net-next v2 4/5] net: dsa: mv88e6xxx: Avoid " David Yang
2026-06-11  7:08 ` [PATCH net-next v2 5/5] devlink: Warn on resource ID " David Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox