Skip to contentSkip to conversation

Preparation for further fwnode property cleanup

PATCH New Sakari Ailus 5 participants 11 messages May 22, 2017 – May 24, 2017 1 message not in the archive

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

v5 cover Preparation for further fwnode property cleanup

Hi Rob, Frank, others,

Here's the 4th version of what used to be a single patch to prepare for fwnode property cleanup.

Beyond this, I have a couple of other patchsets I'll post in the near future:

- fwnode property cleanup (for linux-pm) which moves the property API implementation to FW specific locations; depends on these patches,

- V4L2 fwnode patches (for media_tree, no unmerged dependencies, pull request sent) and

- fwnode const patchset which allows making the fwnode argument for the property API functions const. It depends on both of the previous sets. Might be for linux-pm.

since v4:

- Add patch "of: Support const and non-const use for to_of_node()" to the set.

- Make nop is_of_node() and to_of_node() const-correct if OF is disabled. (since v4.1)

since v3:

- Rebase the first patch (no conflicts),

- Add another patch for to make of_fwnode_handle() handle NULL argument gracefully.

Sakari Ailus (3):
of: Move OF property and graph API from base.c to property.c
of: Make of_fwnode_handle() safer
of: Support const and non-const use for to_of_node()

 drivers/of/Makefile   |   2 +-
 drivers/of/base.c     | 733 ------------------------------------------------
 drivers/of/property.c | 763 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of.h    |  30 +-
 4 files changed, 784 insertions(+), 744 deletions(-)
 create mode 100644 drivers/of/property.c
Signature · 6 lines
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw

PATCH v5 1/3 of: Move OF property and graph API from base.c to property.c

base.c contains both core OF functions and increasingly other functionality such as accessing properties and graphs, including convenience functions. In the near future this would also include OF specific implementation of the fwnode property and graph APIs.

Create driver/of/property.c to contain procedures for accessing and interpreting device tree properties. The procedures are moved from drivers/of/base.c, with no changes other than copying only the includes required by the moved procedures.

---
 drivers/of/Makefile   |   2 +-
 drivers/of/base.c     | 733 ------------------------------------------------
 drivers/of/property.c | 763 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 764 insertions(+), 734 deletions(-)
 create mode 100644 drivers/of/property.c
drivers/of/Makefile +1 -1
index d7efd9d..97dc01c 100644
@@ -1,4 +1,4 @@
-obj-y = base.o device.o platform.o
+obj-y = base.o device.o platform.o property.o
 obj-$(CONFIG_OF_DYNAMIC) += dynamic.o
 obj-$(CONFIG_OF_FLATTREE) += fdt.o
 obj-$(CONFIG_OF_EARLY_FLATTREE) += fdt_address.o
drivers/of/base.c +0 -733

748 lines not on this page · raw message

drivers/of/property.c new file +763 -0

763 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#2 lore raw

Re: [PATCH v5 1/3] of: Move OF property and graph API from base.c to property.c

Quoted 10 lines · Sakari Ailus

base.c contains both core OF functions and increasingly other functionality such as accessing properties and graphs, including convenience functions. In the near future this would also include OF specific implementation of the fwnode property and graph APIs.

Create driver/of/property.c to contain procedures for accessing and interpreting device tree properties. The procedures are moved from drivers/of/base.c, with no changes other than copying only the includes required by the moved procedures.

Quoted 5 lines
---
 drivers/of/Makefile   |   2 +-
 drivers/of/base.c     | 733 ------------------------------------------------
 drivers/of/property.c | 763 ++++++++++++++++++++++++++++++++++++++++++++++++++

Please put graph functions in graph.c unless there is some reason not to.

[...]

