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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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>
---
since v1:

- Use correct return codes for ops returning integers. -ENXIO is returned if an op
  does not exist and -EINVAL is returned if fwnode is NULL.

 include/linux/fwnode.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h
index ede74fb..75e2a00 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__) : -ENXIO) : \
+	 -EINVAL)
+#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 linux-acpi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux IBM ACPI]     [Linux Power Management]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux