device: Add dev_of_node() accessor
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>
Wed, 18 Feb 2015 01:03:41 +0000 (19:03 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 25 Mar 2015 13:53:58 +0000 (14:53 +0100)
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.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/linux/device.h

index 0eb8ee2..f3f2c7e 100644 (file)
@@ -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);
 
 /*