Quoted 21 lines
drivers/of/property.c new file +15 -0
new file mode 100644
index 0000000..e5d3e1f
@@ -0,0 +1,763 @@
+/*
+ * drivers/of/property.c - Procedures for accessing and interpreting
+ *                        Devicetree properties and graphs.
+ *
+ * Initially created by copying procedures from drivers/of/base.c. This
+ * file contains the OF property as well as the OF graph interface
+ * functions.
+ *
+ * Paul Mackerras      August 1996.
+ * Copyright (C) 1996-2005 Paul Mackerras.
+ *
+ *  Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
+ *    {engebret|bergner}@us.ibm.com
+ *
+ *  Adapted for sparc and sparc64 by David S. Miller [email protected]

drivers/of/property.c line 25

Quoted 10 lines
drivers/of/property.c new file +10 -0
+ *
+ *  Reconsolidated from arch/x/kernel/prom.c by Stephen Rothwell and
+ *  Grant Likely.
+ *
+ *      This program is free software; you can redistribute it and/or
+ *      modify it under the terms of the GNU General Public License
+ *      as published by the Free Software Foundation; either version
+ *      2 of the License, or (at your option) any later version.
+ */
+

Need a pr_fmt here.

drivers/of/property.c line 31

Quoted 6 lines
drivers/of/property.c new file +6 -0
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_graph.h>
+#include <linux/string.h>
+
+#include "of_private.h"

A blank line needed here.

Quoted 12 lines
drivers/of/property.c new file +12 -0
+/**
+ * of_property_count_elems_of_size - Count the number of elements in a property
+ *
+ * @np:                device node from which the property value is to be read.
+ * @propname:  name of the property to be searched.
+ * @elem_size: size of the individual element
+ *
+ * Search for a property in a device node and count the number of elements of
+ * size elem_size in it. Returns number of elements on sucess, -EINVAL if the
+ * property does not exist or its length does not match a multiple of elem_size
+ * and -ENODATA if the property does not have a value.
+ */
#3 lore raw

Re: [PATCH v5 1/3] of: Move OF property and graph API from base.c to property.c

Hi Rob,

Thanks for the review!

Quoted 12 lines · Rob Herring
Quoted 10 lines · Sakari Ailus

base.c contains both core OF functions and increasingly other functionality such as accessing properties and graphs, including convenience functions. In the near future this would also include OF specific implementation of the fwnode property and graph APIs.

Create driver/of/property.c to contain procedures for accessing and interpreting device tree properties. The procedures are moved from drivers/of/base.c, with no changes other than copying only the includes required by the moved procedures.

Quoted 7 lines
Quoted 5 lines
---
 drivers/of/Makefile   |   2 +-
 drivers/of/base.c     | 733 ------------------------------------------------
 drivers/of/property.c | 763 ++++++++++++++++++++++++++++++++++++++++++++++++++

Please put graph functions in graph.c unless there is some reason not to.

There will be a single fwnode ops struct which will contain both property and graph API primitives. The functions implementing the operations will be private, albeit the corresponding OF functions they will use are global.

If I split current properties.c, which of these should the fwnode ops struct and the function callbacks be put? The patch is here (and the previous one; both were submitted earlier today):

<URL:https://git.linuxtv.org/sailus/media_tree.git/commit/?h=acpi-graph-cleaned&id=b8cb45afa52a892d9ec62530b5f882c56533b30d>

Quoted 28 lines

[...]

Quoted 25 lines
drivers/of/property.c new file +19 -0
new file mode 100644
index 0000000..e5d3e1f
@@ -0,0 +1,763 @@
+/*
+ * drivers/of/property.c - Procedures for accessing and interpreting
+ *                        Devicetree properties and graphs.
+ *
+ * Initially created by copying procedures from drivers/of/base.c. This
+ * file contains the OF property as well as the OF graph interface
+ * functions.
+ *
+ * Paul Mackerras      August 1996.
+ * Copyright (C) 1996-2005 Paul Mackerras.
+ *
+ *  Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
+ *    {engebret|bergner}@us.ibm.com
+ *
+ *  Adapted for sparc and sparc64 by David S. Miller [email protected]
+ *
+ *  Reconsolidated from arch/x/kernel/prom.c by Stephen Rothwell and
+ *  Grant Likely.
+ *
Quoted 8 lines

drivers/of/property.c line 25

Quoted 6 lines
drivers/of/property.c new file +6 -0
+ *      This program is free software; you can redistribute it and/or
+ *      modify it under the terms of the GNU General Public License
+ *      as published by the Free Software Foundation; either version
+ *      2 of the License, or (at your option) any later version.
+ */
+

