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@xxxxxxxxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html