Skip to contentSkip to conversation

device property: Add fwnode_name() helper

PATCH Superseded Heikki Krogerus 3 participants 21 messages Nov 5, 2018 – Nov 7, 2018

Subsystems (4)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Heikki Krogerus

author reviewer
#0 lore raw

cover device property: Add fwnode_name() helper

Hi,

I prepared fwnode_name() for something I'm working on, but then I realized that it makes it possible to also implement a generic fwnode_get_named_child_node(). So in practice I'm proposing that we replace get_named_child_node fwnode op with that new "name" fwnode op in this series.

thanks,

Heikki Krogerus (4):
device property: Introduce fwnode_name()
ACPI: property: Introduce acpi_fwnode_name() of/property: Introduce of_fwnode_name() device property: Drop get_named_child_node callback

 drivers/acpi/property.c  | 26 +++++++-------------------
 drivers/base/property.c  | 28 +++++++++++++++++++++++++++-
 drivers/of/property.c    | 21 ++++++---------------
 include/linux/fwnode.h   |  4 +---
 include/linux/property.h |  2 ++
 5 files changed, 43 insertions(+), 38 deletions(-)
Signature · 1 line
2.19.1
author reviewer
#1 lore raw

PATCH 1/4 device property: Introduce fwnode_name()

This helper returns the name of the node. The name is primarily expected to be returned from a new fwnode operation meant for this purpose, but when no name is returned, the helper will also attempt to read a device property "name".

---
 drivers/base/property.c  | 18 ++++++++++++++++++
 include/linux/fwnode.h   |  1 +
 include/linux/property.h |  2 ++
 3 files changed, 21 insertions(+)
drivers/base/property.c +18 -0
index 240ab5230ff6..1e4eb7ab2b84 100644
@@ -1156,6 +1156,24 @@ void fwnode_handle_put(struct fwnode_handle *fwnode)
 }
 EXPORT_SYMBOL_GPL(fwnode_handle_put);
 
