Skip to contentSkip to conversation

Preparation for further fwnode property cleanup

PATCH Superseded Sakari Ailus 2 participants 4 messages May 18, 2017

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 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) 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.

Sakari Ailus (2):
of: Move OF property and graph API from base.c to property.c
of: Make of_fwnode_handle() safer

since v3:

- Rebase the first patch (no conflicts),

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

 drivers/of/Makefile   |   2 +-
 drivers/of/base.c     | 733 ------------------------------------------------
 drivers/of/property.c | 763 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of.h    |   8 +-
 4 files changed, 771 insertions(+), 735 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 v4 1/2 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
#2 lore raw

PATCH v4 2/2 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
#3 lore raw

PATCH RESEND v4 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.

---
This was actually in another set, but fits better here.

(Now with correct In-Reply-To header.)

 include/linux/of.h | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
include/linux/of.h +10 -6
index a7ccf34..03dbc94 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)						\
 	({								\
Signature · 1 line
2.7.4