From b01edcbd409cf713ff4516c6e1e057834b4b43d6 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 18 Jan 2021 02:52:58 +0100 Subject: media: v4l2-async: Improve v4l2_async_notifier_add_*_subdev() API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The functions that add an async subdev to an async subdev notifier take as an argument the size of the container structure they need to allocate. This is error prone, as passing an invalid size will not be caught by the compiler. Wrap those functions in macros that take a container type instead of a size, and cast the returned pointer to the desired type. The compiler will catch mistakes if the incorrect type is passed to the macro, as the assignment types won't match. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Signed-off-by: Ezequiel Garcia Signed-off-by: Sakari Ailus Reviewed-by: Helen Koike Reviewed-by: Tomi Valkeinen (core+ti-cal) Signed-off-by: Mauro Carvalho Chehab --- include/media/v4l2-async.h | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'include/media/v4l2-async.h') diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h index b113329582ff..192a11bdc4ad 100644 --- a/include/media/v4l2-async.h +++ b/include/media/v4l2-async.h @@ -168,9 +168,12 @@ int __v4l2_async_notifier_add_subdev(struct v4l2_async_notifier *notifier, * is released later at notifier cleanup time. */ struct v4l2_async_subdev * -v4l2_async_notifier_add_fwnode_subdev(struct v4l2_async_notifier *notifier, - struct fwnode_handle *fwnode, - unsigned int asd_struct_size); +__v4l2_async_notifier_add_fwnode_subdev(struct v4l2_async_notifier *notifier, + struct fwnode_handle *fwnode, + unsigned int asd_struct_size); +#define v4l2_async_notifier_add_fwnode_subdev(__notifier, __fwnode, __type) \ +((__type *)__v4l2_async_notifier_add_fwnode_subdev(__notifier, __fwnode, \ + sizeof(__type))) /** * v4l2_async_notifier_add_fwnode_remote_subdev - Allocate and add a fwnode @@ -194,9 +197,12 @@ v4l2_async_notifier_add_fwnode_subdev(struct v4l2_async_notifier *notifier, * exception that the fwnode refers to a local endpoint, not the remote one. */ struct v4l2_async_subdev * -v4l2_async_notifier_add_fwnode_remote_subdev(struct v4l2_async_notifier *notif, - struct fwnode_handle *endpoint, - unsigned int asd_struct_size); +__v4l2_async_notifier_add_fwnode_remote_subdev(struct v4l2_async_notifier *notif, + struct fwnode_handle *endpoint, + unsigned int asd_struct_size); +#define v4l2_async_notifier_add_fwnode_remote_subdev(__notifier, __ep, __type) \ +((__type *)__v4l2_async_notifier_add_fwnode_remote_subdev(__notifier, __ep, \ + sizeof(__type))) /** * v4l2_async_notifier_add_i2c_subdev - Allocate and add an i2c async @@ -214,9 +220,12 @@ v4l2_async_notifier_add_fwnode_remote_subdev(struct v4l2_async_notifier *notif, * Same as above but for I2C matched sub-devices. */ struct v4l2_async_subdev * -v4l2_async_notifier_add_i2c_subdev(struct v4l2_async_notifier *notifier, - int adapter_id, unsigned short address, - unsigned int asd_struct_size); +__v4l2_async_notifier_add_i2c_subdev(struct v4l2_async_notifier *notifier, + int adapter_id, unsigned short address, + unsigned int asd_struct_size); +#define v4l2_async_notifier_add_i2c_subdev(__notifier, __adap, __addr, __type) \ +((__type *)__v4l2_async_notifier_add_i2c_subdev(__notifier, __adap, __addr, \ + sizeof(__type))) /** * v4l2_async_notifier_register - registers a subdevice asynchronous notifier -- cgit