+/**
+ * fwnode_name - Get the name of a device node
+ * @fwnode: Pointer to the device node.
+ *
+ * Returns the node name of @fwnode. If @fwnode does not have a "unit name",
+ * this code will also attempt to read a string property named "name".
+ */
+const char *fwnode_name(const struct fwnode_handle *fwnode)
+{
+	const char *name = fwnode_call_ptr_op(fwnode, name);
+
+	if (!name)
+		fwnode_call_int_op(fwnode, property_read_string_array,
+				   "name", &name, 1);
+	return name;
+}
+EXPORT_SYMBOL_GPL(fwnode_name);
+
 /**
  * fwnode_device_is_available - check if a device is available for use
  * @fwnode: Pointer to the fwnode of the device.
include/linux/fwnode.h +1 -0
index faebf0ca0686..2e445fed4df4 100644
@@ -72,6 +72,7 @@ struct fwnode_reference_args {
 struct fwnode_operations {
 	struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
 	void (*put)(struct fwnode_handle *fwnode);
+	const char *(*name)(const struct fwnode_handle *fwnode);
 	bool (*device_is_available)(const struct fwnode_handle *fwnode);
 	const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
 					     const struct device *dev);
include/linux/property.h +2 -0
index ac8a1ebc4c1b..44781d37dd96 100644
@@ -109,6 +109,8 @@ struct fwnode_handle *device_get_named_child_node(struct device *dev,
 struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode);
 void fwnode_handle_put(struct fwnode_handle *fwnode);
 
+const char *fwnode_name(const struct fwnode_handle *fwnode);
+
 int fwnode_irq_get(struct fwnode_handle *fwnode, unsigned int index);
 
 unsigned int device_get_child_node_count(struct device *dev);
Signature · 1 line
2.19.1
#2 lore raw

Re: [PATCH 1/4] device property: Introduce fwnode_name()

Quoted 25 lines · Heikki Krogerus

This helper returns the name of the node. The name is primarily expected to be returned from a new fwnode operation meant for this purpose, but when no name is returned, the helper will also attempt to read a device property "name".

---
 drivers/base/property.c  | 18 ++++++++++++++++++
 include/linux/fwnode.h   |  1 +
 include/linux/property.h |  2 ++
 3 files changed, 21 insertions(+)
drivers/base/property.c +4 -0
index 240ab5230ff6..1e4eb7ab2b84 100644
@@ -1156,6 +1156,24 @@ void fwnode_handle_put(struct fwnode_handle *fwnode)
 }
 EXPORT_SYMBOL_GPL(fwnode_handle_put);
 
+/**
+ * fwnode_name - Get the name of a device node
+ * @fwnode: Pointer to the device node.
+ *

drivers/base/property.c void fwnode_handle_put(struct fwnode_handle *fwnode) · line 1172

Quoted 10 lines
drivers/base/property.c +10 -0
+ * Returns the node name of @fwnode. If @fwnode does not have a "unit name",
+ * this code will also attempt to read a string property named "name".
+ */
+const char *fwnode_name(const struct fwnode_handle *fwnode)
+{
+	const char *name = fwnode_call_ptr_op(fwnode, name);
+
+	if (!name)
+		fwnode_call_int_op(fwnode, property_read_string_array,
+				   "name", &name, 1);

Is it going to be extended in the future?

Otherwise I would rather go with (few more LOCs, yes)

	const char *name;

	name = fwnode_call_ptr_op(fwnode, name);
	if (name)
		return name;

	fwnode_call_int_op(fwnode, property_read_string_array, "name", &name, 1);
	return name;
Quoted 35 lines
drivers/base/property.c +4 -0
+	return name;
+}
+EXPORT_SYMBOL_GPL(fwnode_name);
+
 /**
  * fwnode_device_is_available - check if a device is available for use
  * @fwnode: Pointer to the fwnode of the device.
include/linux/fwnode.h +1 -0
index faebf0ca0686..2e445fed4df4 100644
@@ -72,6 +72,7 @@ struct fwnode_reference_args {
 struct fwnode_operations {
 	struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
 	void (*put)(struct fwnode_handle *fwnode);
+	const char *(*name)(const struct fwnode_handle *fwnode);
 	bool (*device_is_available)(const struct fwnode_handle *fwnode);
 	const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
 					     const struct device *dev);
include/linux/property.h +2 -0
index ac8a1ebc4c1b..44781d37dd96 100644
@@ -109,6 +109,8 @@ struct fwnode_handle *device_get_named_child_node(struct device *dev,
 struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode);
 void fwnode_handle_put(struct fwnode_handle *fwnode);
 
+const char *fwnode_name(const struct fwnode_handle *fwnode);
+
 int fwnode_irq_get(struct fwnode_handle *fwnode, unsigned int index);
 
 unsigned int device_get_child_node_count(struct device *dev);
Signature · 1 line
2.19.1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author reviewer
#3 lore raw

Re: [PATCH 1/4] device property: Introduce fwnode_name()

Hi,

Quoted 12 lines

drivers/base/property.c void fwnode_handle_put(struct fwnode_handle *fwnode) · line 1172

Quoted 7 lines
drivers/base/property.c +7 -0
+const char *fwnode_name(const struct fwnode_handle *fwnode)
+{
+	const char *name = fwnode_call_ptr_op(fwnode, name);
+
+	if (!name)
+		fwnode_call_int_op(fwnode, property_read_string_array,
+				   "name", &name, 1);

Is it going to be extended in the future?

Otherwise I would rather go with (few more LOCs, yes)

Quoted 8 lines
	const char *name;

	name = fwnode_call_ptr_op(fwnode, name);
	if (name)
		return name;

	fwnode_call_int_op(fwnode, property_read_string_array, "name", &name, 1);
	return name;

That does look better. I'll fix it.

thanks,

Signature · 1 line
heikki
author reviewer
#4 lore raw

PATCH 2/4 ACPI: property: Introduce acpi_fwnode_name()

In reply to Heikki Krogerus

ACPI data nodes have a name, so let's return that when fwnode_name() is called.

---
 drivers/acpi/property.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/acpi/property.c +6 -0
index 8c7c4583b52d..75854e07ed64 100644
@@ -1219,6 +1219,11 @@ acpi_graph_get_remote_endpoint(const struct fwnode_handle *__fwnode)
 	return acpi_graph_get_child_prop_value(fwnode, "endpoint", endpoint_nr);
 }
 
+static const char *acpi_fwnode_name(const struct fwnode_handle *node)
+{
+	return is_acpi_data_node(node) ? to_acpi_data_node(node)->name : NULL;
+}
+
 static bool acpi_fwnode_device_is_available(const struct fwnode_handle *fwnode)
 {
 	if (!is_acpi_device_node(fwnode))
@@ -1310,6 +1315,7 @@ acpi_fwnode_device_get_match_data(const struct fwnode_handle *fwnode,
 
 #define DECLARE_ACPI_FWNODE_OPS(ops) \
 	const struct fwnode_operations ops = {				\
+		.name = acpi_fwnode_name,				\
 		.device_is_available = acpi_fwnode_device_is_available, \
 		.device_get_match_data = acpi_fwnode_device_get_match_data, \
 		.property_present = acpi_fwnode_property_present,	\
Signature · 1 line
2.19.1
author reviewer
#5 lore raw

PATCH 3/4 of/property: Introduce of_fwnode_name()

In reply to Heikki Krogerus

Instead of always being forced to read the "name" property in fwnode_name() with of_nodes, implementing the fwnode operation meant for getting the node name.

---
 drivers/of/property.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/of/property.c +6 -0
index f46828e3b082..ac7b0b6c2d4d 100644
@@ -823,6 +823,11 @@ static void of_fwnode_put(struct fwnode_handle *fwnode)
 	of_node_put(to_of_node(fwnode));
 }
 
+static const char *of_fwnode_name(const struct fwnode_handle *fwnode)
+{
+	return to_of_node(fwnode)->name;
+}
+
 static bool of_fwnode_device_is_available(const struct fwnode_handle *fwnode)
 {
 	return of_device_is_available(to_of_node(fwnode));
@@ -987,6 +992,7 @@ of_fwnode_device_get_match_data(const struct fwnode_handle *fwnode,
 const struct fwnode_operations of_fwnode_ops = {
 	.get = of_fwnode_get,
 	.put = of_fwnode_put,
+	.name = of_fwnode_name,
 	.device_is_available = of_fwnode_device_is_available,
 	.device_get_match_data = of_fwnode_device_get_match_data,
 	.property_present = of_fwnode_property_present,
Signature · 1 line
2.19.1
maintainer
#6 lore raw

Re: [PATCH 3/4] of/property: Introduce of_fwnode_name()

Quoted 9 lines · Heikki Krogerus

Instead of always being forced to read the "name" property in fwnode_name() with of_nodes, implementing the fwnode operation meant for getting the node name.

---
 drivers/of/property.c | 6 ++++++

Please Cc the DT list for DT changes.

drivers/of/property.c static void of_fwnode_put(struct fwnode_handle *fwnode) · line 828

Quoted 13 lines
 1 file changed, 6 insertions(+)
drivers/of/property.c +3 -0
index f46828e3b082..ac7b0b6c2d4d 100644
@@ -823,6 +823,11 @@ static void of_fwnode_put(struct fwnode_handle *fwnode)
        of_node_put(to_of_node(fwnode));
 }
 
+static const char *of_fwnode_name(const struct fwnode_handle *fwnode)
+{
+       return to_of_node(fwnode)->name;

I'm trying to get rid of the DT name ptr, so please don't add one. You can use of_node_full_name() here instead if "<name>@<unit-address>" instead of <name> is fine. Otherwise, you've got to allocate your own storage and use "%pOFn" printf specifier.

Rob

author reviewer
#7 lore raw

Re: [PATCH 3/4] of/property: Introduce of_fwnode_name()

Quoted 7 lines · Rob Herring
Quoted 5 lines · Heikki Krogerus

Instead of always being forced to read the "name" property in fwnode_name() with of_nodes, implementing the fwnode operation meant for getting the node name.

Quoted 6 lines
Quoted 4 lines
---
 drivers/of/property.c | 6 ++++++

Please Cc the DT list for DT changes.

OK.

Quoted 10 lines
Quoted 10 lines
 1 file changed, 6 insertions(+)
drivers/of/property.c +0 -0
index f46828e3b082..ac7b0b6c2d4d 100644
@@ -823,6 +823,11 @@ static void of_fwnode_put(struct fwnode_handle *fwnode)
        of_node_put(to_of_node(fwnode));
 }
 
Quoted 8 lines

drivers/of/property.c static void of_fwnode_put(struct fwnode_handle *fwnode) · line 828

Quoted 3 lines
drivers/of/property.c +3 -0
+static const char *of_fwnode_name(const struct fwnode_handle *fwnode)
+{
+       return to_of_node(fwnode)->name;

I'm trying to get rid of the DT name ptr, so please don't add one. You can use of_node_full_name() here instead if "<name>@<unit-address>" instead of <name> is fine. Otherwise, you've got to allocate your own storage and use "%pOFn" printf specifier.

OK, I'll use of_node_full_name().

thanks,

Signature · 1 line
heikki
#8 lore raw

Re: [PATCH 3/4] of/property: Introduce of_fwnode_name()

In reply to Rob Herring
Quoted 11 lines · Rob Herring

drivers/of/property.c static void of_fwnode_put(struct fwnode_handle *fwnode) · line 828

Quoted 3 lines · Heikki Krogerus
drivers/of/property.c +3 -0
+static const char *of_fwnode_name(const struct fwnode_handle *fwnode)
+{
+       return to_of_node(fwnode)->name;

I'm trying to get rid of the DT name ptr, so please don't add one. You can use of_node_full_name() here instead if "<name>@<unit-address>" instead of <name> is fine. Otherwise, you've got to allocate your own storage and use "%pOFn" printf specifier.

If we do this here, we will change a behaviour of the entire set of of_fwnode_get_named_child_node() users.

I think this is out of scope of the series.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author reviewer
#9 lore raw

Re: [PATCH 3/4] of/property: Introduce of_fwnode_name()

Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Rob Herring

drivers/of/property.c static void of_fwnode_put(struct fwnode_handle *fwnode) · line 828

Quoted 3 lines · Heikki Krogerus
drivers/of/property.c +3 -0
+static const char *of_fwnode_name(const struct fwnode_handle *fwnode)
+{
+       return to_of_node(fwnode)->name;

I'm trying to get rid of the DT name ptr, so please don't add one. You can use of_node_full_name() here instead if "<name>@<unit-address>" instead of <name> is fine. Otherwise, you've got to allocate your own storage and use "%pOFn" printf specifier.

Quoted 4 lines

If we do this here, we will change a behaviour of the entire set of of_fwnode_get_named_child_node() users.

I think this is out of scope of the series.

You have a point. We must use the same member that was used in of_fwnode_get_named_child_node().

The goal of this series if most likely not clear from this patch alone, so I'll send a second version and make sure to CC the DT list and Rob.

But in any case, I'll keep this part as it is.

thanks,

Signature · 1 line
heikki
maintainer
#10 lore raw

Re: [PATCH 3/4] of/property: Introduce of_fwnode_name()

Quoted 15 lines · Heikki Krogerus
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Rob Herring

drivers/of/property.c static void of_fwnode_put(struct fwnode_handle *fwnode) · line 828

Quoted 3 lines · Heikki Krogerus
drivers/of/property.c +3 -0
+static const char *of_fwnode_name(const struct fwnode_handle *fwnode)
+{
+       return to_of_node(fwnode)->name;

I'm trying to get rid of the DT name ptr, so please don't add one. You can use of_node_full_name() here instead if "<name>@<unit-address>" instead of <name> is fine. Otherwise, you've got to allocate your own storage and use "%pOFn" printf specifier.

Quoted 4 lines
Quoted 4 lines

If we do this here, we will change a behaviour of the entire set of of_fwnode_get_named_child_node() users.

I think this is out of scope of the series.

No, because you are adding a firmware op for something that's going away.

Quoted 6 lines

You have a point. We must use the same member that was used in of_fwnode_get_named_child_node().

The goal of this series if most likely not clear from this patch alone, so I'll send a second version and make sure to CC the DT list and Rob.

Looking at patch 4, if matching the name is what you want to do, then use the DT name matching functions. They were added in 4.19.

Rob

#11 lore raw

Re: [PATCH 3/4] of/property: Introduce of_fwnode_name()

Quoted 17 lines · Rob Herring
Quoted 15 lines · Heikki Krogerus
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Rob Herring

drivers/of/property.c static void of_fwnode_put(struct fwnode_handle *fwnode) · line 828

Quoted 3 lines · Heikki Krogerus
drivers/of/property.c +3 -0
+static const char *of_fwnode_name(const struct fwnode_handle *fwnode)
+{
+       return to_of_node(fwnode)->name;

I'm trying to get rid of the DT name ptr, so please don't add one. You can use of_node_full_name() here instead if "<name>@<unit-address>" instead of <name> is fine. Otherwise, you've got to allocate your own storage and use "%pOFn" printf specifier.

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

If we do this here, we will change a behaviour of the entire set of of_fwnode_get_named_child_node() users.

I think this is out of scope of the series.

No, because you are adding a firmware op for something that's going away.

W/o your below explanation it wasn't obvious.

Quoted 10 lines
Quoted 7 lines

You have a point. We must use the same member that was used in of_fwnode_get_named_child_node().

The goal of this series if most likely not clear from this patch alone, so I'll send a second version and make sure to CC the DT list and Rob.

Looking at patch 4, if matching the name is what you want to do, then use the DT name matching functions. They were added in 4.19.

Do you mean of_node_name_eq()?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#12 lore raw

Re: [PATCH 3/4] of/property: Introduce of_fwnode_name()

Quoted 32 lines · Andy Shevchenko
Quoted 17 lines · Rob Herring
Quoted 15 lines · Heikki Krogerus
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Rob Herring

drivers/of/property.c static void of_fwnode_put(struct fwnode_handle *fwnode) · line 828

Quoted 3 lines · Heikki Krogerus
drivers/of/property.c +3 -0
+static const char *of_fwnode_name(const struct fwnode_handle *fwnode)
+{
+       return to_of_node(fwnode)->name;

I'm trying to get rid of the DT name ptr, so please don't add one. You can use of_node_full_name() here instead if "<name>@<unit-address>" instead of <name> is fine. Otherwise, you've got to allocate your own storage and use "%pOFn" printf specifier.

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

If we do this here, we will change a behaviour of the entire set of of_fwnode_get_named_child_node() users.

I think this is out of scope of the series.

No, because you are adding a firmware op for something that's going away.

W/o your below explanation it wasn't obvious.

Quoted 4 lines
Quoted 4 lines

You have a point. We must use the same member that was used in of_fwnode_get_named_child_node().

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

The goal of this series if most likely not clear from this patch alone, so I'll send a second version and make sure to CC the DT list and Rob.

Looking at patch 4, if matching the name is what you want to do, then use the DT name matching functions. They were added in 4.19.

Do you mean of_node_name_eq()?

Yes or maybe move further up and just retrieve child nodes by name. There's a recent function Johan added for that too. of_find_child_node_by_name IIRC.

Rob

author reviewer
#13 lore raw

Re: [PATCH 3/4] of/property: Introduce of_fwnode_name()

In reply to Rob Herring
Quoted 27 lines · Rob Herring
Quoted 15 lines · Heikki Krogerus
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Rob Herring

drivers/of/property.c static void of_fwnode_put(struct fwnode_handle *fwnode) · line 828

Quoted 3 lines · Heikki Krogerus
drivers/of/property.c +3 -0
+static const char *of_fwnode_name(const struct fwnode_handle *fwnode)
+{
+       return to_of_node(fwnode)->name;

I'm trying to get rid of the DT name ptr, so please don't add one. You can use of_node_full_name() here instead if "<name>@<unit-address>" instead of <name> is fine. Otherwise, you've got to allocate your own storage and use "%pOFn" printf specifier.

Quoted 4 lines
Quoted 4 lines

If we do this here, we will change a behaviour of the entire set of of_fwnode_get_named_child_node() users.

I think this is out of scope of the series.

No, because you are adding a firmware op for something that's going away.

Quoted 3 lines

You have a point. We must use the same member that was used in of_fwnode_get_named_child_node().

Quoted 6 lines
Quoted 3 lines

The goal of this series if most likely not clear from this patch alone, so I'll send a second version and make sure to CC the DT list and Rob.

Looking at patch 4, if matching the name is what you want to do, then use the DT name matching functions. They were added in 4.19.

That is something that the of_fwnode_get_named_child_node() needs to use (would have needed).

Regardless of what we do with that callback, fwnode_name() needs to return the name in from that for example of_node_name_eq() takes as the second parameter. So "node-name@unit-address" is not OK. Sorry for not realizeing that before.

So I guess we need to either get the "node-name" from that full_name member in of_fwnode_name() (Andy, are you OK with that?), or is there already a helper that does it for us?

Thanks,

Signature · 1 line
heikki
#14 lore raw

Re: [PATCH 3/4] of/property: Introduce of_fwnode_name()

Quoted 8 lines · Heikki Krogerus
Quoted 2 lines · Rob Herring

Looking at patch 4, if matching the name is what you want to do, then use the DT name matching functions. They were added in 4.19.

That is something that the of_fwnode_get_named_child_node() needs to use (would have needed).

Quoted 8 lines

Regardless of what we do with that callback, fwnode_name() needs to return the name in from that for example of_node_name_eq() takes as the second parameter. So "node-name@unit-address" is not OK. Sorry for not realizeing that before.

So I guess we need to either get the "node-name" from that full_name member in of_fwnode_name() (Andy, are you OK with that?), or is there already a helper that does it for us?

Looking into existing API I think we need something like

of_node_name_extract()

of_node_name_eq()

{
	name = of_node_name_extract();
	return strlen()...strncmp()...;
}

The question is who is going to allocate and free memory for the name out of it.

OTOH, of_fwnode_get_named_child_node() might need to copy that code which brings the consistency issue (several places to maintain the same set of rules, i.e. how we extract name out of full_name).

So, removal of name field shouldn't be done until we resolve the issue with of_fwnode_get_named_child_node().

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author reviewer
#15 lore raw

Re: [PATCH 3/4] of/property: Introduce of_fwnode_name()

Quoted 22 lines · Andy Shevchenko
Quoted 8 lines · Heikki Krogerus
Quoted 2 lines · Rob Herring

Looking at patch 4, if matching the name is what you want to do, then use the DT name matching functions. They were added in 4.19.

That is something that the of_fwnode_get_named_child_node() needs to use (would have needed).

Quoted 8 lines

Regardless of what we do with that callback, fwnode_name() needs to return the name in from that for example of_node_name_eq() takes as the second parameter. So "node-name@unit-address" is not OK. Sorry for not realizeing that before.

So I guess we need to either get the "node-name" from that full_name member in of_fwnode_name() (Andy, are you OK with that?), or is there already a helper that does it for us?

Looking into existing API I think we need something like

of_node_name_extract()

Quoted 7 lines

of_node_name_eq()

{
	name = of_node_name_extract();
	return strlen()...strncmp()...;
}

The question is who is going to allocate and free memory for the name out of it.

Maybe it would be best to just read the "name" device property in fwnode_name() and not have of_fwnode_name at all.

Quoted 6 lines

OTOH, of_fwnode_get_named_child_node() might need to copy that code which brings the consistency issue (several places to maintain the same set of rules, i.e. how we extract name out of full_name).

So, removal of name field shouldn't be done until we resolve the issue with of_fwnode_get_named_child_node().

thanks,

Signature · 1 line
heikki
#16 lore raw

Re: [PATCH 3/4] of/property: Introduce of_fwnode_name()

Quoted 2 lines · Heikki Krogerus

Maybe it would be best to just read the "name" device property in fwnode_name() and not have of_fwnode_name at all.

If it's a mandatory property or somehow its presence is guaranteed, it would work.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#17 lore raw

Re: [PATCH 3/4] of/property: Introduce of_fwnode_name()

Quoted 7 lines · Andy Shevchenko
Quoted 2 lines · Heikki Krogerus

Maybe it would be best to just read the "name" device property in fwnode_name() and not have of_fwnode_name at all.

If it's a mandatory property or somehow its presence is guaranteed, it would work.

It is currently, but after removing the name ptr, my current plan is to remove the 'name' property too for FDT. On real OpenFirmware, it is a real property so it will remain for sure in some cases.

Rob

author reviewer
#18 lore raw

Re: [PATCH 3/4] of/property: Introduce of_fwnode_name()

Quoted 5 lines · Rob Herring
Quoted 3 lines · Andy Shevchenko

On Tue, Nov 06, 2018 at 05:05:03PM +0200, Heikki Krogerus wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Maybe it would be best to just read the "name" device property in fwnode_name() and not have of_fwnode_name at all.

If it's a mandatory property or somehow its presence is guaranteed, it would work.

It is currently, but after removing the name ptr, my current plan is to remove the 'name' property too for FDT. On real OpenFirmware, it is a real property so it will remain for sure in some cases.

OK. I think we'll use the full_name after all.

thanks,

Signature · 1 line
heikki
author reviewer
#19 lore raw

PATCH 4/4 device property: Drop get_named_child_node callback

In reply to Heikki Krogerus

By using fwnode_name() in fwnode_get_named_child_node(), get_named_child_node implementations become boilerplate. Removing all of them.

---
 drivers/acpi/property.c | 20 +-------------------
 drivers/base/property.c | 10 +++++++++-
 drivers/of/property.c   | 15 ---------------
 include/linux/fwnode.h  |  3 ---
 4 files changed, 10 insertions(+), 38 deletions(-)
drivers/acpi/property.c +1 -19
index 75854e07ed64..6c38cd73e4c0 100644
@@ -587,23 +587,6 @@ static int acpi_data_get_property_array(const struct acpi_device_data *data,
 	return 0;
 }
 
-static struct fwnode_handle *
-acpi_fwnode_get_named_child_node(const struct fwnode_handle *fwnode,
-				 const char *childname)
-{
-	struct fwnode_handle *child;
-
-	/*
-	 * Find first matching named child node of this fwnode.
-	 * For ACPI this will be a data only sub-node.
-	 */
-	fwnode_for_each_child_node(fwnode, child)
-		if (acpi_data_node_match(child, childname))
-			return child;
-
-	return NULL;
-}
-
 /**
  * __acpi_node_get_property_reference - returns handle to the referenced object
  * @fwnode: Firmware node to get the property from
@@ -712,7 +695,7 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,
 			for (ref_fwnode = acpi_fwnode_handle(device);
 			     element < end && element->type == ACPI_TYPE_STRING;
 			     element++) {
-				ref_fwnode = acpi_fwnode_get_named_child_node(
+				ref_fwnode = fwnode_get_named_child_node(
 					ref_fwnode, element->string.pointer);
 				if (!ref_fwnode)
 					return -EINVAL;
@@ -1325,7 +1308,6 @@ acpi_fwnode_device_get_match_data(const struct fwnode_handle *fwnode,
 			acpi_fwnode_property_read_string_array,		\
 		.get_parent = acpi_node_get_parent,			\
 		.get_next_child_node = acpi_get_next_subnode,		\
-		.get_named_child_node = acpi_fwnode_get_named_child_node, \
 		.get_reference_args = acpi_fwnode_get_reference_args,	\
 		.graph_get_next_endpoint =				\
 			acpi_graph_get_next_endpoint,			\
drivers/base/property.c +9 -1
index 1e4eb7ab2b84..06ba83d73517 100644
@@ -1111,7 +1111,15 @@ struct fwnode_handle *
 fwnode_get_named_child_node(const struct fwnode_handle *fwnode,
 			    const char *childname)
 {
-	return fwnode_call_ptr_op(fwnode, get_named_child_node, childname);
+	struct fwnode_handle *child;
+	const char *name;
+
+	fwnode_for_each_child_node(fwnode, child) {
+		name = fwnode_name(child);
+		if (name && !strcasecmp(name, childname))
+			return child;
+	}
+	return NULL;
 }
 EXPORT_SYMBOL_GPL(fwnode_get_named_child_node);
 
drivers/of/property.c +0 -15
index ac7b0b6c2d4d..60b590fc5b99 100644
@@ -890,20 +890,6 @@ of_fwnode_get_next_child_node(const struct fwnode_handle *fwnode,
 							    to_of_node(child)));
 }
 
-static struct fwnode_handle *
-of_fwnode_get_named_child_node(const struct fwnode_handle *fwnode,
-			       const char *childname)
-{
-	const struct device_node *node = to_of_node(fwnode);
-	struct device_node *child;
-
-	for_each_available_child_of_node(node, child)
-		if (!of_node_cmp(child->name, childname))
-			return of_fwnode_handle(child);
-
-	return NULL;
-}
-
 static int
 of_fwnode_get_reference_args(const struct fwnode_handle *fwnode,
 			     const char *prop, const char *nargs_prop,
@@ -1000,7 +986,6 @@ const struct fwnode_operations of_fwnode_ops = {
 	.property_read_string_array = of_fwnode_property_read_string_array,
 	.get_parent = of_fwnode_get_parent,
 	.get_next_child_node = of_fwnode_get_next_child_node,
-	.get_named_child_node = of_fwnode_get_named_child_node,
 	.get_reference_args = of_fwnode_get_reference_args,
 	.graph_get_next_endpoint = of_fwnode_graph_get_next_endpoint,
 	.graph_get_remote_endpoint = of_fwnode_graph_get_remote_endpoint,
include/linux/fwnode.h +0 -3
index 2e445fed4df4..83f8ec3754d0 100644
@@ -90,9 +90,6 @@ struct fwnode_operations {
 	struct fwnode_handle *
 	(*get_next_child_node)(const struct fwnode_handle *fwnode,
 			       struct fwnode_handle *child);
-	struct fwnode_handle *
-	(*get_named_child_node)(const struct fwnode_handle *fwnode,
-				const char *name);
 	int (*get_reference_args)(const struct fwnode_handle *fwnode,
 				  const char *prop, const char *nargs_prop,
 				  unsigned int nargs, unsigned int index,
Signature · 1 line
2.19.1
reviewer Reviewed-by on the v1 series
#20 lore raw
In reply to Heikki Krogerus
Quoted 8 lines · Heikki Krogerus

Hi,

I prepared fwnode_name() for something I'm working on, but then I realized that it makes it possible to also implement a generic fwnode_get_named_child_node(). So in practice I'm proposing that we replace get_named_child_node fwnode op with that new "name" fwnode op in this series.

All LGTM, though consider one minor comment in patch 1.

Quoted 18 lines

thanks,

Heikki Krogerus (4):
device property: Introduce fwnode_name()
ACPI: property: Introduce acpi_fwnode_name() of/property: Introduce of_fwnode_name() device property: Drop get_named_child_node callback

 drivers/acpi/property.c  | 26 +++++++-------------------
 drivers/base/property.c  | 28 +++++++++++++++++++++++++++-
 drivers/of/property.c    | 21 ++++++---------------
 include/linux/fwnode.h   |  4 +---
 include/linux/property.h |  2 ++
 5 files changed, 43 insertions(+), 38 deletions(-)
Signature · 1 line
2.19.1
Signature · 2 lines
With Best Regards,
Andy Shevchenko