Skip to contentSkip to conversation

Device property improvements, add %pfw format specifier

PATCH Superseded Sakari Ailus 8 participants 36 messages Mar 26, 2019 – Mar 31, 2019

Subsystems (8)

v2 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Sakari Ailus

author reviewer
#0 lore raw

v2 cover Device property improvements, add %pfw format specifier

Hi all,

This set adds functionality into the device property API (counting a node's parents as well as obtaining its name) in order to support printing fwnode names using a new conversion specifier "%pfw". The names that are produced are equivalent to its OF counterpart "%pOF" on OF systems for the two supported modifiers ("f" and "P").

Printing a node's name is something that's been available on OF for a long time and if something is converted to device property API (such as the V4L2 fwnode framework) it always got removed of a nice feature that was sometimes essential in debugging. With this set, that no longer is the case.

This set depends on a cleanup fully releasing the now-deprecated %pf for other use:

<URL:https://lore.kernel.org/lkml/[email protected]/T/#t>

I was a bit hesitant on how much of this should be covered by the fwnode ops and how much would be just better to reside in lib/vsprintf.c, but opted for putting it to the fwnode interface. This keeps it clean in vsprintf.c and still rather lean on the fwnode ops side while making it possible to add other firmware types (although that is unlikely I guess).

since v1:

- Add patch to remove support for %pf and %pF (depends on another patch removing all use of %pf and %pF) (now 4th patch)

- Fix kerneldoc argument documentation for fwnode_get_name (2nd patch)

- Align kerneldoc style with the rest of drivers/base/property.c (no extra newline after function name)

- Make checkpatch.pl complain about "%pf" not followed by "w" (6th patch)

- WARN_ONCE() on use of invalid conversion specifiers ("%pf" not followed by "w")

Sakari Ailus (6):
device property: Add functions for accessing node's parents device property: Add fwnode_get_name for returning the name of a node device property: Add a function to obtain a node's prefix lib/vsprintf: Remove support for %pF and %pf in favour of %pS and %ps lib/vsprintf: Make use of fwnode API to obtain node names and
separators
lib/vsprintf: Add %pfw conversion specifier for printing fwnode names

 Documentation/core-api/printk-formats.rst |  34 +++++++---
 drivers/acpi/property.c                   |  46 ++++++++++++++
 drivers/base/property.c                   |  82 +++++++++++++++++++++---
 drivers/of/property.c                     |  16 +++++
 include/linux/fwnode.h                    |   4 ++
 include/linux/property.h                  |   5 ++
 lib/vsprintf.c                            | 101 +++++++++++++++++++++---------
 scripts/checkpatch.pl                     |   4 +-
 8 files changed, 245 insertions(+), 47 deletions(-)
Signature · 1 line
2.11.0
author reviewer
#1 lore raw

PATCH v2 1/6 device property: Add functions for accessing node's parents

Add two convenience functions for accessing node's parents:

fwnode_count_parents() returns the number of parent nodes a given node has. fwnode_get_nth_parent() returns node's parent at a given distance from the node itself.

Also reorder fwnode_get_parent() in property.c according to the same order as in property.h.

---
 drivers/base/property.c  | 59 ++++++++++++++++++++++++++++++++++++++++++------
 include/linux/property.h |  3 +++
 2 files changed, 55 insertions(+), 7 deletions(-)
drivers/base/property.c +52 -7
index 8b91ab380d14..61eb6ceacc3f 100644
@@ -533,6 +533,19 @@ int device_add_properties(struct device *dev,
 EXPORT_SYMBOL_GPL(device_add_properties);
 
 /**
+ * fwnode_get_parent - Return parent firwmare node
+ * @fwnode: Firmware whose parent is retrieved
+ *
+ * Return parent firmware node of the given node if possible or %NULL if no
+ * parent was available.
+ */
+struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode)
+{
+	return fwnode_call_ptr_op(fwnode, get_parent);
+}
+EXPORT_SYMBOL_GPL(fwnode_get_parent);
+
+/**
  * fwnode_get_next_parent - Iterate to the node's parent
  * @fwnode: Firmware whose parent is retrieved
  *
@@ -554,17 +567,49 @@ struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode)
 EXPORT_SYMBOL_GPL(fwnode_get_next_parent);
 
 /**
- * fwnode_get_parent - Return parent firwmare node
- * @fwnode: Firmware whose parent is retrieved
+ * fwnode_count_parents - Return the number of parents a node has
+ * @fwnode: The node the parents of which are to be counted
  *
- * Return parent firmware node of the given node if possible or %NULL if no
- * parent was available.
+ * Returns the number of parents a node has.
  */
-struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode)
+unsigned int fwnode_count_parents(struct fwnode_handle *fwnode)
 {
-	return fwnode_call_ptr_op(fwnode, get_parent);
+	unsigned int count;
+
+	fwnode_handle_get(fwnode);
+
+	for (count = 0; fwnode; count++)
+		fwnode = fwnode_get_next_parent(fwnode);
+
+	return count - 1;
 }
-EXPORT_SYMBOL_GPL(fwnode_get_parent);
+EXPORT_SYMBOL_GPL(fwnode_count_parents);
+
+/**
+ * fwnode_get_nth_parent - Return an nth parent of a node
+ * @fwnode: The node the parent of which is requested
+ * @depth: Distance of the parent from the node
+ *
+ * Returns the nth parent of a node. If @depth is 0, the functionality is
+ * equivalent to fwnode_handle_get(). For @depth == 1, it is fwnode_get_parent()
+ * and so on.
+ *
+ * The caller is responsible for calling fwnode_handle_put() for the returned
+ * node.
+ */
+struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwnode,
+					    unsigned int depth)
+{
+	unsigned int i;
+
+	fwnode_handle_get(fwnode);
+
+	for (i = 0; i < depth && fwnode; i++)
+		fwnode = fwnode_get_next_parent(fwnode);
+
+	return fwnode;
+}
+EXPORT_SYMBOL_GPL(fwnode_get_nth_parent);
 
 /**
  * fwnode_get_next_child_node - Return the next child node handle for a node
include/linux/property.h +3 -0
index 65d3420dd5d1..1164ac974ee8 100644
@@ -81,6 +81,9 @@ int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
 struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode);
 struct fwnode_handle *fwnode_get_next_parent(
 	struct fwnode_handle *fwnode);
+unsigned int fwnode_count_parents(struct fwnode_handle *fwn);
+struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn,
+					    unsigned int depth);
 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.11.0
maintainer
#2 lore raw

Re: [PATCH v2 1/6] device property: Add functions for accessing node's parents

Quoted 26 lines · Sakari Ailus

Add two convenience functions for accessing node's parents:

fwnode_count_parents() returns the number of parent nodes a given node has. fwnode_get_nth_parent() returns node's parent at a given distance from the node itself.

Also reorder fwnode_get_parent() in property.c according to the same order as in property.h.

drivers/base/property.c +3 -4
index 8b91ab380d14..61eb6ceacc3f 100644
@@ -554,17 +567,49 @@ struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode)
 EXPORT_SYMBOL_GPL(fwnode_get_next_parent);
 
 /**
- * fwnode_get_parent - Return parent firwmare node
- * @fwnode: Firmware whose parent is retrieved
+ * fwnode_count_parents - Return the number of parents a node has
+ * @fwnode: The node the parents of which are to be counted
  *
- * Return parent firmware node of the given node if possible or %NULL if no
- * parent was available.
+ * Returns the number of parents a node has.
  */

drivers/base/property.c struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode) · line 582

Quoted 10 lines
drivers/base/property.c +7 -2
-struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode)
+unsigned int fwnode_count_parents(struct fwnode_handle *fwnode)
 {
-	return fwnode_call_ptr_op(fwnode, get_parent);
+	unsigned int count;
+
+	fwnode_handle_get(fwnode);
+
+	for (count = 0; fwnode; count++)
+		fwnode = fwnode_get_next_parent(fwnode);

Is it guaranteed that all parents stay when fwnode_get_next_parent() releases the reference count for each counted member?

drivers/base/property.c struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode) · line 584

Quoted 2 lines
drivers/base/property.c +2 -0
+
+	return count - 1;

We could start counting from count = -1;

drivers/base/property.c struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode) · line 587

Quoted 4 lines
drivers/base/property.c +2 -1
 }
-EXPORT_SYMBOL_GPL(fwnode_get_parent);
+EXPORT_SYMBOL_GPL(fwnode_count_parents);
+

Best Regards,
Petr

author reviewer
#3 lore raw

Re: [PATCH v2 1/6] device property: Add functions for accessing node's parents

Hi Petr,

Quoted 33 lines · Petr Mladek
Quoted 32 lines · Sakari Ailus

Add two convenience functions for accessing node's parents:

fwnode_count_parents() returns the number of parent nodes a given node has. fwnode_get_nth_parent() returns node's parent at a given distance from the node itself.

Also reorder fwnode_get_parent() in property.c according to the same order as in property.h.

drivers/base/property.c +6 -6
index 8b91ab380d14..61eb6ceacc3f 100644
@@ -554,17 +567,49 @@ struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode)
 EXPORT_SYMBOL_GPL(fwnode_get_next_parent);
 
 /**
- * fwnode_get_parent - Return parent firwmare node
- * @fwnode: Firmware whose parent is retrieved
+ * fwnode_count_parents - Return the number of parents a node has
+ * @fwnode: The node the parents of which are to be counted
  *
- * Return parent firmware node of the given node if possible or %NULL if no
- * parent was available.
+ * Returns the number of parents a node has.
  */
-struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode)
+unsigned int fwnode_count_parents(struct fwnode_handle *fwnode)
 {
-	return fwnode_call_ptr_op(fwnode, get_parent);
+	unsigned int count;
+
Quoted 8 lines

drivers/base/property.c struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode) · line 582

Quoted 4 lines
drivers/base/property.c +4 -0
+	fwnode_handle_get(fwnode);
+
+	for (count = 0; fwnode; count++)
+		fwnode = fwnode_get_next_parent(fwnode);

Is it guaranteed that all parents stay when fwnode_get_next_parent() releases the reference count for each counted member?

fwnode_get_next_parent() only releases the child node after it has acquired the parent. The only implementation with refcounting for single nodes is actually OF.

Quoted 5 lines

drivers/base/property.c struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode) · line 584

Quoted 3 lines
drivers/base/property.c +2 -0
+
+	return count - 1;

We could start counting from count = -1;

We could, but then count would need to be made signed (unless overflowing is preferred instead).

Signature · 4 lines
Regards,

Sakari Ailus
[email protected]
#4 lore raw

Re: [PATCH v2 1/6] device property: Add functions for accessing node's parents

Quoted 51 lines · Sakari Ailus

Hi Petr,

Quoted 33 lines · Petr Mladek
Quoted 32 lines · Sakari Ailus

