Commit b01edcbd authored by Laurent Pinchart's avatar Laurent Pinchart Committed by Mauro Carvalho Chehab
Browse files

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: default avatarLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: default avatarNiklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: default avatarJacopo Mondi <jacopo+renesas@jmondi.org>
Signed-off-by: default avatarEzequiel Garcia <ezequiel@collabora.com>
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: default avatarHelen Koike <helen.koike@collabora.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> (core+ti-cal)
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent c1cc2362
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -576,19 +576,19 @@ static int max9286_v4l2_notifier_register(struct max9286_priv *priv)

	for_each_source(priv, source) {
		unsigned int i = to_index(priv, source);
		struct v4l2_async_subdev *asd;
		struct max9286_asd *mas;

		asd = v4l2_async_notifier_add_fwnode_subdev(&priv->notifier,
		mas = v4l2_async_notifier_add_fwnode_subdev(&priv->notifier,
							    source->fwnode,
							    sizeof(struct max9286_asd));
		if (IS_ERR(asd)) {
							    struct max9286_asd);
		if (IS_ERR(mas)) {
			dev_err(dev, "Failed to add subdev for source %u: %ld",
				i, PTR_ERR(asd));
				i, PTR_ERR(mas));
			v4l2_async_notifier_cleanup(&priv->notifier);
			return PTR_ERR(asd);
			return PTR_ERR(mas);
		}

		to_max9286_asd(asd)->source = source;
		mas->source = source;
	}

	priv->notifier.ops = &max9286_notify_ops;
+1 −1
Original line number Diff line number Diff line
@@ -879,7 +879,7 @@ static int mipid02_parse_rx_ep(struct mipid02_dev *bridge)
	asd = v4l2_async_notifier_add_fwnode_remote_subdev(
					&bridge->notifier,
					of_fwnode_handle(ep_node),
					sizeof(*asd));
					struct v4l2_async_subdev);
	of_node_put(ep_node);

	if (IS_ERR(asd)) {
+4 −6
Original line number Diff line number Diff line
@@ -1465,7 +1465,6 @@ static int cio2_parse_firmware(struct cio2_device *cio2)
			.bus_type = V4L2_MBUS_CSI2_DPHY
		};
		struct sensor_async_subdev *s_asd;
		struct v4l2_async_subdev *asd;
		struct fwnode_handle *ep;

		ep = fwnode_graph_get_endpoint_by_id(
@@ -1479,14 +1478,13 @@ static int cio2_parse_firmware(struct cio2_device *cio2)
		if (ret)
			goto err_parse;

		asd = v4l2_async_notifier_add_fwnode_remote_subdev(
				&cio2->notifier, ep, sizeof(*s_asd));
		if (IS_ERR(asd)) {
			ret = PTR_ERR(asd);
		s_asd = v4l2_async_notifier_add_fwnode_remote_subdev(
				&cio2->notifier, ep, struct sensor_async_subdev);
		if (IS_ERR(s_asd)) {
			ret = PTR_ERR(s_asd);
			goto err_parse;
		}

		s_asd = container_of(asd, struct sensor_async_subdev, asd);
		s_asd->csi2.port = vep.base.port;
		s_asd->csi2.lanes = vep.bus.mipi_csi2.num_data_lanes;

+1 −1
Original line number Diff line number Diff line
@@ -2365,7 +2365,7 @@ vpfe_get_pdata(struct vpfe_device *vpfe)

		pdata->asd[i] = v4l2_async_notifier_add_fwnode_subdev(
			&vpfe->notifier, of_fwnode_handle(rem),
			sizeof(struct v4l2_async_subdev));
			struct v4l2_async_subdev);
		of_node_put(rem);
		if (IS_ERR(pdata->asd[i]))
			goto cleanup;
+1 −1
Original line number Diff line number Diff line
@@ -1150,7 +1150,7 @@ static int isi_graph_init(struct atmel_isi *isi)
	asd = v4l2_async_notifier_add_fwnode_remote_subdev(
						&isi->notifier,
						of_fwnode_handle(ep),
						sizeof(*asd));
						struct v4l2_async_subdev);
	of_node_put(ep);

	if (IS_ERR(asd))
Loading