Skip to contentSkip to conversation

device: Add dev_of_node() accessor

PATCH In review Benjamin Herrenschmidt 2 participants 2 messages Feb 16, 2015 – Feb 18, 2015 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 device: Add dev_of_node() accessor

Suggested by Arnd Bergmann, this gives a practical accessor for the of_node field of struct device while instructing the compiler that it will be NULL if CONFIG_OF is not set.

---

This is what we discussed back in November and I had forgotten to finish :)

 include/linux/device.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/linux/device.h +7 -0
index fb50673..08128288 100644
@@ -916,6 +916,13 @@ static inline void device_lock_assert(struct device *dev)
 	lockdep_assert_held(&dev->mutex);
 }
 
+static inline struct device_node *dev_of_node(struct device *dev)
+{
+	if (!IS_ENABLED(CONFIG_OF))
+		return NULL;
+	return dev->of_node;
+}
+
 void driver_init(void);
 
 /*

--
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

Acked-by on v1 1/2
#1 lore raw

+Greg KH

Quoted 6 lines · Benjamin Herrenschmidt

Suggested by Arnd Bergmann, this gives a practical accessor for the of_node field of struct device while instructing the compiler that it will be NULL if CONFIG_OF is not set.

---

I'll let Greg take this with the other patch:

Quoted 28 lines

This is what we discussed back in November and I had forgotten to finish :)

 include/linux/device.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/linux/device.h +7 -0
index fb50673..08128288 100644
@@ -916,6 +916,13 @@ static inline void device_lock_assert(struct device *dev)
        lockdep_assert_held(&dev->mutex);
 }
 
+static inline struct device_node *dev_of_node(struct device *dev)
+{
+       if (!IS_ENABLED(CONFIG_OF))
+               return NULL;
+       return dev->of_node;
+}
+
 void driver_init(void);
 
 /*