Add two convenience functions for accessing node's parents:

fwnode_count_parents() returns the number of parent nodes a given node has. fwnode_get_nth_parent() returns node's parent at a given distance from the node itself.

Also reorder fwnode_get_parent() in property.c according to the same order as in property.h.

drivers/base/property.c +6 -6
index 8b91ab380d14..61eb6ceacc3f 100644
@@ -554,17 +567,49 @@ struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode)
 EXPORT_SYMBOL_GPL(fwnode_get_next_parent);
 
 /**
- * fwnode_get_parent - Return parent firwmare node
- * @fwnode: Firmware whose parent is retrieved
+ * fwnode_count_parents - Return the number of parents a node has
+ * @fwnode: The node the parents of which are to be counted
  *
- * Return parent firmware node of the given node if possible or %NULL if no
- * parent was available.
+ * Returns the number of parents a node has.
  */
-struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode)
+unsigned int fwnode_count_parents(struct fwnode_handle *fwnode)
 {
-   return fwnode_call_ptr_op(fwnode, get_parent);
+   unsigned int count;
+
Quoted 8 lines

drivers/base/property.c struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode) · line 582

Quoted 4 lines
drivers/base/property.c +4 -0
+   fwnode_handle_get(fwnode);
+
+   for (count = 0; fwnode; count++)
+           fwnode = fwnode_get_next_parent(fwnode);

Is it guaranteed that all parents stay when fwnode_get_next_parent() releases the reference count for each counted member?

fwnode_get_next_parent() only releases the child node after it has acquired the parent. The only implementation with refcounting for single nodes is actually OF.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

drivers/base/property.c struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode) · line 584

Quoted 2 lines
drivers/base/property.c +2 -0
+
+   return count - 1;

We could start counting from count = -1;

We could, but then count would need to be made signed (unless overflowing is preferred instead).

What if there are no parents?

Or is it guaranteed that there always will be at least one?

author reviewer
#5 lore raw

Re: [PATCH v2 1/6] device property: Add functions for accessing node's parents

Hi Rafael,

Quoted 56 lines · Rafael J. Wysocki
Quoted 54 lines · Sakari Ailus

Hi Petr,

Quoted 33 lines · Petr Mladek
Quoted 32 lines · Sakari Ailus

Add two convenience functions for accessing node's parents:

fwnode_count_parents() returns the number of parent nodes a given node has. fwnode_get_nth_parent() returns node's parent at a given distance from the node itself.

Also reorder fwnode_get_parent() in property.c according to the same order as in property.h.

drivers/base/property.c +6 -6
index 8b91ab380d14..61eb6ceacc3f 100644
@@ -554,17 +567,49 @@ struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode)
 EXPORT_SYMBOL_GPL(fwnode_get_next_parent);
 
 /**
- * fwnode_get_parent - Return parent firwmare node
- * @fwnode: Firmware whose parent is retrieved
+ * fwnode_count_parents - Return the number of parents a node has
+ * @fwnode: The node the parents of which are to be counted
  *
- * Return parent firmware node of the given node if possible or %NULL if no
- * parent was available.
+ * Returns the number of parents a node has.
  */
-struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode)
+unsigned int fwnode_count_parents(struct fwnode_handle *fwnode)
 {
-   return fwnode_call_ptr_op(fwnode, get_parent);
+   unsigned int count;
+
Quoted 8 lines

drivers/base/property.c struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode) · line 582

Quoted 4 lines
drivers/base/property.c +4 -0
+   fwnode_handle_get(fwnode);
+
+   for (count = 0; fwnode; count++)
+           fwnode = fwnode_get_next_parent(fwnode);

Is it guaranteed that all parents stay when fwnode_get_next_parent() releases the reference count for each counted member?

fwnode_get_next_parent() only releases the child node after it has acquired the parent. The only implementation with refcounting for single nodes is actually OF.

Quoted 4 lines
Quoted 3 lines
drivers/base/property.c +2 -0
+
+   return count - 1;
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

We could start counting from count = -1;

We could, but then count would need to be made signed (unless overflowing is preferred instead).

What if there are no parents?

Or is it guaranteed that there always will be at least one?

If there are no parents, the function will return 0 --- the node itself is counted in the loop, too, hence the need to decrement by one.

Signature · 4 lines
Regards,

Sakari Ailus
[email protected]
#6 lore raw

Re: [PATCH v2 1/6] device property: Add functions for accessing node's parents

Quoted 65 lines · Sakari Ailus

Hi Rafael,

Quoted 61 lines · Rafael J. Wysocki
Quoted 58 lines · Sakari Ailus

Hi Petr,

Quoted 33 lines · Petr Mladek
Quoted 32 lines · Sakari Ailus

Add two convenience functions for accessing node's parents:

fwnode_count_parents() returns the number of parent nodes a given node has. fwnode_get_nth_parent() returns node's parent at a given distance from the node itself.

Also reorder fwnode_get_parent() in property.c according to the same order as in property.h.

drivers/base/property.c +6 -6
index 8b91ab380d14..61eb6ceacc3f 100644
@@ -554,17 +567,49 @@ struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode)
 EXPORT_SYMBOL_GPL(fwnode_get_next_parent);
 
 /**
- * fwnode_get_parent - Return parent firwmare node
- * @fwnode: Firmware whose parent is retrieved
+ * fwnode_count_parents - Return the number of parents a node has
+ * @fwnode: The node the parents of which are to be counted
  *
- * Return parent firmware node of the given node if possible or %NULL if no
- * parent was available.
+ * Returns the number of parents a node has.
  */
-struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode)
+unsigned int fwnode_count_parents(struct fwnode_handle *fwnode)
 {
-   return fwnode_call_ptr_op(fwnode, get_parent);
+   unsigned int count;
+
Quoted 8 lines

drivers/base/property.c struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode) · line 582

Quoted 4 lines
drivers/base/property.c +4 -0
+   fwnode_handle_get(fwnode);
+
+   for (count = 0; fwnode; count++)
+           fwnode = fwnode_get_next_parent(fwnode);

Is it guaranteed that all parents stay when fwnode_get_next_parent() releases the reference count for each counted member?

fwnode_get_next_parent() only releases the child node after it has acquired the parent. The only implementation with refcounting for single nodes is actually OF.

Quoted 5 lines

drivers/base/property.c struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode) · line 584

Quoted 3 lines
drivers/base/property.c +2 -0
+
+   return count - 1;

We could start counting from count = -1;

We could, but then count would need to be made signed (unless overflowing is preferred instead).

Quoted 6 lines
Quoted 3 lines

What if there are no parents?

Or is it guaranteed that there always will be at least one?

If there are no parents, the function will return 0 --- the node itself is counted in the loop, too, hence the need to decrement by one.

Right, sorry.

Then I don't see why count cannot be int. Or call it "iter" to avoid confusion with negative "counts". :-)

author reviewer
#7 lore raw

Re: [PATCH v2 1/6] device property: Add functions for accessing node's parents

Quoted 71 lines · Rafael J. Wysocki
Quoted 69 lines · Sakari Ailus

Hi Rafael,

Quoted 64 lines · Rafael J. Wysocki
Quoted 51 lines · Sakari Ailus

Hi Petr,

Quoted 33 lines · Petr Mladek
Quoted 32 lines · Sakari Ailus

Add two convenience functions for accessing node's parents:

fwnode_count_parents() returns the number of parent nodes a given node has. fwnode_get_nth_parent() returns node's parent at a given distance from the node itself.

Also reorder fwnode_get_parent() in property.c according to the same order as in property.h.

drivers/base/property.c +6 -6
index 8b91ab380d14..61eb6ceacc3f 100644
@@ -554,17 +567,49 @@ struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode)
 EXPORT_SYMBOL_GPL(fwnode_get_next_parent);
 
 /**
- * fwnode_get_parent - Return parent firwmare node
- * @fwnode: Firmware whose parent is retrieved
+ * fwnode_count_parents - Return the number of parents a node has
+ * @fwnode: The node the parents of which are to be counted
  *
- * Return parent firmware node of the given node if possible or %NULL if no
- * parent was available.
+ * Returns the number of parents a node has.
  */
-struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode)
+unsigned int fwnode_count_parents(struct fwnode_handle *fwnode)
 {
-   return fwnode_call_ptr_op(fwnode, get_parent);
+   unsigned int count;
+
Quoted 8 lines

drivers/base/property.c struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode) · line 582

Quoted 4 lines
drivers/base/property.c +4 -0
+   fwnode_handle_get(fwnode);
+
+   for (count = 0; fwnode; count++)
+           fwnode = fwnode_get_next_parent(fwnode);

Is it guaranteed that all parents stay when fwnode_get_next_parent() releases the reference count for each counted member?

fwnode_get_next_parent() only releases the child node after it has acquired the parent. The only implementation with refcounting for single nodes is actually OF.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

drivers/base/property.c struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode) · line 584

Quoted 2 lines
drivers/base/property.c +2 -0
+
+   return count - 1;

We could start counting from count = -1;

We could, but then count would need to be made signed (unless overflowing is preferred instead).

What if there are no parents?

Or is it guaranteed that there always will be at least one?

Quoted 7 lines
Quoted 2 lines

If there are no parents, the function will return 0 --- the node itself is counted in the loop, too, hence the need to decrement by one.

Right, sorry.

Then I don't see why count cannot be int. Or call it "iter" to avoid confusion with negative "counts". :-)

Another option would be changing where the counting starts --- the first parent. I.e.

fwnode = fwnode_get_parent(fwnode);

for (count = 0; fwnode; count++)

	fwnode = fwnode_get_next_parent(fwnode);

return count;

Signature · 2 lines
Sakari Ailus
[email protected]
#8 lore raw

Re: [PATCH v2 1/6] device property: Add functions for accessing node's parents

Quoted 11 lines · Sakari Ailus
Quoted 7 lines · Rafael J. Wysocki
Quoted 5 lines · Sakari Ailus
Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines · Sakari Ailus
Quoted 1 line · Petr Mladek

On Tue 2019-03-26 14:41:01, Sakari Ailus wrote:

Another option would be changing where the counting starts --- the first parent. I.e.

Looks better to me, though can you put comment how parents are being counted?

Quoted 6 lines

fwnode = fwnode_get_parent(fwnode);

for (count = 0; fwnode; count++)

	fwnode = fwnode_get_next_parent(fwnode);

return count;

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

Re: [PATCH v2 1/6] device property: Add functions for accessing node's parents

Hi Andy,

Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Sakari Ailus
Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines · Sakari Ailus
Quoted 2 lines · Rafael J. Wysocki

On Wed, Mar 27, 2019 at 3:20 PM Sakari Ailus
<[email protected]> wrote:

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines · Petr Mladek
Quoted 1 line · Sakari Ailus

Another option would be changing where the counting starts --- the first parent. I.e.

