Skip to contentSkip to conversation

net: phylink: constify fwnode arguments

PATCH In review Russell King (Oracle) 5 participants 7 messages May 10, 2023 – May 11, 2023

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

PATCH 1/1 net: phylink: constify fwnode arguments

Both phylink_create() and phylink_fwnode_phy_connect() do not modify the fwnode argument that they are passed, so lets constify these.

---
 drivers/net/phy/phylink.c | 11 ++++++-----
 include/linux/phylink.h   |  5 +++--
 2 files changed, 9 insertions(+), 7 deletions(-)
drivers/net/phy/phylink.c +6 -5
index a4111f1be375..cf53096047e6 100644
@@ -708,7 +708,7 @@ static int phylink_validate(struct phylink *pl, unsigned long *supported,
 }
 
 static int phylink_parse_fixedlink(struct phylink *pl,
-				   struct fwnode_handle *fwnode)
+				   const struct fwnode_handle *fwnode)
 {
 	struct fwnode_handle *fixed_node;
 	bool pause, asym_pause, autoneg;
@@ -819,7 +819,8 @@ static int phylink_parse_fixedlink(struct phylink *pl,
 	return 0;
 }
 
-static int phylink_parse_mode(struct phylink *pl, struct fwnode_handle *fwnode)
+static int phylink_parse_mode(struct phylink *pl,
+			      const struct fwnode_handle *fwnode)
 {
 	struct fwnode_handle *dn;
 	const char *managed;
@@ -1441,7 +1442,7 @@ static void phylink_fixed_poll(struct timer_list *t)
 static const struct sfp_upstream_ops sfp_phylink_ops;
 
 static int phylink_register_sfp(struct phylink *pl,
-				struct fwnode_handle *fwnode)
+				const struct fwnode_handle *fwnode)
 {
 	struct sfp_bus *bus;
 	int ret;
@@ -1480,7 +1481,7 @@ static int phylink_register_sfp(struct phylink *pl,
  * must use IS_ERR() to check for errors from this function.
  */
 struct phylink *phylink_create(struct phylink_config *config,
-			       struct fwnode_handle *fwnode,
+			       const struct fwnode_handle *fwnode,
 			       phy_interface_t iface,
 			       const struct phylink_mac_ops *mac_ops)
 {
@@ -1809,7 +1810,7 @@ EXPORT_SYMBOL_GPL(phylink_of_phy_connect);
  * Returns 0 on success or a negative errno.
  */
 int phylink_fwnode_phy_connect(struct phylink *pl,
-			       struct fwnode_handle *fwnode,
+			       const struct fwnode_handle *fwnode,
 			       u32 flags)
 {
 	struct fwnode_handle *phy_fwnode;
include/linux/phylink.h +3 -2
index 71755c66c162..02c777ad18f2 100644
@@ -568,7 +568,8 @@ void phylink_generic_validate(struct phylink_config *config,
 			      unsigned long *supported,
 			      struct phylink_link_state *state);
 
-struct phylink *phylink_create(struct phylink_config *, struct fwnode_handle *,
+struct phylink *phylink_create(struct phylink_config *,
+			       const struct fwnode_handle *,
 			       phy_interface_t iface,
 			       const struct phylink_mac_ops *mac_ops);
 void phylink_destroy(struct phylink *);
@@ -577,7 +578,7 @@ bool phylink_expects_phy(struct phylink *pl);
 int phylink_connect_phy(struct phylink *, struct phy_device *);
 int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags);
 int phylink_fwnode_phy_connect(struct phylink *pl,
-			       struct fwnode_handle *fwnode,
+			       const struct fwnode_handle *fwnode,
 			       u32 flags);
 void phylink_disconnect_phy(struct phylink *);
 
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#2 lore raw
In reply to Russell King (Oracle)
Quoted 3 lines · Russell King (Oracle)

Both phylink_create() and phylink_fwnode_phy_connect() do not modify the fwnode argument that they are passed, so lets constify these.

Thank you!

Quoted 82 lines
---
 drivers/net/phy/phylink.c | 11 ++++++-----
 include/linux/phylink.h   |  5 +++--
 2 files changed, 9 insertions(+), 7 deletions(-)
drivers/net/phy/phylink.c +6 -5
index a4111f1be375..cf53096047e6 100644
@@ -708,7 +708,7 @@ static int phylink_validate(struct phylink *pl, unsigned long *supported,
 }
 
 static int phylink_parse_fixedlink(struct phylink *pl,
-                                  struct fwnode_handle *fwnode)
+                                  const struct fwnode_handle *fwnode)
 {
        struct fwnode_handle *fixed_node;
        bool pause, asym_pause, autoneg;
@@ -819,7 +819,8 @@ static int phylink_parse_fixedlink(struct phylink *pl,
        return 0;
 }
 
-static int phylink_parse_mode(struct phylink *pl, struct fwnode_handle *fwnode)
+static int phylink_parse_mode(struct phylink *pl,
+                             const struct fwnode_handle *fwnode)
 {
        struct fwnode_handle *dn;
        const char *managed;
@@ -1441,7 +1442,7 @@ static void phylink_fixed_poll(struct timer_list *t)
 static const struct sfp_upstream_ops sfp_phylink_ops;
 
 static int phylink_register_sfp(struct phylink *pl,
-                               struct fwnode_handle *fwnode)
+                               const struct fwnode_handle *fwnode)
 {
        struct sfp_bus *bus;
        int ret;
@@ -1480,7 +1481,7 @@ static int phylink_register_sfp(struct phylink *pl,
  * must use IS_ERR() to check for errors from this function.
  */
 struct phylink *phylink_create(struct phylink_config *config,
-                              struct fwnode_handle *fwnode,
+                              const struct fwnode_handle *fwnode,
                               phy_interface_t iface,
                               const struct phylink_mac_ops *mac_ops)
 {
@@ -1809,7 +1810,7 @@ EXPORT_SYMBOL_GPL(phylink_of_phy_connect);
  * Returns 0 on success or a negative errno.
  */
 int phylink_fwnode_phy_connect(struct phylink *pl,
-                              struct fwnode_handle *fwnode,
+                              const struct fwnode_handle *fwnode,
                               u32 flags)
 {
        struct fwnode_handle *phy_fwnode;
include/linux/phylink.h +3 -3
index 71755c66c162..02c777ad18f2 100644
@@ -568,7 +568,8 @@ void phylink_generic_validate(struct phylink_config *config,
                              unsigned long *supported,
                              struct phylink_link_state *state);
 
-struct phylink *phylink_create(struct phylink_config *, struct fwnode_handle *,
+struct phylink *phylink_create(struct phylink_config *,
+                              const struct fwnode_handle *,
                               phy_interface_t iface,
                               const struct phylink_mac_ops *mac_ops);
 void phylink_destroy(struct phylink *);
@@ -577,7 +578,7 @@ bool phylink_expects_phy(struct phylink *pl);
 int phylink_connect_phy(struct phylink *, struct phy_device *);
 int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags);
 int phylink_fwnode_phy_connect(struct phylink *pl,
-                              struct fwnode_handle *fwnode,
+                              const struct fwnode_handle *fwnode,
                               u32 flags);
 void phylink_disconnect_phy(struct phylink *);
 
--

2.30.2

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#3 lore raw
In reply to Russell King (Oracle)

include/linux/phylink.h void phylink_generic_validate(struct phylink_config *config, · line 572

Quoted 11 lines · Russell King (Oracle)
include/linux/phylink.h +2 -1
index 71755c66c162..02c777ad18f2 100644
@@ -568,7 +568,8 @@ void phylink_generic_validate(struct phylink_config *config,
 			      unsigned long *supported,
 			      struct phylink_link_state *state);
 
-struct phylink *phylink_create(struct phylink_config *, struct fwnode_handle *,
+struct phylink *phylink_create(struct phylink_config *,
+			       const struct fwnode_handle *,

While touching the above, could you please also add the missing params name, to keep checkpatch happy and be consistent with the others arguments?

Thanks!

Paolo

#4 lore raw
Quoted 9 lines · Paolo Abeni
Quoted 8 lines · Russell King (Oracle)
include/linux/phylink.h +0 -0
index 71755c66c162..02c777ad18f2 100644
@@ -568,7 +568,8 @@ void phylink_generic_validate(struct phylink_config *config,
 			      unsigned long *supported,
 			      struct phylink_link_state *state);
 
Quoted 7 lines

include/linux/phylink.h void phylink_generic_validate(struct phylink_config *config, · line 572

Quoted 3 lines
include/linux/phylink.h +2 -1
-struct phylink *phylink_create(struct phylink_config *, struct fwnode_handle *,
+struct phylink *phylink_create(struct phylink_config *,
+			       const struct fwnode_handle *,

While touching the above, could you please also add the missing params name, to keep checkpatch happy and be consistent with the others arguments?

For interest, when did naming parameters in a prototype become a requirement?

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
maintainer
#5 lore raw
Quoted 18 lines · Russell King (Oracle)
Quoted 9 lines · Paolo Abeni
Quoted 8 lines · Russell King (Oracle)
include/linux/phylink.h +0 -0
index 71755c66c162..02c777ad18f2 100644
@@ -568,7 +568,8 @@ void phylink_generic_validate(struct phylink_config *config,
 			      unsigned long *supported,
 			      struct phylink_link_state *state);
 
Quoted 7 lines

include/linux/phylink.h void phylink_generic_validate(struct phylink_config *config, · line 572

Quoted 3 lines
include/linux/phylink.h +2 -1
-struct phylink *phylink_create(struct phylink_config *, struct fwnode_handle *,
+struct phylink *phylink_create(struct phylink_config *,
+			       const struct fwnode_handle *,

While touching the above, could you please also add the missing params name, to keep checkpatch happy and be consistent with the others arguments?

Quoted 2 lines

For interest, when did naming parameters in a prototype become a requirement?

I would not call it a general requirement, but in this specific case we have 2 named params and 2 unnamed ones for the same function, which looks not good to me. Since you are touching that function definition and checkpatch is complaining about the above, I think it would be better to make the function declaration self-consistent.

Looking again at the checkpatch warning, that is possibly a false positive - git history hints such check should apply only to function definition, not declaration.

I still think it would be better removing the mixed unnamed/named params usage.

Thanks,

Paolo

#6 lore raw
Quoted 28 lines · Paolo Abeni
Quoted 18 lines · Russell King (Oracle)
Quoted 9 lines · Paolo Abeni
Quoted 8 lines · Russell King (Oracle)
include/linux/phylink.h +0 -0
index 71755c66c162..02c777ad18f2 100644
@@ -568,7 +568,8 @@ void phylink_generic_validate(struct phylink_config *config,
 			      unsigned long *supported,
 			      struct phylink_link_state *state);
 
Quoted 7 lines

include/linux/phylink.h void phylink_generic_validate(struct phylink_config *config, · line 572

Quoted 3 lines
include/linux/phylink.h +2 -1
-struct phylink *phylink_create(struct phylink_config *, struct fwnode_handle *,
+struct phylink *phylink_create(struct phylink_config *,
+			       const struct fwnode_handle *,

While touching the above, could you please also add the missing params name, to keep checkpatch happy and be consistent with the others arguments?

Quoted 2 lines

For interest, when did naming parameters in a prototype become a requirement?

I would not call it a general requirement, but in this specific case we have 2 named params and 2 unnamed ones for the same function, which looks not good to me. Since you are touching that function definition and checkpatch is complaining about the above, I think it would be better to make the function declaration self-consistent.

Quoted 6 lines

Looking again at the checkpatch warning, that is possibly a false positive - git history hints such check should apply only to function definition, not declaration.

I still think it would be better removing the mixed unnamed/named params usage.

In this particular instance, I think removing them is appropriate, since giving names for them doesn't contribute anything useful (since the types give allt he information necessary.)

However, for something like a function that takes e.g. a u32 and a bunch of other unique structs, I think it is entirely appropriate to use mixed named/unnamed parameters - since a "u32" can't describe on its own what it is. Hence, I think, e.g.:

int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags);

is entirely reasonable, since "flags" describes what the u32 is. Adding "pl" and "dn" to the other two arguments doesn't add any useful value.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!