Skip to contentSkip to conversation

devlink port attr cleanup

PATCH Applied Parav Pandit 2 participants 4 messages Aug 13, 2025 – Aug 15, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover devlink port attr cleanup

Hi,

This two small patches simplifies the devlink port attributes set functions.

Summary:
patch-1 removes the return 0 check at several places and simplfies patch-2 constifies the attributes and moves the checks early caller

Please review.

changelog:
v1->v2:
- Addressed comments from Jakub and Vadim
- changed patch order
- replaced dl_port_attrs to attrs that matches implementation API declaration

Parav Pandit (2):
devlink/port: Simplify return checks devlink/port: Check attributes early and constify

 include/net/devlink.h |  2 +-
 net/devlink/port.c    | 33 ++++++++-------------------------
 2 files changed, 9 insertions(+), 26 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH v2 1/2 devlink/port: Simplify return checks

Drop always returning 0 from the helper routine and simplify its callers.

---
changelog:
v1->v2:
- Addressed comments from Jakub and Vadim
- changed patch order
v1: https://lore.kernel.org/netdev/[email protected]/T/#t

---
 net/devlink/port.c | 29 ++++++-----------------------
 1 file changed, 6 insertions(+), 23 deletions(-)
net/devlink/port.c +6 -23
index 939081a0e615..1bb5df75aa20 100644
@@ -1333,8 +1333,8 @@ int devlink_port_netdevice_event(struct notifier_block *nb,
 	return NOTIFY_OK;
 }
 
-static int __devlink_port_attrs_set(struct devlink_port *devlink_port,
-				    enum devlink_port_flavour flavour)
+static void __devlink_port_attrs_set(struct devlink_port *devlink_port,
+				     enum devlink_port_flavour flavour)
 {
 	struct devlink_port_attrs *attrs = &devlink_port->attrs;
 
@@ -1347,7 +1347,6 @@ static int __devlink_port_attrs_set(struct devlink_port *devlink_port,
 	} else {
 		devlink_port->switch_port = false;
 	}
-	return 0;
 }
 
 /**
@@ -1359,14 +1358,10 @@ static int __devlink_port_attrs_set(struct devlink_port *devlink_port,
 void devlink_port_attrs_set(struct devlink_port *devlink_port,
 			    struct devlink_port_attrs *attrs)
 {
-	int ret;
-
 	ASSERT_DEVLINK_PORT_NOT_REGISTERED(devlink_port);
 
 	devlink_port->attrs = *attrs;
-	ret = __devlink_port_attrs_set(devlink_port, attrs->flavour);
-	if (ret)
-		return;
+	__devlink_port_attrs_set(devlink_port, attrs->flavour);
 	WARN_ON(attrs->splittable && attrs->split);
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_set);
@@ -1383,14 +1378,10 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 contro
 				   u16 pf, bool external)
 {
 	struct devlink_port_attrs *attrs = &devlink_port->attrs;
-	int ret;
 
 	ASSERT_DEVLINK_PORT_NOT_REGISTERED(devlink_port);
 
-	ret = __devlink_port_attrs_set(devlink_port,
-				       DEVLINK_PORT_FLAVOUR_PCI_PF);
-	if (ret)
-		return;
+	__devlink_port_attrs_set(devlink_port, DEVLINK_PORT_FLAVOUR_PCI_PF);
 	attrs->pci_pf.controller = controller;
 	attrs->pci_pf.pf = pf;
 	attrs->pci_pf.external = external;
@@ -1411,14 +1402,10 @@ void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 contro
 				   u16 pf, u16 vf, bool external)
 {
 	struct devlink_port_attrs *attrs = &devlink_port->attrs;
-	int ret;
 
 	ASSERT_DEVLINK_PORT_NOT_REGISTERED(devlink_port);
 
-	ret = __devlink_port_attrs_set(devlink_port,
-				       DEVLINK_PORT_FLAVOUR_PCI_VF);
-	if (ret)
-		return;
+	__devlink_port_attrs_set(devlink_port, DEVLINK_PORT_FLAVOUR_PCI_VF);
 	attrs->pci_vf.controller = controller;
 	attrs->pci_vf.pf = pf;
 	attrs->pci_vf.vf = vf;
@@ -1439,14 +1426,10 @@ void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port, u32 contro
 				   u16 pf, u32 sf, bool external)
 {
 	struct devlink_port_attrs *attrs = &devlink_port->attrs;
-	int ret;
 
 	ASSERT_DEVLINK_PORT_NOT_REGISTERED(devlink_port);
 
-	ret = __devlink_port_attrs_set(devlink_port,
-				       DEVLINK_PORT_FLAVOUR_PCI_SF);
-	if (ret)
-		return;
+	__devlink_port_attrs_set(devlink_port, DEVLINK_PORT_FLAVOUR_PCI_SF);
 	attrs->pci_sf.controller = controller;
 	attrs->pci_sf.pf = pf;
 	attrs->pci_sf.sf = sf;
Signature · 1 line
2.26.2
#2 lore raw

PATCH v2 2/2 devlink/port: Check attributes early and constify

In reply to Parav Pandit

Constify the devlink port attributes to indicate they are read only and does not depend on anything else. Therefore, validate it early before setting in the devlink port.

---
changelog:
v1->v2:
- Addressed comments from Jakub and Vadim
- changed patch order
- replaced dl_port_attrs to attrs that matches implementation
v1: https://lore.kernel.org/netdev/[email protected]/T/#t

---
 include/net/devlink.h | 2 +-
 net/devlink/port.c    | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
include/net/devlink.h +1 -1
index 93640a29427c..052234f0d8ce 100644
@@ -1739,7 +1739,7 @@ void devlink_port_type_ib_set(struct devlink_port *devlink_port,
 			      struct ib_device *ibdev);
 void devlink_port_type_clear(struct devlink_port *devlink_port);
 void devlink_port_attrs_set(struct devlink_port *devlink_port,
-			    struct devlink_port_attrs *devlink_port_attrs);
+			    const struct devlink_port_attrs *attrs);
 void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 controller,
 				   u16 pf, bool external);
 void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 controller,
net/devlink/port.c +2 -2
index 1bb5df75aa20..93f2969b9cf3 100644
@@ -1356,13 +1356,13 @@ static void __devlink_port_attrs_set(struct devlink_port *devlink_port,
  *	@attrs: devlink port attrs
  */
 void devlink_port_attrs_set(struct devlink_port *devlink_port,
-			    struct devlink_port_attrs *attrs)
+			    const struct devlink_port_attrs *attrs)
 {
 	ASSERT_DEVLINK_PORT_NOT_REGISTERED(devlink_port);
+	WARN_ON(attrs->splittable && attrs->split);
 
 	devlink_port->attrs = *attrs;
 	__devlink_port_attrs_set(devlink_port, attrs->flavour);
-	WARN_ON(attrs->splittable && attrs->split);
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_set);
 
Signature · 1 line
2.26.2
#3 lore raw
In reply to Parav Pandit
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 11 lines · On Wed, 13 Aug 2025 12:44:15 +0300 you wrote:

Hi,

This two small patches simplifies the devlink port attributes set functions.

Summary:
patch-1 removes the return 0 check at several places and simplfies patch-2 constifies the attributes and moves the checks early caller

[...]

Here is the summary with links:
- [net-next,v2,1/2] devlink/port: Simplify return checks

    https://git.kernel.org/netdev/net-next/c/0ebc0bcd0aa0
  - [net-next,v2,2/2] devlink/port: Check attributes early and constify
    https://git.kernel.org/netdev/net-next/c/41a6e8ab1864

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html