media: v4l2-async: Improve v4l2_async_notifier_add_*_subdev() API

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 <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Helen Koike <helen.koike@collabora.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> (core+ti-cal)
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
This commit is contained in:
Laurent Pinchart
2021-01-18 02:52:58 +01:00
committed by Mauro Carvalho Chehab
parent c1cc236250
commit b01edcbd40
33 changed files with 113 additions and 118 deletions

View File

@@ -631,9 +631,9 @@ unlock:
EXPORT_SYMBOL_GPL(__v4l2_async_notifier_add_subdev);
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)
{
struct v4l2_async_subdev *asd;
int ret;
@@ -654,12 +654,12 @@ v4l2_async_notifier_add_fwnode_subdev(struct v4l2_async_notifier *notifier,
return asd;
}
EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_fwnode_subdev);
EXPORT_SYMBOL_GPL(__v4l2_async_notifier_add_fwnode_subdev);
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)
{
struct v4l2_async_subdev *asd;
struct fwnode_handle *remote;
@@ -668,21 +668,21 @@ v4l2_async_notifier_add_fwnode_remote_subdev(struct v4l2_async_notifier *notif,
if (!remote)
return ERR_PTR(-ENOTCONN);
asd = v4l2_async_notifier_add_fwnode_subdev(notif, remote,
asd_struct_size);
asd = __v4l2_async_notifier_add_fwnode_subdev(notif, remote,
asd_struct_size);
/*
* Calling v4l2_async_notifier_add_fwnode_subdev grabs a refcount,
* Calling __v4l2_async_notifier_add_fwnode_subdev grabs a refcount,
* so drop the one we got in fwnode_graph_get_remote_port_parent.
*/
fwnode_handle_put(remote);
return asd;
}
EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_fwnode_remote_subdev);
EXPORT_SYMBOL_GPL(__v4l2_async_notifier_add_fwnode_remote_subdev);
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)
{
struct v4l2_async_subdev *asd;
int ret;
@@ -703,7 +703,7 @@ v4l2_async_notifier_add_i2c_subdev(struct v4l2_async_notifier *notifier,
return asd;
}
EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_i2c_subdev);
EXPORT_SYMBOL_GPL(__v4l2_async_notifier_add_i2c_subdev);
int v4l2_async_register_subdev(struct v4l2_subdev *sd)
{