Looks better to me, though can you put comment how parents are being counted?

To the code? The kerneldoc comment contains one, and the code below is pretty simple.

Quoted 8 lines
Quoted 7 lines

fwnode = fwnode_get_parent(fwnode);

for (count = 0; fwnode; count++)

	fwnode = fwnode_get_next_parent(fwnode);

return count;

Signature · 2 lines
Sakari Ailus
[email protected]
#10 lore raw

Re: [PATCH v2 1/6] device property: Add functions for accessing node's parents

In reply to Sakari Ailus
Quoted 83 lines · CET Sakari Ailus
Quoted 71 lines · Rafael J. Wysocki
Quoted 69 lines · Sakari Ailus

Hi Rafael,

Quoted 64 lines · Rafael J. Wysocki
Quoted 51 lines · Sakari Ailus

Hi Petr,

Quoted 33 lines · Petr Mladek
Quoted 32 lines · Sakari Ailus

Add two convenience functions for accessing node's parents:

fwnode_count_parents() returns the number of parent nodes a given node has. fwnode_get_nth_parent() returns node's parent at a given distance from the node itself.

Also reorder fwnode_get_parent() in property.c according to the same order as in property.h.

drivers/base/property.c +6 -6
index 8b91ab380d14..61eb6ceacc3f 100644
@@ -554,17 +567,49 @@ struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode)
 EXPORT_SYMBOL_GPL(fwnode_get_next_parent);
 
 /**
- * fwnode_get_parent - Return parent firwmare node
- * @fwnode: Firmware whose parent is retrieved
+ * fwnode_count_parents - Return the number of parents a node has
+ * @fwnode: The node the parents of which are to be counted
  *
- * Return parent firmware node of the given node if possible or %NULL if no
- * parent was available.
+ * Returns the number of parents a node has.
  */
-struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode)
+unsigned int fwnode_count_parents(struct fwnode_handle *fwnode)
 {
-   return fwnode_call_ptr_op(fwnode, get_parent);
+   unsigned int count;
+
Quoted 8 lines

drivers/base/property.c struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode) · line 582

Quoted 4 lines
drivers/base/property.c +4 -0
+   fwnode_handle_get(fwnode);
+
+   for (count = 0; fwnode; count++)
+           fwnode = fwnode_get_next_parent(fwnode);

Is it guaranteed that all parents stay when fwnode_get_next_parent() releases the reference count for each counted member?

fwnode_get_next_parent() only releases the child node after it has acquired the parent. The only implementation with refcounting for single nodes is actually OF.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

drivers/base/property.c struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode) · line 584

Quoted 2 lines
drivers/base/property.c +2 -0
+
+   return count - 1;

We could start counting from count = -1;

We could, but then count would need to be made signed (unless overflowing is preferred instead).

What if there are no parents?

Or is it guaranteed that there always will be at least one?

Quoted 7 lines
Quoted 2 lines

If there are no parents, the function will return 0 --- the node itself is counted in the loop, too, hence the need to decrement by one.

Right, sorry.

Then I don't see why count cannot be int. Or call it "iter" to avoid confusion with negative "counts". :-)

Another option would be changing where the counting starts --- the first parent. I.e.

Quoted 6 lines

fwnode = fwnode_get_parent(fwnode);

for (count = 0; fwnode; count++)

	fwnode = fwnode_get_next_parent(fwnode);

return count;

LGTM, thanks!

maintainer
#11 lore raw

Re: [PATCH v2 1/6] device property: Add functions for accessing node's parents

In reply to Sakari Ailus
Quoted 45 lines · Sakari Ailus

Hi Petr,

Quoted 33 lines · Petr Mladek
Quoted 32 lines · Sakari Ailus

Add two convenience functions for accessing node's parents:

fwnode_count_parents() returns the number of parent nodes a given node has. fwnode_get_nth_parent() returns node's parent at a given distance from the node itself.

Also reorder fwnode_get_parent() in property.c according to the same order as in property.h.

drivers/base/property.c +6 -6
index 8b91ab380d14..61eb6ceacc3f 100644
@@ -554,17 +567,49 @@ struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode)
 EXPORT_SYMBOL_GPL(fwnode_get_next_parent);
 
 /**
- * fwnode_get_parent - Return parent firwmare node
- * @fwnode: Firmware whose parent is retrieved
+ * fwnode_count_parents - Return the number of parents a node has
+ * @fwnode: The node the parents of which are to be counted
  *
- * Return parent firmware node of the given node if possible or %NULL if no
- * parent was available.
+ * Returns the number of parents a node has.
  */
-struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode)
+unsigned int fwnode_count_parents(struct fwnode_handle *fwnode)
 {
-	return fwnode_call_ptr_op(fwnode, get_parent);
+	unsigned int count;
+
Quoted 8 lines

drivers/base/property.c struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode) · line 582

Quoted 4 lines
drivers/base/property.c +4 -0
+	fwnode_handle_get(fwnode);
+
+	for (count = 0; fwnode; count++)
+		fwnode = fwnode_get_next_parent(fwnode);

Is it guaranteed that all parents stay when fwnode_get_next_parent() releases the reference count for each counted member?

Quoted 3 lines

fwnode_get_next_parent() only releases the child node after it has acquired the parent. The only implementation with refcounting for single nodes is actually OF.

I am still a bit confused. The function is later used the following way:

	for (depth = fwnode_count_parents(fwnode); depth >= 0; depth--) {
		struct fwnode_handle *__fwnode =
			fwnode_get_nth_parent(fwnode, depth);

		buf = string(buf, end, fwnode_get_name_prefix(__fwnode),
			     default_str_spec);
		buf = string(buf, end, fwnode_get_name(__fwnode),
			     default_str_spec);

		fwnode_handle_put(__fwnode);
	}

It uses the number to walk the hierarchy over and over again to print the path from root.

I would expect that parents could not get removed until all children are removed. And that the most bottom child (fwnode) must not get removed. Otherwise we would access freed memory in each cycle.

Then there is a question why we need to get the reference of the parents
at all.

It might be because we do not need touch refcounting of the parents in this scenario. But we are re-using existing functions where the ref-counting hang-over is important.

Or we really need to increase refcounting of parents. Then it looks suspicious because we want to traverse the same path several times and always have only one node locked (refcounted).

Best Regards,
Petr

author reviewer
#12 lore raw

Re: [PATCH v2 1/6] device property: Add functions for accessing node's parents

Hi Petr,

Quoted 75 lines · Petr Mladek
Quoted 45 lines · Sakari Ailus

Hi Petr,

Quoted 33 lines · Petr Mladek
Quoted 32 lines · Sakari Ailus

Add two convenience functions for accessing node's parents:

fwnode_count_parents() returns the number of parent nodes a given node has. fwnode_get_nth_parent() returns node's parent at a given distance from the node itself.

Also reorder fwnode_get_parent() in property.c according to the same order as in property.h.

drivers/base/property.c +6 -6
index 8b91ab380d14..61eb6ceacc3f 100644
@@ -554,17 +567,49 @@ struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode)
 EXPORT_SYMBOL_GPL(fwnode_get_next_parent);
 
 /**
- * fwnode_get_parent - Return parent firwmare node
- * @fwnode: Firmware whose parent is retrieved
+ * fwnode_count_parents - Return the number of parents a node has
+ * @fwnode: The node the parents of which are to be counted
  *
- * Return parent firmware node of the given node if possible or %NULL if no
- * parent was available.
+ * Returns the number of parents a node has.
  */
-struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode)
+unsigned int fwnode_count_parents(struct fwnode_handle *fwnode)
 {
-	return fwnode_call_ptr_op(fwnode, get_parent);
+	unsigned int count;
+
Quoted 8 lines

drivers/base/property.c struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode) · line 582

Quoted 4 lines
drivers/base/property.c +4 -0
+	fwnode_handle_get(fwnode);
+
+	for (count = 0; fwnode; count++)
+		fwnode = fwnode_get_next_parent(fwnode);

Is it guaranteed that all parents stay when fwnode_get_next_parent() releases the reference count for each counted member?

Quoted 3 lines

fwnode_get_next_parent() only releases the child node after it has acquired the parent. The only implementation with refcounting for single nodes is actually OF.

I am still a bit confused. The function is later used the following way:

	for (depth = fwnode_count_parents(fwnode); depth >= 0; depth--) {
		struct fwnode_handle *__fwnode =
			fwnode_get_nth_parent(fwnode, depth);

		buf = string(buf, end, fwnode_get_name_prefix(__fwnode),
			     default_str_spec);
		buf = string(buf, end, fwnode_get_name(__fwnode),
			     default_str_spec);

		fwnode_handle_put(__fwnode);
	}

It uses the number to walk the hierarchy over and over again to print the path from root.

I would expect that parents could not get removed until all children are removed. And that the most bottom child (fwnode) must not get removed. Otherwise we would access freed memory in each cycle.

Then there is a question why we need to get the reference of the parents
at all.

Quoted 7 lines

It might be because we do not need touch refcounting of the parents in this scenario. But we are re-using existing functions where the ref-counting hang-over is important.

Or we really need to increase refcounting of parents. Then it looks suspicious because we want to traverse the same path several times and always have only one node locked (refcounted).

I hope I understand your concern better this time.

You basically have to have a reference to a node until you're done accessing it. The refcounting in the fwnode framework is based on the OF API --- otherwise you couldn't access OF nodes using the framework. ACPI does not have those (as you can't dynamically remove nodes). The newly added swnode does have refcounting of individual nodes as well.

Even if a node's parent did disappear while printing an fwnode full name, it'd mean that

1) fwnode_count_parents() returned an incorrect value (less than expected) or

2) some of the node names could be NULL if node references could not be obtained.

Both would result into garbled output in that case. I have to admit I'm not sure if this is possible with OF.

Signature · 4 lines
Kind regards,

Sakari Ailus
[email protected]
#13 lore raw

Re: [PATCH v2 1/6] device property: Add functions for accessing node's parents

Quoted 8 lines · Sakari Ailus

On Thu, Mar 28, 2019 at 03:10:36PM +0100, Petr Mladek wrote:

You basically have to have a reference to a node until you're done accessing it. The refcounting in the fwnode framework is based on the OF API --- otherwise you couldn't access OF nodes using the framework.

