[PATCH 05/20] device property: Add macros for calling fwnode operations

Sakari Ailus
2017-02-23T17:08:33Z

Not all implementations may implement all fwnode operations. Instead of
leaving this up to the caller to figure out, add a few macros for the
purpose.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
include/linux/fwnode.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h
index ede74fb..37d6ee1 100644
--- a/include/linux/fwnode.h
+++ b/include/linux/fwnode.h
@@ -82,4 +82,19 @@ struct fwnode_operations {
struct fwnode_endpoint *endpoint);
};

+#define fwnode_has_op(fwnode, op) \
+ ((fwnode) && (fwnode)->ops && (fwnode)->ops->op)
+#define fwnode_call_int_op(fwnode, op, ...) \
+ (fwnode ? (fwnode_has_op(fwnode, op) ? \
+ (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : 0) : \
+ -ENXIO)
+#define fwnode_call_ptr_op(fwnode, op, ...) \
+ (fwnode_has_op(fwnode, op) ? \
+ (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
+#define fwnode_call_void_op(fwnode, op, ...) \
+ do { \
+ if (fwnode_has_op(fwnode, op)) \
+ (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \
+ } while (false)
+
#endif
--
2.7.4