Skip to contentSkip to conversation

driver core: Move fw_devlink stuff to where it belongs

PATCH In review Andy Shevchenko 3 participants 8 messages Feb 20, 2024 – Feb 23, 2024

Subsystems (3)
lore
Share & tools
lore

Andy Shevchenko

author reviewer
#0 lore raw

PATCH 1/1 driver core: Move fw_devlink stuff to where it belongs

A few APIs that belong specifically to the fw_devlink APIs
- are exposed to others without need
- prevents device property code to be cleaned up in the future

Resolve this mess by moving fw_devlink code to where it belongs and hide from others.

Fixes b5d3e2fbcb10 ("device property: Add fwnode_is_ancestor_of() and fwnode_get_next_parent_dev()")
Fixes 372a67c0c5ef ("driver core: Add fwnode_to_dev() to look up device from fwnode")
---
 drivers/base/core.c      | 58 ++++++++++++++++++++++++++++++++++++++++
 drivers/base/property.c  | 56 --------------------------------------
 include/linux/fwnode.h   |  1 -
 include/linux/property.h |  2 --
 4 files changed, 58 insertions(+), 59 deletions(-)
drivers/base/core.c +58 -0
index 9828da9b933c..35ccd8bb2c9b 100644
@@ -1871,6 +1871,7 @@ static void fw_devlink_unblock_consumers(struct device *dev)
 	device_links_write_unlock();
 }
 
+#define get_dev_from_fwnode(fwnode)	get_device((fwnode)->dev)
 
 static bool fwnode_init_without_drv(struct fwnode_handle *fwnode)
 {
@@ -1901,6 +1902,63 @@ static bool fwnode_ancestor_init_without_drv(struct fwnode_handle *fwnode)
 	return false;
 }
 