Need a pr_fmt here.

Indeed. I'll address that in v6.

Quoted 9 lines

drivers/of/property.c line 31

Quoted 7 lines
drivers/of/property.c new file +6 -0
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_graph.h>
+#include <linux/string.h>
+
+#include "of_private.h"

A blank line needed here.

Oops!

Quoted 13 lines
Quoted 13 lines
drivers/of/property.c new file +12 -0
+/**
+ * of_property_count_elems_of_size - Count the number of elements in a property
+ *
+ * @np:                device node from which the property value is to be read.
+ * @propname:  name of the property to be searched.
+ * @elem_size: size of the individual element
+ *
+ * Search for a property in a device node and count the number of elements of
+ * size elem_size in it. Returns number of elements on sucess, -EINVAL if the
+ * property does not exist or its length does not match a multiple of elem_size
+ * and -ENODATA if the property does not have a value.
+ */
Signature · 4 lines
Kind regards,

Sakari Ailus
[email protected]
maintainer
#4 lore raw

Re: [PATCH v5 1/3] of: Move OF property and graph API from base.c to property.c

Quoted 25 lines · Sakari Ailus

Hi Rob,

Thanks for the review!

Quoted 12 lines · Rob Herring
Quoted 10 lines · Sakari Ailus

base.c contains both core OF functions and increasingly other functionality such as accessing properties and graphs, including convenience functions. In the near future this would also include OF specific implementation of the fwnode property and graph APIs.

Create driver/of/property.c to contain procedures for accessing and interpreting device tree properties. The procedures are moved from drivers/of/base.c, with no changes other than copying only the includes required by the moved procedures.

Quoted 7 lines
Quoted 5 lines
---
 drivers/of/Makefile   |   2 +-
 drivers/of/base.c     | 733 ------------------------------------------------
 drivers/of/property.c | 763 ++++++++++++++++++++++++++++++++++++++++++++++++++

Please put graph functions in graph.c unless there is some reason not to.

Quoted 8 lines

There will be a single fwnode ops struct which will contain both property and graph API primitives. The functions implementing the operations will be private, albeit the corresponding OF functions they will use are global.

If I split current properties.c, which of these should the fwnode ops struct and the function callbacks be put? The patch is here (and the previous one; both were submitted earlier today):

Okay, makes sense. The filename is a bit confusing, but I don't have a better suggestion.

Rob

#5 lore raw

PATCH 1/3 of: Move OF property and graph API from base.c to property.c

In reply to Sakari Ailus

base.c contains both core OF functions and increasingly other functionality such as accessing properties and graphs, including convenience functions. In the near future this would also include OF specific implementation of the fwnode property and graph APIs.

Create driver/of/property.c to contain procedures for accessing and interpreting device tree properties. The procedures are moved from drivers/of/base.c, with no changes other than copying only the includes required by the moved procedures.

---
since v5:

- Add "pr_fmt" macro missed when splitting base.c

- Add a missing newline

 drivers/of/Makefile   |   2 +-
 drivers/of/base.c     | 733 -----------------------------------------------
 drivers/of/property.c | 766 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 767 insertions(+), 734 deletions(-)
 create mode 100644 drivers/of/property.c
drivers/of/Makefile +1 -1
index d7efd9d..97dc01c 100644
@@ -1,4 +1,4 @@
-obj-y = base.o device.o platform.o
+obj-y = base.o device.o platform.o property.o
 obj-$(CONFIG_OF_DYNAMIC) += dynamic.o
 obj-$(CONFIG_OF_FLATTREE) += fdt.o
 obj-$(CONFIG_OF_EARLY_FLATTREE) += fdt_address.o
drivers/of/base.c +0 -733

748 lines not on this page · raw message

drivers/of/property.c new file +766 -0

766 lines not on this page · raw message

Signature · 1 line
2.7.4
#6 lore raw

PATCH v5 2/3 of: Make of_fwnode_handle() safer