ACPI
does not have those (as you can't dynamically remove nodes).

What about configfs where we can load / unload tables at run time?

Quoted 2 lines

The newly
added swnode does have refcounting of individual nodes as well.

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

Re: [PATCH v2 1/6] device property: Add functions for accessing node's parents

Hi Andy,

Quoted 11 lines · Andy Shevchenko
Quoted 8 lines · Sakari Ailus

On Thu, Mar 28, 2019 at 03:10:36PM +0100, Petr Mladek wrote:

You basically have to have a reference to a node until you're done accessing it. The refcounting in the fwnode framework is based on the OF API --- otherwise you couldn't access OF nodes using the framework.

ACPI
does not have those (as you can't dynamically remove nodes).

What about configfs where we can load / unload tables at run time?

Hmm. I have to admit I missed this one.

Well, I guess that this feature depends on the user making sure there are no references to the tables that are to be removed, as there is no refcounting. Let me know if I'm missing something, but nothing appears to prevent releasing nodes that are in use.

If that is really so, then refcounting or another mechanism to achieve something similar should be added to make removal safe, but this isn't related to printing the node names anymore nor such fixes belong to this patchset.

Signature · 4 lines
Regards,

Sakari Ailus
[email protected]
author reviewer
#15 lore raw

PATCH v2 2/6 device property: Add fwnode_get_name for returning the name of a node

In reply to Sakari Ailus

The fwnode framework did not have means to obtain the name of a node. Add that now, in form of the fwnode_get_name() function and a corresponding get_name fwnode op. OF and ACPI support is included.

---
 drivers/acpi/property.c  | 24 ++++++++++++++++++++++++
 drivers/base/property.c  | 11 +++++++++++
 drivers/of/property.c    |  6 ++++++
 include/linux/fwnode.h   |  2 ++
 include/linux/property.h |  1 +
 5 files changed, 44 insertions(+)
drivers/acpi/property.c +24 -0
index 77abe0ec4043..8c9a4c02cde2 100644
@@ -1291,6 +1291,29 @@ acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode,
 						  args_count, args);
 }
 