+/**
+ * fwnode_is_ancestor_of - Test if @ancestor is ancestor of @child
+ * @ancestor: Firmware which is tested for being an ancestor
+ * @child: Firmware which is tested for being the child
+ *
+ * A node is considered an ancestor of itself too.
+ *
+ * Return: true if @ancestor is an ancestor of @child. Otherwise, returns false.
+ */
+static bool fwnode_is_ancestor_of(const struct fwnode_handle *ancestor,
+				  const struct fwnode_handle *child)
+{
+	struct fwnode_handle *parent;
+
+	if (IS_ERR_OR_NULL(ancestor))
+		return false;
+
+	if (child == ancestor)
+		return true;
+
+	fwnode_for_each_parent_node(child, parent) {
+		if (parent == ancestor) {
+			fwnode_handle_put(parent);
+			return true;
+		}
+	}
+	return false;
+}
+
+/**
+ * fwnode_get_next_parent_dev - Find device of closest ancestor fwnode
+ * @fwnode: firmware node
+ *
+ * Given a firmware node (@fwnode), this function finds its closest ancestor
+ * firmware node that has a corresponding struct device and returns that struct
+ * device.
+ *
+ * The caller is responsible for calling put_device() on the returned device
+ * pointer.
+ *
+ * Return: a pointer to the device of the @fwnode's closest ancestor.
+ */
+static struct device *fwnode_get_next_parent_dev(const struct fwnode_handle *fwnode)
+{
+	struct fwnode_handle *parent;
+	struct device *dev;
+
+	fwnode_for_each_parent_node(fwnode, parent) {
+		dev = get_dev_from_fwnode(parent);
+		if (dev) {
+			fwnode_handle_put(parent);
+			return dev;
+		}
+	}
+	return NULL;
+}
+
 /**
  * __fw_devlink_relax_cycles - Relax and mark dependency cycles.
  * @con: Potential consumer device.
drivers/base/property.c +0 -56

68 lines not on this page · raw message

include/linux/fwnode.h +0 -1
index 0428942093a7..4228c45d5ccc 100644
@@ -193,7 +193,6 @@ struct fwnode_operations {
 		if (fwnode_has_op(fwnode, op))				\
 			(fwnode)->ops->op(fwnode, ## __VA_ARGS__);	\
 	} while (false)
-#define get_dev_from_fwnode(fwnode)	get_device((fwnode)->dev)
 
 static inline void fwnode_init(struct fwnode_handle *fwnode,
 			       const struct fwnode_operations *ops)
include/linux/property.h +0 -2
index 07fbebc73243..1f0135e24d00 100644
@@ -150,11 +150,9 @@ struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode);
 	for (parent = fwnode_get_parent(fwnode); parent;	\
 	     parent = fwnode_get_next_parent(parent))
 
-struct device *fwnode_get_next_parent_dev(const struct fwnode_handle *fwnode);
 unsigned int fwnode_count_parents(const struct fwnode_handle *fwn);
 struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn,
 					    unsigned int depth);
-bool fwnode_is_ancestor_of(const struct fwnode_handle *ancestor, const struct fwnode_handle *child);
 struct fwnode_handle *fwnode_get_next_child_node(
 	const struct fwnode_handle *fwnode, struct fwnode_handle *child);
 struct fwnode_handle *fwnode_get_next_available_child_node(
Signature · 1 line
2.43.0.rc1.1.gbec44491f096
#1 lore raw
Quoted 185 lines · Andy Shevchenko

A few APIs that belong specifically to the fw_devlink APIs
- are exposed to others without need
- prevents device property code to be cleaned up in the future

Resolve this mess by moving fw_devlink code to where it belongs and hide from others.

Fixes b5d3e2fbcb10 ("device property: Add fwnode_is_ancestor_of() and fwnode_get_next_parent_dev()")
Fixes 372a67c0c5ef ("driver core: Add fwnode_to_dev() to look up device from fwnode")
---
 drivers/base/core.c      | 58 ++++++++++++++++++++++++++++++++++++++++
 drivers/base/property.c  | 56 --------------------------------------
 include/linux/fwnode.h   |  1 -
 include/linux/property.h |  2 --
 4 files changed, 58 insertions(+), 59 deletions(-)
drivers/base/core.c +58 -0
index 9828da9b933c..35ccd8bb2c9b 100644
@@ -1871,6 +1871,7 @@ static void fw_devlink_unblock_consumers(struct device *dev)
        device_links_write_unlock();
 }
 
+#define get_dev_from_fwnode(fwnode)    get_device((fwnode)->dev)
 
 static bool fwnode_init_without_drv(struct fwnode_handle *fwnode)
 {
@@ -1901,6 +1902,63 @@ static bool fwnode_ancestor_init_without_drv(struct fwnode_handle *fwnode)
        return false;
 }
 
+/**
+ * fwnode_is_ancestor_of - Test if @ancestor is ancestor of @child
+ * @ancestor: Firmware which is tested for being an ancestor
+ * @child: Firmware which is tested for being the child
+ *
+ * A node is considered an ancestor of itself too.
+ *
+ * Return: true if @ancestor is an ancestor of @child. Otherwise, returns false.
+ */
+static bool fwnode_is_ancestor_of(const struct fwnode_handle *ancestor,
+                                 const struct fwnode_handle *child)
+{
+       struct fwnode_handle *parent;
+
+       if (IS_ERR_OR_NULL(ancestor))
+               return false;
+
+       if (child == ancestor)
+               return true;
+
+       fwnode_for_each_parent_node(child, parent) {
+               if (parent == ancestor) {
+                       fwnode_handle_put(parent);
+                       return true;
+               }
+       }
+       return false;
+}
+
+/**
+ * fwnode_get_next_parent_dev - Find device of closest ancestor fwnode
+ * @fwnode: firmware node
+ *
+ * Given a firmware node (@fwnode), this function finds its closest ancestor
+ * firmware node that has a corresponding struct device and returns that struct
+ * device.
+ *
+ * The caller is responsible for calling put_device() on the returned device
+ * pointer.
+ *
+ * Return: a pointer to the device of the @fwnode's closest ancestor.
+ */
+static struct device *fwnode_get_next_parent_dev(const struct fwnode_handle *fwnode)
+{
+       struct fwnode_handle *parent;
+       struct device *dev;
+
+       fwnode_for_each_parent_node(fwnode, parent) {
+               dev = get_dev_from_fwnode(parent);
+               if (dev) {
+                       fwnode_handle_put(parent);
+                       return dev;
+               }
+       }
+       return NULL;
+}
+
 /**
  * __fw_devlink_relax_cycles - Relax and mark dependency cycles.
  * @con: Potential consumer device.
drivers/base/property.c +0 -56
index a1b01ab42052..afa1bf2b3c5a 100644
@@ -699,34 +699,6 @@ struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode)
 }
 EXPORT_SYMBOL_GPL(fwnode_get_next_parent);
 
-/**
- * fwnode_get_next_parent_dev - Find device of closest ancestor fwnode
- * @fwnode: firmware node
- *
- * Given a firmware node (@fwnode), this function finds its closest ancestor
- * firmware node that has a corresponding struct device and returns that struct
- * device.
- *
- * The caller is responsible for calling put_device() on the returned device
- * pointer.
- *
- * Return: a pointer to the device of the @fwnode's closest ancestor.
- */
-struct device *fwnode_get_next_parent_dev(const struct fwnode_handle *fwnode)
-{
-       struct fwnode_handle *parent;
-       struct device *dev;
-
-       fwnode_for_each_parent_node(fwnode, parent) {
-               dev = get_dev_from_fwnode(parent);
-               if (dev) {
-                       fwnode_handle_put(parent);
-                       return dev;
-               }
-       }
-       return NULL;
-}
-
 /**
  * fwnode_count_parents - Return the number of parents a node has
  * @fwnode: The node the parents of which are to be counted
@@ -773,34 +745,6 @@ struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwnode,
 }
 EXPORT_SYMBOL_GPL(fwnode_get_nth_parent);
 
-/**
- * fwnode_is_ancestor_of - Test if @ancestor is ancestor of @child
- * @ancestor: Firmware which is tested for being an ancestor
- * @child: Firmware which is tested for being the child
- *
- * A node is considered an ancestor of itself too.
- *
- * Return: true if @ancestor is an ancestor of @child. Otherwise, returns false.
- */
-bool fwnode_is_ancestor_of(const struct fwnode_handle *ancestor, const struct fwnode_handle *child)
-{
-       struct fwnode_handle *parent;
-
-       if (IS_ERR_OR_NULL(ancestor))
-               return false;
-
-       if (child == ancestor)
-               return true;
-
-       fwnode_for_each_parent_node(child, parent) {
-               if (parent == ancestor) {
-                       fwnode_handle_put(parent);
-                       return true;
-               }
-       }
-       return false;
-}
-
 /**
  * fwnode_get_next_child_node - Return the next child node handle for a node
  * @fwnode: Firmware node to find the next child node for.
include/linux/fwnode.h +0 -1
index 0428942093a7..4228c45d5ccc 100644
@@ -193,7 +193,6 @@ struct fwnode_operations {
                if (fwnode_has_op(fwnode, op))                          \
                        (fwnode)->ops->op(fwnode, ## __VA_ARGS__);      \
        } while (false)
-#define get_dev_from_fwnode(fwnode)    get_device((fwnode)->dev)
 
 static inline void fwnode_init(struct fwnode_handle *fwnode,
                               const struct fwnode_operations *ops)
include/linux/property.h +0 -0
index 07fbebc73243..1f0135e24d00 100644

include/linux/property.h struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode); · line 157

Quoted 8 lines
include/linux/property.h +0 -2
@@ -150,11 +150,9 @@ struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode);
        for (parent = fwnode_get_parent(fwnode); parent;        \
             parent = fwnode_get_next_parent(parent))
 
-struct device *fwnode_get_next_parent_dev(const struct fwnode_handle *fwnode);
 unsigned int fwnode_count_parents(const struct fwnode_handle *fwn);
 struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn,
                                            unsigned int depth);
-bool fwnode_is_ancestor_of(const struct fwnode_handle *ancestor, const struct fwnode_handle *child);

The rest of the functions here are related to parents and children of a fwnode. So, why is this function considered to be in the wrong place?

-Saravana

Quoted 3 lines
include/linux/property.h +0 -0
 struct fwnode_handle *fwnode_get_next_child_node(
        const struct fwnode_handle *fwnode, struct fwnode_handle *child);
 struct fwnode_handle *fwnode_get_next_available_child_node(
reviewer Reviewed-by on v1 1/1
#6 lore raw
In reply to Andy Shevchenko
Quoted 10 lines · Andy Shevchenko

A few APIs that belong specifically to the fw_devlink APIs
- are exposed to others without need
- prevents device property code to be cleaned up in the future

Resolve this mess by moving fw_devlink code to where it belongs and hide from others.

Fixes b5d3e2fbcb10 ("device property: Add fwnode_is_ancestor_of() and fwnode_get_next_parent_dev()")
Fixes 372a67c0c5ef ("driver core: Add fwnode_to_dev() to look up device from fwnode")
Signature · 1 line
Sakari Ailus
author reviewer
#2 lore raw
In reply to Saravana Kannan
Quoted 9 lines · Saravana Kannan
Quoted 7 lines · Andy Shevchenko

A few APIs that belong specifically to the fw_devlink APIs
- are exposed to others without need
- prevents device property code to be cleaned up in the future

Resolve this mess by moving fw_devlink code to where it belongs and hide from others.

...

Quoted 3 lines

The rest of the functions here are related to parents and children of a fwnode. So, why is this function considered to be in the wrong place?

When devlink was added it made a few fields in struct fwnode_handle. These fields have no common grounds with device properties. In particular struct device pointer is solely for devlinks and shouldn't be used with them. Hence this patch. TL;DR: they semantically do _not_ belong to the device property APIs.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author reviewer
#3 lore raw
Quoted 10 lines · Andy Shevchenko
Quoted 9 lines · Saravana Kannan
Quoted 7 lines · Andy Shevchenko

A few APIs that belong specifically to the fw_devlink APIs
- are exposed to others without need
- prevents device property code to be cleaned up in the future

Resolve this mess by moving fw_devlink code to where it belongs and hide from others.

...

Quoted 9 lines
Quoted 3 lines

The rest of the functions here are related to parents and children of a fwnode. So, why is this function considered to be in the wrong place?

When devlink was added it made a few fields in struct fwnode_handle. These fields have no common grounds with device properties. In particular struct device pointer is solely for devlinks and shouldn't be used with them. Hence this patch. TL;DR: they semantically do _not_ belong to the device property APIs.

On top of that for the 4+ years no new users appeared, so exporting them was a clear mistake. Hence Fixes tags.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author reviewer
#7 lore raw
In reply to Sakari Ailus
Quoted 9 lines · Sakari Ailus
Quoted 6 lines · Andy Shevchenko

A few APIs that belong specifically to the fw_devlink APIs
- are exposed to others without need
- prevents device property code to be cleaned up in the future

Resolve this mess by moving fw_devlink code to where it belongs and hide from others.

Thank you!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
In reply to Andy Shevchenko
Quoted 19 lines · Andy Shevchenko
Quoted 10 lines · Andy Shevchenko
Quoted 9 lines · Saravana Kannan
Quoted 7 lines · Andy Shevchenko

A few APIs that belong specifically to the fw_devlink APIs
- are exposed to others without need
- prevents device property code to be cleaned up in the future

Resolve this mess by moving fw_devlink code to where it belongs and hide from others.

...

Quoted 4 lines
Quoted 3 lines

The rest of the functions here are related to parents and children of a fwnode. So, why is this function considered to be in the wrong place?

Quoted 5 lines
Quoted 5 lines

When devlink was added it made a few fields in struct fwnode_handle. These fields have no common grounds with device properties. In particular struct device pointer is solely for devlinks and shouldn't be used with them. Hence this patch. TL;DR: they semantically do _not_ belong to the device property APIs.

But fwnode_is_ancestor_of() uses none of those new fields and seems like a very reasonable API to provide. I understand if you want to make the "device link only" argument for fwnode_get_next_parent_dev().

Quoted 2 lines

On top of that for the 4+ years no new users appeared, so exporting them was a clear mistake. Hence Fixes tags.

We have plenty of APIs in .h files (not the same as export to modules) -- that have only 1 user. And even some with no users. You don't move a string function out of lib/string.c just because there's only one user of that function. We put functions in C files that make sense.

I think Fixes is a bit of an overkill. It's not a bug. Fixes get propagated to LTS. This is certainly not LTS worthy. I'm not going to NACK or push back on this patch for these reasons, but just letting you know that you come off as unreasonably grumpy when you do these things even for fwnode_is_ancestor_of() :)

-Saravana

author reviewer
#5 lore raw
Quoted 6 lines · Saravana Kannan
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Saravana Kannan

On Tue, Feb 20, 2024 at 8:10 AM Andy Shevchenko
<[email protected]> wrote:

...

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines

The rest of the functions here are related to parents and children of a fwnode. So, why is this function considered to be in the wrong place?

When devlink was added it made a few fields in struct fwnode_handle. These fields have no common grounds with device properties. In particular struct device pointer is solely for devlinks and shouldn't be used with them. Hence this patch. TL;DR: they semantically do _not_ belong to the device property APIs.

Quoted 3 lines

But fwnode_is_ancestor_of() uses none of those new fields and seems like a very reasonable API to provide. I understand if you want to make the "device link only" argument for fwnode_get_next_parent_dev().

Nobody is using that except devlink. That API can be and should be hidden (we do not add APIs without users). On itself it's useless.

Quoted 7 lines
Quoted 2 lines

On top of that for the 4+ years no new users appeared, so exporting them was a clear mistake. Hence Fixes tags.

We have plenty of APIs in .h files (not the same as export to modules) -- that have only 1 user. And even some with no users. You don't move a string function out of lib/string.c just because there's only one user of that function. We put functions in C files that make sense.

You understand that this is a weak argument, right? There are generic functions, there are more specific ones. Here we are talking about niche APIs without (other / new) users for all this time!

Now about generic one (as string.h is a bad example here), yes we do move functions from the headers out if we have only one static user. We even target killing some generic functions (strlcpy() is one and strlcat() is rumored to follow same destiny.

Quoted 5 lines

I think Fixes is a bit of an overkill. It's not a bug. Fixes get propagated to LTS. This is certainly not LTS worthy. I'm not going to NACK or push back on this patch for these reasons, but just letting you know that you come off as unreasonably grumpy when you do these things even for fwnode_is_ancestor_of() :)

I can drop Fixes it won't affect much as as I said there is no (other) user for it anyway for all these years.

TL;DR: I will drop Fixes for the next version and that's it. I'm not okay of leaving functions in the header and be exported just for the sake of exporting.

Signature · 2 lines
With Best Regards,
Andy Shevchenko