In reply to Sakari Ailus

On the expense of a little bit more complexity in the of_fwnode_handle() macro, make the macro result in NULL in case its argument is NULL while still referencing it only once.

---
 include/linux/of.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
include/linux/of.h +7 -1
index 50fcdb5..a7ccf34 100644
@@ -159,7 +159,13 @@ static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
 		container_of(fwnode, struct device_node, fwnode) : NULL;
 }
 
-#define of_fwnode_handle(node) (&(node)->fwnode)
+#define of_fwnode_handle(node)						\
+	({								\
+		typeof(node) __of_fwnode_handle_node = node;		\
+									\
+		__of_fwnode_handle_node ?				\
+			&__of_fwnode_handle_node->fwnode : NULL;	\
+	})
 
 static inline bool of_have_populated_dt(void)
 {
Signature · 1 line
2.7.4
Reviewed-by on v5 2/3
#7 lore raw

Re: [PATCH v5 2/3] of: Make of_fwnode_handle() safer

Hi Sakari,

Thankyou for the patch,

Quoted 14 lines · Sakari Ailus

On the expense of a little bit more complexity in the of_fwnode_handle() macro, make the macro result in NULL in case its argument is NULL while still referencing it only once.

---
 include/linux/of.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
include/linux/of.h +0 -0
index 50fcdb5..a7ccf34 100644

include/linux/of.h static inline struct device_node *to_of_node(struct fwnode_handle *fwnode) · line 164

Quoted 7 lines
include/linux/of.h +3 -1
@@ -159,7 +159,13 @@ static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
 		container_of(fwnode, struct device_node, fwnode) : NULL;
 }
 