+static const char *acpi_fwnode_get_name(const struct fwnode_handle *fwnode)
+{
+	const struct acpi_device *adev;
+	struct fwnode_handle *parent;
+
+	parent = fwnode_get_parent(fwnode);
+	/* Is this the root node? */
+	if (!parent)
+		return "\\";
+
+	fwnode_handle_put(parent);
+
+	if (is_acpi_data_node(fwnode)) {
+		const struct acpi_data_node *dn = to_acpi_data_node(fwnode);
+
+		return dn->name;
+	}
+
+	adev = to_acpi_device_node(fwnode);
+
+	return adev ? acpi_device_bid(adev) : NULL;
+}
+
 static struct fwnode_handle *
 acpi_fwnode_get_parent(struct fwnode_handle *fwnode)
 {
@@ -1331,6 +1354,7 @@ acpi_fwnode_device_get_match_data(const struct fwnode_handle *fwnode,
 		.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_name = acpi_fwnode_get_name,			\
 		.get_reference_args = acpi_fwnode_get_reference_args,	\
 		.graph_get_next_endpoint =				\
 			acpi_graph_get_next_endpoint,			\
drivers/base/property.c +11 -0
index 61eb6ceacc3f..04a8591cd1b0 100644
@@ -533,6 +533,17 @@ int device_add_properties(struct device *dev,
 EXPORT_SYMBOL_GPL(device_add_properties);
 
 /**
+ * fwnode_get_name - Return the name of a node
+ * @fwnode: The firmware node
+ *
+ * Returns a pointer to the node name.
+ */
+const char *fwnode_get_name(const struct fwnode_handle *fwnode)
+{
+	return fwnode_call_ptr_op(fwnode, get_name);
+}
+
+/**
  * fwnode_get_parent - Return parent firwmare node
  * @fwnode: Firmware whose parent is retrieved
  *
drivers/of/property.c +6 -0
index 8631efa1daa1..f0a7b78f2d9f 100644
@@ -872,6 +872,11 @@ of_fwnode_property_read_string_array(const struct fwnode_handle *fwnode,
 		of_property_count_strings(node, propname);
 }
 
+static const char *of_fwnode_get_name(const struct fwnode_handle *fwnode)
+{
+	return kbasename(to_of_node(fwnode)->full_name);
+}
+
 static struct fwnode_handle *
 of_fwnode_get_parent(const struct fwnode_handle *fwnode)
 {
@@ -993,6 +998,7 @@ const struct fwnode_operations of_fwnode_ops = {
 	.property_present = of_fwnode_property_present,
 	.property_read_int_array = of_fwnode_property_read_int_array,
 	.property_read_string_array = of_fwnode_property_read_string_array,
+	.get_name = of_fwnode_get_name,
 	.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,
include/linux/fwnode.h +2 -0
index faebf0ca0686..85b7fa4dc727 100644
@@ -59,6 +59,7 @@ struct fwnode_reference_args {
  *				 otherwise.
  * @property_read_string_array: Read an array of string properties. Return zero
  *				on success, a negative error code otherwise.
+ * @get_name: Return the name of an fwnode.
  * @get_parent: Return the parent of an fwnode.
  * @get_next_child_node: Return the next child node in an iteration.
  * @get_named_child_node: Return a child node with a given name.
@@ -85,6 +86,7 @@ struct fwnode_operations {
 	(*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
 				      const char *propname, const char **val,
 				      size_t nval);
+	const char *(*get_name)(const struct fwnode_handle *fwnode);
 	struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
 	struct fwnode_handle *
 	(*get_next_child_node)(const struct fwnode_handle *fwnode,
include/linux/property.h +1 -0
index 1164ac974ee8..2f5df900e310 100644
@@ -78,6 +78,7 @@ int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
 				       unsigned int nargs, unsigned int index,
 				       struct fwnode_reference_args *args);
 
+const char *fwnode_get_name(const struct fwnode_handle *fwnode);
 struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode);
 struct fwnode_handle *fwnode_get_next_parent(
 	struct fwnode_handle *fwnode);
Signature · 1 line
2.11.0
#16 lore raw

Re: [PATCH v2 2/6] device property: Add fwnode_get_name for returning the name of a node

Quoted 33 lines · Sakari Ailus

The fwnode framework did not have means to obtain the name of a node. Add that now, in form of the fwnode_get_name() function and a corresponding get_name fwnode op. OF and ACPI support is included.

---
 drivers/acpi/property.c  | 24 ++++++++++++++++++++++++
 drivers/base/property.c  | 11 +++++++++++
 drivers/of/property.c    |  6 ++++++
 include/linux/fwnode.h   |  2 ++
 include/linux/property.h |  1 +
 5 files changed, 44 insertions(+)
drivers/acpi/property.c +11 -0
index 77abe0ec4043..8c9a4c02cde2 100644
@@ -1291,6 +1291,29 @@ acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode,
                                                  args_count, args);
 }
 
+static const char *acpi_fwnode_get_name(const struct fwnode_handle *fwnode)
+{
+       const struct acpi_device *adev;
+       struct fwnode_handle *parent;
+
+       parent = fwnode_get_parent(fwnode);
+       /* Is this the root node? */
+       if (!parent)
+               return "\\";
+
+       fwnode_handle_put(parent);

drivers/acpi/property.c acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode, · line 1314

Quoted 10 lines
drivers/acpi/property.c +10 -0
+
+       if (is_acpi_data_node(fwnode)) {
+               const struct acpi_data_node *dn = to_acpi_data_node(fwnode);
+
+               return dn->name;
+       }
+
+       adev = to_acpi_device_node(fwnode);
+
+       return adev ? acpi_device_bid(adev) : NULL;

I would do

if (WARN_ON(!adev))

         return NULL;

return acpi_device_bid(adev);

Quoted 92 lines
drivers/acpi/property.c +3 -0
+}
+
 static struct fwnode_handle *
 acpi_fwnode_get_parent(struct fwnode_handle *fwnode)
 {
@@ -1331,6 +1354,7 @@ acpi_fwnode_device_get_match_data(const struct fwnode_handle *fwnode,
                .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_name = acpi_fwnode_get_name,                       \
                .get_reference_args = acpi_fwnode_get_reference_args,   \
                .graph_get_next_endpoint =                              \
                        acpi_graph_get_next_endpoint,                   \
drivers/base/property.c +11 -0
index 61eb6ceacc3f..04a8591cd1b0 100644
@@ -533,6 +533,17 @@ int device_add_properties(struct device *dev,
 EXPORT_SYMBOL_GPL(device_add_properties);
 
 /**
+ * fwnode_get_name - Return the name of a node
+ * @fwnode: The firmware node
+ *
+ * Returns a pointer to the node name.
+ */
+const char *fwnode_get_name(const struct fwnode_handle *fwnode)
+{
+       return fwnode_call_ptr_op(fwnode, get_name);
+}
+
+/**
  * fwnode_get_parent - Return parent firwmare node
  * @fwnode: Firmware whose parent is retrieved
  *
drivers/of/property.c +6 -0
index 8631efa1daa1..f0a7b78f2d9f 100644
@@ -872,6 +872,11 @@ of_fwnode_property_read_string_array(const struct fwnode_handle *fwnode,
                of_property_count_strings(node, propname);
 }
 
+static const char *of_fwnode_get_name(const struct fwnode_handle *fwnode)
+{
+       return kbasename(to_of_node(fwnode)->full_name);
+}
+
 static struct fwnode_handle *
 of_fwnode_get_parent(const struct fwnode_handle *fwnode)
 {
@@ -993,6 +998,7 @@ const struct fwnode_operations of_fwnode_ops = {
        .property_present = of_fwnode_property_present,
        .property_read_int_array = of_fwnode_property_read_int_array,
        .property_read_string_array = of_fwnode_property_read_string_array,
+       .get_name = of_fwnode_get_name,
        .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,
include/linux/fwnode.h +2 -0
index faebf0ca0686..85b7fa4dc727 100644
@@ -59,6 +59,7 @@ struct fwnode_reference_args {
  *                              otherwise.
  * @property_read_string_array: Read an array of string properties. Return zero
  *                             on success, a negative error code otherwise.
+ * @get_name: Return the name of an fwnode.
  * @get_parent: Return the parent of an fwnode.
  * @get_next_child_node: Return the next child node in an iteration.
  * @get_named_child_node: Return a child node with a given name.
@@ -85,6 +86,7 @@ struct fwnode_operations {
        (*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
                                      const char *propname, const char **val,
                                      size_t nval);
+       const char *(*get_name)(const struct fwnode_handle *fwnode);
        struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
        struct fwnode_handle *
        (*get_next_child_node)(const struct fwnode_handle *fwnode,
include/linux/property.h +1 -1
index 1164ac974ee8..2f5df900e310 100644
@@ -78,6 +78,7 @@ int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
                                       unsigned int nargs, unsigned int index,
                                       struct fwnode_reference_args *args);
 
+const char *fwnode_get_name(const struct fwnode_handle *fwnode);
 struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode);
 struct fwnode_handle *fwnode_get_next_parent(
        struct fwnode_handle *fwnode);
--
author reviewer
#17 lore raw

Re: [PATCH v2 2/6] device property: Add fwnode_get_name for returning the name of a node

Hi Rafael,

Quoted 48 lines · Rafael J. Wysocki
Quoted 33 lines · Sakari Ailus

The fwnode framework did not have means to obtain the name of a node. Add that now, in form of the fwnode_get_name() function and a corresponding get_name fwnode op. OF and ACPI support is included.

---
 drivers/acpi/property.c  | 24 ++++++++++++++++++++++++
 drivers/base/property.c  | 11 +++++++++++
 drivers/of/property.c    |  6 ++++++
 include/linux/fwnode.h   |  2 ++
 include/linux/property.h |  1 +
 5 files changed, 44 insertions(+)
drivers/acpi/property.c +11 -0
index 77abe0ec4043..8c9a4c02cde2 100644
@@ -1291,6 +1291,29 @@ acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode,
                                                  args_count, args);
 }
 
+static const char *acpi_fwnode_get_name(const struct fwnode_handle *fwnode)
+{
+       const struct acpi_device *adev;
+       struct fwnode_handle *parent;
+
+       parent = fwnode_get_parent(fwnode);
+       /* Is this the root node? */
+       if (!parent)
+               return "\\";
+
+       fwnode_handle_put(parent);

drivers/acpi/property.c acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode, · line 1314

Quoted 10 lines
drivers/acpi/property.c +10 -0
+
+       if (is_acpi_data_node(fwnode)) {
+               const struct acpi_data_node *dn = to_acpi_data_node(fwnode);
+
+               return dn->name;
+       }
+
+       adev = to_acpi_device_node(fwnode);
+
+       return adev ? acpi_device_bid(adev) : NULL;

I would do

Quoted 4 lines

if (WARN_ON(!adev))

         return NULL;

return acpi_device_bid(adev);

Done.

Signature · 2 lines
Sakari Ailus
[email protected]
maintainer Acked-by on v2 2/6
#18 lore raw

Re: [PATCH v2 2/6] device property: Add fwnode_get_name for returning the name of a node

In reply to Sakari Ailus
Quoted 9 lines · Sakari Ailus

The fwnode framework did not have means to obtain the name of a node. Add that now, in form of the fwnode_get_name() function and a corresponding get_name fwnode op. OF and ACPI support is included.

---
 drivers/acpi/property.c  | 24 ++++++++++++++++++++++++
 drivers/base/property.c  | 11 +++++++++++
 drivers/of/property.c    |  6 ++++++
Quoted 3 lines
 include/linux/fwnode.h   |  2 ++
 include/linux/property.h |  1 +
 5 files changed, 44 insertions(+)
author reviewer
#19 lore raw

PATCH v2 3/6 device property: Add a function to obtain a node's prefix

In reply to Sakari Ailus

The prefix is used for printing purpose before a node, and it also works as a separator between two nodes.

---
 drivers/acpi/property.c  | 22 ++++++++++++++++++++++
 drivers/base/property.c  | 12 ++++++++++++
 drivers/of/property.c    | 10 ++++++++++
 include/linux/fwnode.h   |  2 ++
 include/linux/property.h |  1 +
 5 files changed, 47 insertions(+)
drivers/acpi/property.c +22 -0
index 8c9a4c02cde2..c167fd748f86 100644
@@ -1314,6 +1314,27 @@ static const char *acpi_fwnode_get_name(const struct fwnode_handle *fwnode)
 	return adev ? acpi_device_bid(adev) : NULL;
 }
 
+static const char *
+acpi_fwnode_get_name_prefix(const struct fwnode_handle *fwnode)
+{
+	struct fwnode_handle *parent;
+
+	parent = fwnode_get_parent(fwnode);
+	/* Root node. */
+	if (!parent)
+		return "";
+
+	parent = fwnode_get_next_parent(parent);
+	/* Second node from the root; no prefix here either. */
+	if (!parent)
+		return "";
+
+	fwnode_handle_put(parent);
+
+	/* ACPI device or data node. */
+	return ".";
+}
+
 static struct fwnode_handle *
 acpi_fwnode_get_parent(struct fwnode_handle *fwnode)
 {
@@ -1355,6 +1376,7 @@ acpi_fwnode_device_get_match_data(const struct fwnode_handle *fwnode,
 		.get_next_child_node = acpi_get_next_subnode,		\
 		.get_named_child_node = acpi_fwnode_get_named_child_node, \
 		.get_name = acpi_fwnode_get_name,			\
+		.get_name_prefix = acpi_fwnode_get_name_prefix,		\
 		.get_reference_args = acpi_fwnode_get_reference_args,	\
 		.graph_get_next_endpoint =				\
 			acpi_graph_get_next_endpoint,			\
drivers/base/property.c +12 -0
index 04a8591cd1b0..2e5b826a2376 100644
@@ -544,6 +544,18 @@ const char *fwnode_get_name(const struct fwnode_handle *fwnode)
 }
 
 /**
+ * fwnode_get_name_prefix - Return the prefix of node for printing purposes
+ * @fwnode: The firmware node
+ *
+ * Returns the prefix of a node, intended to be printed right before the node.
+ * The prefix works also as a separator between the nodes.
+ */
+const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode)
+{
+	return fwnode_call_ptr_op(fwnode, get_name_prefix);
+}
+
+/**
  * fwnode_get_parent - Return parent firwmare node
  * @fwnode: Firmware whose parent is retrieved
  *
drivers/of/property.c +10 -0
index f0a7b78f2d9f..8fed3b142b41 100644
@@ -877,6 +877,15 @@ static const char *of_fwnode_get_name(const struct fwnode_handle *fwnode)
 	return kbasename(to_of_node(fwnode)->full_name);
 }
 
+static const char *of_fwnode_get_name_prefix(const struct fwnode_handle *fwnode)
+{
+	/* Root needs no prefix here (its name is "/"). */
+	if (!to_of_node(fwnode)->parent)
+		return "";
+
+	return "/";
+}
+
 static struct fwnode_handle *
 of_fwnode_get_parent(const struct fwnode_handle *fwnode)
 {
@@ -999,6 +1008,7 @@ const struct fwnode_operations of_fwnode_ops = {
 	.property_read_int_array = of_fwnode_property_read_int_array,
 	.property_read_string_array = of_fwnode_property_read_string_array,
 	.get_name = of_fwnode_get_name,
+	.get_name_prefix = of_fwnode_get_name_prefix,
 	.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,
include/linux/fwnode.h +2 -0
index 85b7fa4dc727..592ac6936e14 100644
@@ -60,6 +60,7 @@ struct fwnode_reference_args {
  * @property_read_string_array: Read an array of string properties. Return zero
  *				on success, a negative error code otherwise.
  * @get_name: Return the name of an fwnode.
+ * @get_name_prefix: Get a prefix for a node (for printing purposes).
  * @get_parent: Return the parent of an fwnode.
  * @get_next_child_node: Return the next child node in an iteration.
  * @get_named_child_node: Return a child node with a given name.
@@ -87,6 +88,7 @@ struct fwnode_operations {
 				      const char *propname, const char **val,
 				      size_t nval);
 	const char *(*get_name)(const struct fwnode_handle *fwnode);
+	const char *(*get_name_prefix)(const struct fwnode_handle *fwnode);
 	struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
 	struct fwnode_handle *
 	(*get_next_child_node)(const struct fwnode_handle *fwnode,
include/linux/property.h +1 -0
index 2f5df900e310..0ea466ee8c3d 100644
@@ -79,6 +79,7 @@ int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
 				       struct fwnode_reference_args *args);
 
 const char *fwnode_get_name(const struct fwnode_handle *fwnode);
+const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode);
 struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode);
 struct fwnode_handle *fwnode_get_next_parent(
 	struct fwnode_handle *fwnode);
Signature · 1 line
2.11.0
#20 lore raw

Re: [PATCH v2 3/6] device property: Add a function to obtain a node's prefix

Quoted 3 lines · Sakari Ailus

The prefix is used for printing purpose before a node, and it also works as a separator between two nodes.

One nit below.

drivers/acpi/property.c static const char *acpi_fwnode_get_name(const struct fwnode_handle *fwnode) · line 1323

Quoted 8 lines
drivers/acpi/property.c +7 -0
+static const char *
+acpi_fwnode_get_name_prefix(const struct fwnode_handle *fwnode)
+{
+	struct fwnode_handle *parent;
+
 
+	parent = fwnode_get_parent(fwnode);
+	/* Root node. */

I guess a comment could be easier to read if it goes before parent assignment line.

drivers/acpi/property.c static const char *acpi_fwnode_get_name(const struct fwnode_handle *fwnode) · line 1328

Quoted 5 lines
drivers/acpi/property.c +5 -0
+	if (!parent)
+		return "";
+
+	parent = fwnode_get_next_parent(parent);
+	/* Second node from the root; no prefix here either. */

Ditto.

Quoted 8 lines
drivers/acpi/property.c +8 -0
+	if (!parent)
+		return "";
+
+	fwnode_handle_put(parent);
+
+	/* ACPI device or data node. */
+	return ".";
+}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author reviewer
#21 lore raw

Re: [PATCH v2 3/6] device property: Add a function to obtain a node's prefix

Hi Andy,

Quoted 13 lines · Andy Shevchenko
Quoted 3 lines · Sakari Ailus

The prefix is used for printing purpose before a node, and it also works as a separator between two nodes.

One nit below.

Quoted 5 lines
drivers/acpi/property.c +5 -0
+static const char *
+acpi_fwnode_get_name_prefix(const struct fwnode_handle *fwnode)
+{
+	struct fwnode_handle *parent;
+
Quoted 5 lines

drivers/acpi/property.c static const char *acpi_fwnode_get_name(const struct fwnode_handle *fwnode) · line 1323

Quoted 2 lines
drivers/acpi/property.c +2 -0
+	parent = fwnode_get_parent(fwnode);
+	/* Root node. */

I guess a comment could be easier to read if it goes before parent assignment line.

Only if the comments are changed accordingly. What we're doing here is trying to figure out whether this is the root node. I can do that for v3.

Quoted 17 lines

drivers/acpi/property.c static const char *acpi_fwnode_get_name(const struct fwnode_handle *fwnode) · line 1328

Quoted 6 lines
drivers/acpi/property.c +5 -0
+	if (!parent)
+		return "";
+
+	parent = fwnode_get_next_parent(parent);
+	/* Second node from the root; no prefix here either. */

Ditto.

Quoted 8 lines
drivers/acpi/property.c +8 -0
+	if (!parent)
+		return "";
+
+	fwnode_handle_put(parent);
+
+	/* ACPI device or data node. */
+	return ".";
+}
Signature · 4 lines
Regards,

Sakari Ailus
[email protected]
maintainer
#22 lore raw

Re: [PATCH v2 3/6] device property: Add a function to obtain a node's prefix

Quoted 16 lines · Sakari Ailus

Hi Andy,

Quoted 13 lines · Andy Shevchenko
Quoted 3 lines · Sakari Ailus

The prefix is used for printing purpose before a node, and it also works as a separator between two nodes.

One nit below.

Quoted 5 lines
drivers/acpi/property.c +5 -0
+static const char *
+acpi_fwnode_get_name_prefix(const struct fwnode_handle *fwnode)
+{
+	struct fwnode_handle *parent;
+
Quoted 8 lines
Quoted 5 lines

drivers/acpi/property.c static const char *acpi_fwnode_get_name(const struct fwnode_handle *fwnode) · line 1323

Quoted 2 lines
drivers/acpi/property.c +2 -0
+	parent = fwnode_get_parent(fwnode);
+	/* Root node. */

I guess a comment could be easier to read if it goes before parent assignment line.

Only if the comments are changed accordingly. What we're doing here is trying to figure out whether this is the root node. I can do that for v3.

IMHO, the comment in acpi_fwnode_get_name() is easier to understand:

/* Is this the root node? */

Quoted 8 lines
Quoted 8 lines

drivers/acpi/property.c static const char *acpi_fwnode_get_name(const struct fwnode_handle *fwnode) · line 1328

Quoted 6 lines
drivers/acpi/property.c +5 -0
+	if (!parent)
+		return "";
+
+	parent = fwnode_get_next_parent(parent);
+	/* Second node from the root; no prefix here either. */

Ditto.

/* Is this 2nd node from the root? */

Quoted 8 lines
Quoted 8 lines

drivers/acpi/property.c static const char *acpi_fwnode_get_name(const struct fwnode_handle *fwnode) · line 1336

Quoted 8 lines
drivers/acpi/property.c +8 -0
+	if (!parent)
+		return "";
+
+	fwnode_handle_put(parent);
+
+	/* ACPI device or data node. */
+	return ".";
+}

Best Regards,
Petr

author reviewer
#23 lore raw

Re: [PATCH v2 3/6] device property: Add a function to obtain a node's prefix

Quoted 39 lines · Petr Mladek
Quoted 16 lines · Sakari Ailus

Hi Andy,

Quoted 13 lines · Andy Shevchenko
Quoted 3 lines · Sakari Ailus

The prefix is used for printing purpose before a node, and it also works as a separator between two nodes.

One nit below.

Quoted 5 lines
drivers/acpi/property.c +5 -0
+static const char *
+acpi_fwnode_get_name_prefix(const struct fwnode_handle *fwnode)
+{
+	struct fwnode_handle *parent;
+
Quoted 8 lines
Quoted 5 lines

drivers/acpi/property.c static const char *acpi_fwnode_get_name(const struct fwnode_handle *fwnode) · line 1323

Quoted 2 lines
drivers/acpi/property.c +2 -0
+	parent = fwnode_get_parent(fwnode);
+	/* Root node. */

I guess a comment could be easier to read if it goes before parent assignment line.

Only if the comments are changed accordingly. What we're doing here is trying to figure out whether this is the root node. I can do that for v3.

IMHO, the comment in acpi_fwnode_get_name() is easier to understand:

/* Is this the root node? */

Quoted 8 lines
Quoted 8 lines

drivers/acpi/property.c static const char *acpi_fwnode_get_name(const struct fwnode_handle *fwnode) · line 1328

Quoted 6 lines
drivers/acpi/property.c +5 -0
+	if (!parent)
+		return "";
+
+	parent = fwnode_get_next_parent(parent);
+	/* Second node from the root; no prefix here either. */

Ditto.

Quoted 1 line

/* Is this 2nd node from the root? */

I used both the strings.

Signature · 2 lines
Sakari Ailus
[email protected]
maintainer Acked-by on v2 3/6
#24 lore raw

Re: [PATCH v2 3/6] device property: Add a function to obtain a node's prefix

In reply to Sakari Ailus
Quoted 8 lines · Sakari Ailus

The prefix is used for printing purpose before a node, and it also works as a separator between two nodes.

---
 drivers/acpi/property.c  | 22 ++++++++++++++++++++++
 drivers/base/property.c  | 12 ++++++++++++
 drivers/of/property.c    | 10 ++++++++++
Quoted 3 lines
 include/linux/fwnode.h   |  2 ++
 include/linux/property.h |  1 +
 5 files changed, 47 insertions(+)
author reviewer
#25 lore raw

PATCH v2 4/6 lib/vsprintf: Remove support for %pF and %pf in favour of %pS and %ps

In reply to Sakari Ailus

%pS and %ps are now the preferred conversion specifiers to print function %names. The functionality is equivalent; remove the old, deprecated %pF %and %pf support.

Depends-on: ("treewide: Switch printk users from %pf and %pF to %ps and
%pS, respectively")

---
 Documentation/core-api/printk-formats.rst | 10 ----------
 lib/vsprintf.c                            |  8 ++------
 scripts/checkpatch.pl                     |  1 -
 3 files changed, 2 insertions(+), 17 deletions(-)
Documentation/core-api/printk-formats.rst +0 -10
index c37ec7cd9c06..c90826a1ff17 100644
@@ -78,8 +78,6 @@ Symbols/Function Pointers
 
 	%pS	versatile_init+0x0/0x110
 	%ps	versatile_init
-	%pF	versatile_init+0x0/0x110
-	%pf	versatile_init
 	%pSR	versatile_init+0x9/0x110
 		(with __builtin_extract_return_addr() translation)
 	%pB	prev_fn_of_versatile_init+0x88/0x88
@@ -89,14 +87,6 @@ The ``S`` and ``s`` specifiers are used for printing a pointer in symbolic
 format. They result in the symbol name with (S) or without (s)
 offsets. If KALLSYMS are disabled then the symbol address is printed instead.
 
-Note, that the ``F`` and ``f`` specifiers are identical to ``S`` (``s``)
-and thus deprecated. We have ``F`` and ``f`` because on ia64, ppc64 and
-parisc64 function pointers are indirect and, in fact, are function
-descriptors, which require additional dereferencing before we can lookup
-the symbol. As of now, ``S`` and ``s`` perform dereferencing on those
-platforms (when needed), so ``F`` and ``f`` exist for compatibility
-reasons only.
-
 The ``B`` specifier results in the symbol name with offsets and should be
 used when printing stack backtraces. The specifier takes into
 consideration the effect of compiler optimisations which may occur
lib/vsprintf.c +2 -6
index 791b6fa36905..5f60b8d41277 100644
@@ -797,7 +797,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
 #ifdef CONFIG_KALLSYMS
 	if (*fmt == 'B')
 		sprint_backtrace(sym, value);
-	else if (*fmt != 'f' && *fmt != 's')
+	else if (*fmt != 's')
 		sprint_symbol(sym, value);
 	else
 		sprint_symbol_no_offset(sym, value);
@@ -1853,9 +1853,7 @@ char *device_node_string(char *buf, char *end, struct device_node *dn,
  *
  * - 'S' For symbolic direct pointers (or function descriptors) with offset
  * - 's' For symbolic direct pointers (or function descriptors) without offset
- * - 'F' Same as 'S'
- * - 'f' Same as 's'
- * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
+ * - '[Ss]R' as above with __builtin_extract_return_addr() translation
  * - 'B' For backtraced symbolic direct pointers with offset
  * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
  * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
@@ -1970,8 +1968,6 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 	}
 
 	switch (*fmt) {
-	case 'F':
-	case 'f':
 	case 'S':
 	case 's':
 		ptr = dereference_symbol_descriptor(ptr);
scripts/checkpatch.pl +0 -1
index 5b756278df13..b2e80259fb8c 100755
@@ -5994,7 +5994,6 @@ sub process {
 					my $ext_type = "Invalid";
 					my $use = "";
 					if ($bad_specifier =~ /p[Ff]/) {
-						$ext_type = "Deprecated";
 						$use = " - use %pS instead";
 						$use =~ s/pS/ps/ if ($bad_specifier =~ /pf/);
 					}
Signature · 1 line
2.11.0
author reviewer
#26 lore raw

PATCH v2 5/6 lib/vsprintf: Make use of fwnode API to obtain node names and separators

In reply to Sakari Ailus

Instead of implementing our own means of discovering parent nodes, node names or counting how many parents a node has, use the newly added functions in the fwnode API to obtain that information.

---
 lib/vsprintf.c | 37 +++++++++++++++----------------------
 1 file changed, 15 insertions(+), 22 deletions(-)
lib/vsprintf.c +15 -22
index 5f60b8d41277..91f2a3e4892e 100644
@@ -37,6 +37,7 @@
 #include <net/addrconf.h>
 #include <linux/siphash.h>
 #include <linux/compiler.h>
+#include <linux/property.h>
 #ifdef CONFIG_BLOCK
 #include <linux/blkdev.h>
 #endif
@@ -1720,32 +1721,23 @@ char *flags_string(char *buf, char *end, void *flags_ptr, const char *fmt)
 	return format_flags(buf, end, flags, names);
 }
 
-static const char *device_node_name_for_depth(const struct device_node *np, int depth)
-{
-	for ( ; np && depth; depth--)
-		np = np->parent;
-
-	return kbasename(np->full_name);
-}
-
 static noinline_for_stack
-char *device_node_gen_full_name(const struct device_node *np, char *buf, char *end)
+char *fwnode_gen_full_name(struct fwnode_handle *fwnode, char *buf, char *end)
 {
 	int depth;
-	const struct device_node *parent = np->parent;
 
-	/* special case for root node */
-	if (!parent)
-		return string(buf, end, "/", default_str_spec);
+	for (depth = fwnode_count_parents(fwnode); depth >= 0; depth--) {
+		struct fwnode_handle *__fwnode =
+			fwnode_get_nth_parent(fwnode, depth);
 
-	for (depth = 0; parent->parent; depth++)
-		parent = parent->parent;
-
-	for ( ; depth >= 0; depth--) {
-		buf = string(buf, end, "/", default_str_spec);
-		buf = string(buf, end, device_node_name_for_depth(np, depth),
+		buf = string(buf, end, fwnode_get_name_prefix(__fwnode),
+			     default_str_spec);
+		buf = string(buf, end, fwnode_get_name(__fwnode),
 			     default_str_spec);
+
+		fwnode_handle_put(__fwnode);
 	}
+
 	return buf;
 }
 
@@ -1790,10 +1782,11 @@ char *device_node_string(char *buf, char *end, struct device_node *dn,
 
 		switch (*fmt) {
 		case 'f':	/* full_name */
-			buf = device_node_gen_full_name(dn, buf, end);
+			buf = fwnode_gen_full_name(of_fwnode_handle(dn), buf,
+						   end);
 			break;
 		case 'n':	/* name */
-			p = kbasename(of_node_full_name(dn));
+			p = fwnode_get_name(of_fwnode_handle(dn));
 			precision = str_spec.precision;
 			str_spec.precision = strchrnul(p, '@') - p;
 			buf = string(buf, end, p, str_spec);
@@ -1803,7 +1796,7 @@ char *device_node_string(char *buf, char *end, struct device_node *dn,
 			buf = number(buf, end, (unsigned int)dn->phandle, num_spec);
 			break;
 		case 'P':	/* path-spec */
-			p = kbasename(of_node_full_name(dn));
+			p = fwnode_get_name(of_fwnode_handle(dn));
 			if (!p[1])
 				p = "/";
 			buf = string(buf, end, p, str_spec);
Signature · 1 line
2.11.0
author reviewer
#27 lore raw

PATCH v2 6/6 lib/vsprintf: Add %pfw conversion specifier for printing fwnode names

In reply to Sakari Ailus

Add support for %pfw conversion specifier (with "f" and "P" modifiers) to support printing full path of the node, including its name ("f") and only the node's name ("P") in the printk family of functions. The two flags have equivalent functionality to existing %pOF with the same two modifiers ("f" and "P") on OF based systems. The ability to do the same on ACPI based systems is added by this patch.

On ACPI based systems the resulting strings look like

	\[email protected]@0

where the nodes are separated by a dot (".") and the first three are ACPI device nodes and the latter two ACPI data nodes.

---
 Documentation/core-api/printk-formats.rst | 24 +++++++++++++
 lib/vsprintf.c                            | 56 +++++++++++++++++++++++++++++++
 scripts/checkpatch.pl                     |  3 +-
 3 files changed, 82 insertions(+), 1 deletion(-)
Documentation/core-api/printk-formats.rst +24 -0
index c90826a1ff17..209625e0c61d 100644
@@ -410,6 +410,30 @@ Examples::
 
 Passed by reference.
 
+Fwnode handles
+--------------
+
+::
+
+	%pfw[fP]
+
+For printing information on fwnode handles. The default is to print the full
+node name, including the path. The modifiers are functionally equivalent to
+%pOF above.
+
+	- f - full name of the node, including the path
+	- P - the name of the node including an address (if there is one)
+
+Examples (ACPI):
+
+	%pfwf	\[email protected]@0	- Full node name
+	%pfwP	endpoint@0				- Node name
+
+Examples (OF):
+
+	%pfwf	/ocp@68000000/i2c@48072000/camera@10/port/endpoint - Full name
+	%pfwP	endpoint				- Node name
+
 Time and date (struct rtc_time)
 -------------------------------
 
lib/vsprintf.c +56 -0

74 lines not on this page · raw message

scripts/checkpatch.pl +2 -1
index b2e80259fb8c..031db629e309 100755
@@ -5977,7 +5977,8 @@ sub process {
 				while ($fmt =~ /(\%[\*\d\.]*p(\w))/g) {
 					$specifier = $1;
 					$extension = $2;
-					if ($extension !~ /[SsBKRraEhMmIiUDdgVCbGNOx]/) {
+					if ($extension !~ /[SsBKRraEhMmIiUDdgVCbGNOxf]/ ||
+					    $extension =~ /f[^w]/) {
 						$bad_specifier = $specifier;
 						last;
 					}
Signature · 1 line
2.11.0
#28 lore raw

Re: [PATCH v2 6/6] lib/vsprintf: Add %pfw conversion specifier for printing fwnode names

Quoted 36 lines · Sakari Ailus

Add support for %pfw conversion specifier (with "f" and "P" modifiers) to support printing full path of the node, including its name ("f") and only the node's name ("P") in the printk family of functions. The two flags have equivalent functionality to existing %pOF with the same two modifiers ("f" and "P") on OF based systems. The ability to do the same on ACPI based systems is added by this patch.

lib/vsprintf.c +28 -0
+static noinline_for_stack
+char *fwnode_string(char *buf, char *end, struct fwnode_handle *fwnode,
+		    struct printf_spec spec, const char *fmt)
+{
+	const char * const modifiers = "fP";
+	struct printf_spec str_spec = spec;
+	char *buf_start = buf;
+	bool pass;
+
+	str_spec.field_width = -1;
+
+	if ((unsigned long)fwnode < PAGE_SIZE)
+		return string(buf, end, "(null)", spec);
+
+	/* simple case without anything any more format specifiers */
+	fmt++;
+	if (fmt[0] == '\0' || strcspn(fmt, modifiers) > 0)
+		fmt = "f";
+
+	for (pass = false; strspn(fmt, modifiers); fmt++, pass = true) {
+		if (pass) {
+			if (buf < end)
+				*buf = ':';
+			buf++;
+		}
+
+		switch (*fmt) {
+		case 'f':	/* full_name */

lib/vsprintf.c char *device_node_string(char *buf, char *end, struct device_node *dn, · line 1874

Quoted 10 lines
lib/vsprintf.c +10 -0
+			buf = fwnode_gen_full_name(fwnode, buf, end);
+			break;
+		case 'P':	/* name */
+			buf = string(buf, end, fwnode_get_name(fwnode),
+				     str_spec);
+			break;
+		default:
+			break;
+		}
+	}

This seems awfully complicated. Why would anyone ever pass more than one of 'f' and 'P'? Why not just

switch(*fmt) {
case 'P':
...
case 'f':
default:
...
}

which avoids the loop and the strcspn. Or, drop the default: case and don't have logic at all for falling back to 'f' if neither is present.

Quoted 18 lines
lib/vsprintf.c +7 -0
+	return widen_string(buf, buf - buf_start, end, spec);
+}
+
 /*
  * Show a '%p' thing.  A kernel extension is that the '%p' is followed
  * by an extra set of alphanumeric characters that are extended format
@@ -1936,6 +1978,10 @@ char *device_node_string(char *buf, char *end, struct device_node *dn,
  *                  F device node flags
  *                  c major compatible string
  *                  C full compatible string
+ * - 'fw[fP]'	For a firmware node (struct fwnode_handle) pointer
+ *		Without an option prints the full name of the node
+ *		f full name
+ *		P node name, including a possible unit address
  * - 'x' For printing the address. Equivalent to "%lx".
  *
  * ** When making changes please also update:

lib/vsprintf.c char *pointer(const char *fmt, char *buf, char *end, void *ptr, · line 2112

Quoted 7 lines
lib/vsprintf.c +4 -0
@@ -2060,6 +2106,16 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 			return device_node_string(buf, end, ptr, spec, fmt + 1);
 		}
 		break;
+	case 'f':
+		switch (fmt[1]) {
+		case 'w':
+			return fwnode_string(buf, end, ptr, spec, fmt + 1);

Why not pass fmt+2; we know that fmt+1 points at a 'w'. Just to avoid doing the fmt++ inside fwnode_string().

Rasmus

#29 lore raw

Re: [PATCH v2 6/6] lib/vsprintf: Add %pfw conversion specifier for printing fwnode names

Quoted 39 lines · Rasmus Villemoes
Quoted 16 lines · Sakari Ailus

Add support for %pfw conversion specifier (with "f" and "P" modifiers) to support printing full path of the node, including its name ("f") and only the node's name ("P") in the printk family of functions. The two flags have equivalent functionality to existing %pOF with the same two modifiers ("f" and "P") on OF based systems. The ability to do the same on ACPI based systems is added by this patch.

lib/vsprintf.c +9 -0
+	for (pass = false; strspn(fmt, modifiers); fmt++, pass = true) {
+		if (pass) {
+			if (buf < end)
+				*buf = ':';
+			buf++;
+		}
+
+		switch (*fmt) {
+		case 'f':	/* full_name */

lib/vsprintf.c char *device_node_string(char *buf, char *end, struct device_node *dn, · line 1874

Quoted 10 lines
lib/vsprintf.c +10 -0
+			buf = fwnode_gen_full_name(fwnode, buf, end);
+			break;
+		case 'P':	/* name */
+			buf = string(buf, end, fwnode_get_name(fwnode),
+				     str_spec);
+			break;
+		default:
+			break;
+		}
+	}

This seems awfully complicated. Why would anyone ever pass more than one of 'f' and 'P'? Why not just

switch(*fmt) {
case 'P':

   ...
case 'f':
default:
   ...
}
Quoted 5 lines

which avoids the loop and the strcspn. Or, drop the default: case and don't have logic at all for falling back to 'f' if neither is present.

lib/vsprintf.c char *device_node_string(char *buf, char *end, struct device_node *dn, · line 1877

Quoted 2 lines
lib/vsprintf.c +2 -0
+	return widen_string(buf, buf - buf_start, end, spec);
+}

My point as well (as per sent comments against previous version). Sakari, can you add test cases at the same time?

Quoted 6 lines

lib/vsprintf.c char *pointer(const char *fmt, char *buf, char *end, void *ptr, · line 2112

Quoted 3 lines
lib/vsprintf.c +1 -0
 			return device_node_string(buf, end, ptr, spec, fmt + 1);
 
+			return fwnode_string(buf, end, ptr, spec, fmt + 1);

Why not pass fmt+2; we know that fmt+1 points at a 'w'. Just to avoid doing the fmt++ inside fwnode_string().

I guess in order to be consistent with existing %pOF case. But wouldn't be better to fix %pOF for that sooner or later?

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

Re: [PATCH v2 6/6] lib/vsprintf: Add %pfw conversion specifier for printing fwnode names

Hi Andy, Rasmus,

Thanks for the comments.

Quoted 40 lines · Andy Shevchenko
Quoted 39 lines · Rasmus Villemoes
Quoted 16 lines · Sakari Ailus

Add support for %pfw conversion specifier (with "f" and "P" modifiers) to support printing full path of the node, including its name ("f") and only the node's name ("P") in the printk family of functions. The two flags have equivalent functionality to existing %pOF with the same two modifiers ("f" and "P") on OF based systems. The ability to do the same on ACPI based systems is added by this patch.

lib/vsprintf.c +9 -0
+	for (pass = false; strspn(fmt, modifiers); fmt++, pass = true) {
+		if (pass) {
+			if (buf < end)
+				*buf = ':';
+			buf++;
+		}
+
+		switch (*fmt) {
+		case 'f':	/* full_name */

lib/vsprintf.c char *device_node_string(char *buf, char *end, struct device_node *dn, · line 1874

Quoted 10 lines
lib/vsprintf.c +10 -0
+			buf = fwnode_gen_full_name(fwnode, buf, end);
+			break;
+		case 'P':	/* name */
+			buf = string(buf, end, fwnode_get_name(fwnode),
+				     str_spec);
+			break;
+		default:
+			break;
+		}
+	}

This seems awfully complicated. Why would anyone ever pass more than one of 'f' and 'P'? Why not just

switch(*fmt) {
case 'P':

   ...
case 'f':
default:
   ...
}
Quoted 2 lines
Quoted 2 lines

which avoids the loop and the strcspn. Or, drop the default: case and don't have logic at all for falling back to 'f' if neither is present.

There are just two modifiers supported now ('f' and 'P') but should more be needed in the future, we'd need the loop again. This is basically modelled after %pOF implementation.

I can simplify this if you both still think that's the way to go, and make the implementations diverge.

Quoted 9 lines
Quoted 3 lines

lib/vsprintf.c char *device_node_string(char *buf, char *end, struct device_node *dn, · line 1877

Quoted 3 lines
lib/vsprintf.c +2 -0
+	return widen_string(buf, buf - buf_start, end, spec);
+}

My point as well (as per sent comments against previous version). Sakari, can you add test cases at the same time?

Quoted 1 line
Quoted 1 line

return device_node_string(buf, end, ptr, spec, fmt + 1);

Quoted 7 lines
Quoted 4 lines

lib/vsprintf.c char *pointer(const char *fmt, char *buf, char *end, void *ptr, · line 2112

Quoted 1 line
lib/vsprintf.c +1 -0
+			return fwnode_string(buf, end, ptr, spec, fmt + 1);

Why not pass fmt+2; we know that fmt+1 points at a 'w'. Just to avoid doing the fmt++ inside fwnode_string().

I guess in order to be consistent with existing %pOF case. But wouldn't be better to fix %pOF for that sooner or later?

Agreed.

Signature · 2 lines
Sakari Ailus
[email protected]
maintainer
#31 lore raw

Re: [PATCH v2 6/6] lib/vsprintf: Add %pfw conversion specifier for printing fwnode names

In reply to Andy Shevchenko
Quoted 51 lines · Andy Shevchenko
Quoted 39 lines · Rasmus Villemoes
Quoted 16 lines · Sakari Ailus

Add support for %pfw conversion specifier (with "f" and "P" modifiers) to support printing full path of the node, including its name ("f") and only the node's name ("P") in the printk family of functions. The two flags have equivalent functionality to existing %pOF with the same two modifiers ("f" and "P") on OF based systems. The ability to do the same on ACPI based systems is added by this patch.

lib/vsprintf.c +9 -0
+	for (pass = false; strspn(fmt, modifiers); fmt++, pass = true) {
+		if (pass) {
+			if (buf < end)
+				*buf = ':';
+			buf++;
+		}
+
+		switch (*fmt) {
+		case 'f':	/* full_name */

lib/vsprintf.c char *device_node_string(char *buf, char *end, struct device_node *dn, · line 1874

Quoted 10 lines
lib/vsprintf.c +10 -0
+			buf = fwnode_gen_full_name(fwnode, buf, end);
+			break;
+		case 'P':	/* name */
+			buf = string(buf, end, fwnode_get_name(fwnode),
+				     str_spec);
+			break;
+		default:
+			break;
+		}
+	}

This seems awfully complicated. Why would anyone ever pass more than one of 'f' and 'P'? Why not just

switch(*fmt) {
case 'P':

   ...
case 'f':
default:
   ...
}
Quoted 5 lines

which avoids the loop and the strcspn. Or, drop the default: case and don't have logic at all for falling back to 'f' if neither is present.

lib/vsprintf.c char *device_node_string(char *buf, char *end, struct device_node *dn, · line 1877

Quoted 2 lines
lib/vsprintf.c +2 -0
+	return widen_string(buf, buf - buf_start, end, spec);
+}

My point as well (as per sent comments against previous version). Sakari, can you add test cases at the same time?

Quoted 1 line
Quoted 1 line

return device_node_string(buf, end, ptr, spec, fmt + 1);

Quoted 7 lines
Quoted 4 lines

lib/vsprintf.c char *pointer(const char *fmt, char *buf, char *end, void *ptr, · line 2112

Quoted 1 line
lib/vsprintf.c +1 -0
+			return fwnode_string(buf, end, ptr, spec, fmt + 1);

Why not pass fmt+2; we know that fmt+1 points at a 'w'. Just to avoid doing the fmt++ inside fwnode_string().

I guess in order to be consistent with existing %pOF case. But wouldn't be better to fix %pOF for that sooner or later?

Good question. Are there any %pOF users that would want to use the for cycle and printk more values by single %pOF? Would the output be human readable without any delimiters or words around?

Best Regards,
Petr

author reviewer
#32 lore raw

Re: [PATCH v2 6/6] lib/vsprintf: Add %pfw conversion specifier for printing fwnode names

Hi Petr,

Quoted 57 lines · Petr Mladek
Quoted 56 lines · Andy Shevchenko
Quoted 39 lines · Rasmus Villemoes
Quoted 16 lines · Sakari Ailus

Add support for %pfw conversion specifier (with "f" and "P" modifiers) to support printing full path of the node, including its name ("f") and only the node's name ("P") in the printk family of functions. The two flags have equivalent functionality to existing %pOF with the same two modifiers ("f" and "P") on OF based systems. The ability to do the same on ACPI based systems is added by this patch.

lib/vsprintf.c +9 -0
+	for (pass = false; strspn(fmt, modifiers); fmt++, pass = true) {
+		if (pass) {
+			if (buf < end)
+				*buf = ':';
+			buf++;
+		}
+
+		switch (*fmt) {
+		case 'f':	/* full_name */

lib/vsprintf.c char *device_node_string(char *buf, char *end, struct device_node *dn, · line 1874

Quoted 10 lines
lib/vsprintf.c +10 -0
+			buf = fwnode_gen_full_name(fwnode, buf, end);
+			break;
+		case 'P':	/* name */
+			buf = string(buf, end, fwnode_get_name(fwnode),
+				     str_spec);
+			break;
+		default:
+			break;
+		}
+	}

This seems awfully complicated. Why would anyone ever pass more than one of 'f' and 'P'? Why not just

switch(*fmt) {
case 'P':

   ...
case 'f':
default:
   ...
}
Quoted 5 lines

which avoids the loop and the strcspn. Or, drop the default: case and don't have logic at all for falling back to 'f' if neither is present.

lib/vsprintf.c char *device_node_string(char *buf, char *end, struct device_node *dn, · line 1877

Quoted 2 lines
lib/vsprintf.c +2 -0
+	return widen_string(buf, buf - buf_start, end, spec);
+}

My point as well (as per sent comments against previous version). Sakari, can you add test cases at the same time?

Quoted 6 lines

lib/vsprintf.c char *pointer(const char *fmt, char *buf, char *end, void *ptr, · line 2112

Quoted 3 lines
lib/vsprintf.c +1 -0
 			return device_node_string(buf, end, ptr, spec, fmt + 1);
 
+			return fwnode_string(buf, end, ptr, spec, fmt + 1);

Why not pass fmt+2; we know that fmt+1 points at a 'w'. Just to avoid doing the fmt++ inside fwnode_string().

Quoted 6 lines
Quoted 2 lines

I guess in order to be consistent with existing %pOF case. But wouldn't be better to fix %pOF for that sooner or later?

Good question. Are there any %pOF users that would want to use the for cycle and printk more values by single %pOF? Would the output be human readable without any delimiters or words around?

The delimiter is ':'. What comes to users, quick grepping tells the only users are actually the unit tests, and this is also present in the documentation.

Based on that I think we can safely omit that on %pfw actually. I thought it was actually used somewhere.

Signature · 4 lines
Kind regards,

Sakari Ailus
[email protected]
maintainer
#33 lore raw

Re: [PATCH v2 6/6] lib/vsprintf: Add %pfw conversion specifier for printing fwnode names

In reply to Sakari Ailus
Quoted 6 lines · Sakari Ailus

Add support for %pfw conversion specifier (with "f" and "P" modifiers) to support printing full path of the node, including its name ("f") and only the node's name ("P") in the printk family of functions. The two flags have equivalent functionality to existing %pOF with the same two modifiers ("f" and "P") on OF based systems. The ability to do the same on ACPI based systems is added by this patch.

[]

scripts/checkpatch.pl

Quoted 1 line
scripts/checkpatch.pl +0 -0

[]

scripts/checkpatch.pl sub process { · line 5984

Quoted 10 lines
scripts/checkpatch.pl +2 -1
@@ -5977,7 +5977,8 @@ sub process {
 				while ($fmt =~ /(\%[\*\d\.]*p(\w))/g) {
 					$specifier = $1;
 					$extension = $2;
-					if ($extension !~ /[SsBKRraEhMmIiUDdgVCbGNOx]/) {
+					if ($extension !~ /[SsBKRraEhMmIiUDdgVCbGNOxf]/ ||
+					    $extension =~ /f[^w]/) {
 						$bad_specifier = $specifier;
 						last;
 					}

You also need to remove the bit about using %pF or %pf below this

					if ($bad_specifier =~ /p[Ff]/) {
						$ext_type = "Deprecated";
						$use = " - use %pS instead";
						$use =~ s/pS/ps/ if ($bad_specifier =~ /pf/);
					}
author reviewer
#34 lore raw

Re: [PATCH v2 6/6] lib/vsprintf: Add %pfw conversion specifier for printing fwnode names

Hi Joe,

Thanks for the review.

Quoted 23 lines · Joe Perches
Quoted 6 lines · Sakari Ailus

Add support for %pfw conversion specifier (with "f" and "P" modifiers) to support printing full path of the node, including its name ("f") and only the node's name ("P") in the printk family of functions. The two flags have equivalent functionality to existing %pOF with the same two modifiers ("f" and "P") on OF based systems. The ability to do the same on ACPI based systems is added by this patch.

[]

scripts/checkpatch.pl

Quoted 1 line
scripts/checkpatch.pl +0 -0

[]

scripts/checkpatch.pl sub process { · line 5984

Quoted 10 lines
scripts/checkpatch.pl +2 -1
@@ -5977,7 +5977,8 @@ sub process {
 				while ($fmt =~ /(\%[\*\d\.]*p(\w))/g) {
 					$specifier = $1;
 					$extension = $2;
-					if ($extension !~ /[SsBKRraEhMmIiUDdgVCbGNOx]/) {
+					if ($extension !~ /[SsBKRraEhMmIiUDdgVCbGNOxf]/ ||
+					    $extension =~ /f[^w]/) {
 						$bad_specifier = $specifier;
 						last;
 					}

You also need to remove the bit about using %pF or %pf below this

Quoted 5 lines
					if ($bad_specifier =~ /p[Ff]/) {
						$ext_type = "Deprecated";
						$use = " - use %pS instead";
						$use =~ s/pS/ps/ if ($bad_specifier =~ /pf/);
					}

I actually intended to leave this --- it points to anyone accidentally trying to use %pf to what it needs to be replaced with. But the Deprecated should be replaced with Invalid (i.e. remove that assignment).

How about that?

Signature · 4 lines
Regards,

Sakari Ailus
[email protected]
author reviewer
#35 lore raw

Re: [PATCH v2 6/6] lib/vsprintf: Add %pfw conversion specifier for printing fwnode names

Quoted 3 lines · Sakari Ailus

I actually intended to leave this --- it points to anyone accidentally trying to use %pf to what it needs to be replaced with. But the Deprecated should be replaced with Invalid (i.e. remove that assignment).

This is actually already a part of an earlier patch, "[PATCH v2 4/6] lib/vsprintf: Remove support for %pF and %pf in favour of %pS and %ps".

Signature · 2 lines
Sakari Ailus
[email protected]