-#define of_fwnode_handle(node) (&(node)->fwnode)
+#define of_fwnode_handle(node)						\
+	({								\
+		typeof(node) __of_fwnode_handle_node = node;		\

Should this be '/= node/= (node)/' ?

include/linux/of.h static inline struct device_node *to_of_node(struct fwnode_handle *fwnode) · line 171

Quoted 8 lines
include/linux/of.h +4 -0
+									\
+		__of_fwnode_handle_node ?				\
+			&__of_fwnode_handle_node->fwnode : NULL;	\
+	})
 
 static inline bool of_have_populated_dt(void)
 {

Otherwise,

--
Regards

Kieran

#8 lore raw

PATCH v5 3/3 of: Support const and non-const use for to_of_node()

In reply to Sakari Ailus

Turn to_of_node() into a macro in order to support both const and non-const use. Additionally make the fwnode argument to is_of_node() const as well.

---
 include/linux/of.h | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
include/linux/of.h +12 -8
index a7ccf34..52ffebc 100644
@@ -148,16 +148,20 @@ extern raw_spinlock_t devtree_lock;
 #ifdef CONFIG_OF
 void of_core_init(void);
 
-static inline bool is_of_node(struct fwnode_handle *fwnode)
+static inline bool is_of_node(const struct fwnode_handle *fwnode)
 {
 	return !IS_ERR_OR_NULL(fwnode) && fwnode->type == FWNODE_OF;
 }
 
-static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
-{
-	return is_of_node(fwnode) ?
-		container_of(fwnode, struct device_node, fwnode) : NULL;
-}
+#define to_of_node(__fwnode)						\
+	({								\
+		typeof(__fwnode) __to_of_node_fwnode = __fwnode;	\
+									\
+		is_of_node(__to_of_node_fwnode) ?			\
+			container_of(__to_of_node_fwnode,		\
+				     struct device_node, fwnode) :	\
+			NULL;						\
+	})
 
 #define of_fwnode_handle(node)						\
 	({								\
@@ -539,12 +543,12 @@ static inline void of_core_init(void)
 {
 }
 
-static inline bool is_of_node(struct fwnode_handle *fwnode)
+static inline bool is_of_node(const struct fwnode_handle *fwnode)
 {
 	return false;
 }
 
-static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
+static inline const struct device_node *to_of_node(struct fwnode_handle *fwnode)
 {
 	return NULL;
 }
Signature · 1 line
2.7.4
#9 lore raw

PATCH 3/3 of: Support const and non-const use for to_of_node()

Turn to_of_node() into a macro in order to support both const and non-const use. Additionally make the fwnode argument to is_of_node() const as well.

---
since v5:

- Put const to the argument, not the type returned.

 include/linux/of.h | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
include/linux/of.h +12 -8
index a7ccf34..aaf9c18 100644
@@ -148,16 +148,20 @@ extern raw_spinlock_t devtree_lock;
 #ifdef CONFIG_OF
 void of_core_init(void);
 
-static inline bool is_of_node(struct fwnode_handle *fwnode)
+static inline bool is_of_node(const struct fwnode_handle *fwnode)
 {
 	return !IS_ERR_OR_NULL(fwnode) && fwnode->type == FWNODE_OF;
 }
 
-static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
-{
-	return is_of_node(fwnode) ?
-		container_of(fwnode, struct device_node, fwnode) : NULL;
-}
+#define to_of_node(__fwnode)						\
+	({								\
+		typeof(__fwnode) __to_of_node_fwnode = __fwnode;	\
+									\
+		is_of_node(__to_of_node_fwnode) ?			\
+			container_of(__to_of_node_fwnode,		\
+				     struct device_node, fwnode) :	\
+			NULL;						\
+	})
 
 #define of_fwnode_handle(node)						\
 	({								\
@@ -539,12 +543,12 @@ static inline void of_core_init(void)
 {
 }
 
-static inline bool is_of_node(struct fwnode_handle *fwnode)
+static inline bool is_of_node(const struct fwnode_handle *fwnode)
 {
 	return false;
 }
 
-static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
+static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode)
 {
 	return NULL;
 }
Signature · 1 line
2.7.4

A message that is not in the archive (sent off-list or not yet received): 1495521543-31570-1-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/[email protected]

Reviewed-by
#11 lore raw

Re: [PATCH v5.1 3/3] of: Support const and non-const use for to_of_node()

Hi Sakari,

Thankyou for the patch,

Quoted 25 lines · Sakari Ailus

Turn to_of_node() into a macro in order to support both const and non-const use. Additionally make the fwnode argument to is_of_node() const as well.

---
since v5:

- Put const to the argument, not the type returned.

 include/linux/of.h | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
include/linux/of.h +1 -1
index a7ccf34..aaf9c18 100644
@@ -148,16 +148,20 @@ extern raw_spinlock_t devtree_lock;
 #ifdef CONFIG_OF
 void of_core_init(void);
 
-static inline bool is_of_node(struct fwnode_handle *fwnode)
+static inline bool is_of_node(const struct fwnode_handle *fwnode)
 {
 	return !IS_ERR_OR_NULL(fwnode) && fwnode->type == FWNODE_OF;

include/linux/of.h extern raw_spinlock_t devtree_lock; · line 158

Quoted 10 lines
include/linux/of.h +3 -5
 }
 
-static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
-{
-	return is_of_node(fwnode) ?
-		container_of(fwnode, struct device_node, fwnode) : NULL;
-}
+#define to_of_node(__fwnode)						\
+	({								\
+		typeof(__fwnode) __to_of_node_fwnode = __fwnode;	\

Again here, I think it might need /= __fwnode/= (__fwnode)/

Other than that - this looks good to me.

Quoted 15 lines
include/linux/of.h +6 -1
+									\
+		is_of_node(__to_of_node_fwnode) ?			\
+			container_of(__to_of_node_fwnode,		\
+				     struct device_node, fwnode) :	\
+			NULL;						\
+	})
 
 #define of_fwnode_handle(node)						\
 	({								\
@@ -539,12 +543,12 @@ static inline void of_core_init(void)
 {
 }
 
-static inline bool is_of_node(struct fwnode_handle *fwnode)

include/linux/of.h static inline void of_core_init(void) · line 554

Quoted 10 lines
include/linux/of.h +2 -1
+static inline bool is_of_node(const struct fwnode_handle *fwnode)
 {
 	return false;
 }
 
-static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
+static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode)
 {
 	return NULL;
 }

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html