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

@@ -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;

View File

@@ -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)) {

View File

@@ -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;

View File

@@ -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;

View File

@@ -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))

View File

@@ -214,7 +214,7 @@ static int atmel_isc_probe(struct platform_device *pdev)
asd = v4l2_async_notifier_add_fwnode_remote_subdev(
&subdev_entity->notifier,
of_fwnode_handle(subdev_entity->epn),
sizeof(*asd));
struct v4l2_async_subdev);
of_node_put(subdev_entity->epn);
subdev_entity->epn = NULL;

View File

@@ -398,7 +398,8 @@ static int csi2rx_parse_dt(struct csi2rx_priv *csi2rx)
v4l2_async_notifier_init(&csi2rx->notifier);
asd = v4l2_async_notifier_add_fwnode_remote_subdev(&csi2rx->notifier,
fwh, sizeof(*asd));
fwh,
struct v4l2_async_subdev);
of_node_put(ep);
if (IS_ERR(asd))
return PTR_ERR(asd);

View File

@@ -1584,7 +1584,7 @@ vpif_capture_get_pdata(struct platform_device *pdev)
pdata->asd[i] = v4l2_async_notifier_add_fwnode_subdev(
&vpif_obj.notifier, of_fwnode_handle(rem),
sizeof(struct v4l2_async_subdev));
struct v4l2_async_subdev);
if (IS_ERR(pdata->asd[i]))
goto err_cleanup;

View File

@@ -465,7 +465,8 @@ static int fimc_md_parse_one_endpoint(struct fimc_md *fmd,
}
asd = v4l2_async_notifier_add_fwnode_remote_subdev(
&fmd->subdev_notifier, of_fwnode_handle(ep), sizeof(*asd));
&fmd->subdev_notifier, of_fwnode_handle(ep),
struct v4l2_async_subdev);
of_node_put(ep);

View File

@@ -552,7 +552,7 @@ static int cafe_pci_probe(struct pci_dev *pdev,
asd = v4l2_async_notifier_add_i2c_subdev(&mcam->notifier,
i2c_adapter_id(cam->i2c_adapter),
ov7670_info.addr,
sizeof(*asd));
struct v4l2_async_subdev);
if (IS_ERR(asd)) {
ret = PTR_ERR(asd);
goto out_smbus_shutdown;

View File

@@ -241,8 +241,8 @@ static int mmpcam_probe(struct platform_device *pdev)
v4l2_async_notifier_init(&mcam->notifier);
asd = v4l2_async_notifier_add_fwnode_remote_subdev(&mcam->notifier,
ep, sizeof(*asd));
asd = v4l2_async_notifier_add_fwnode_remote_subdev(&mcam->notifier, ep,
struct v4l2_async_subdev);
fwnode_handle_put(ep);
if (IS_ERR(asd)) {
ret = PTR_ERR(asd);

View File

@@ -2141,7 +2141,6 @@ static int isp_parse_of_endpoints(struct isp_device *isp)
{
struct fwnode_handle *ep;
struct isp_async_subdev *isd = NULL;
struct v4l2_async_subdev *asd;
unsigned int i;
ep = fwnode_graph_get_endpoint_by_id(
@@ -2159,12 +2158,10 @@ static int isp_parse_of_endpoints(struct isp_device *isp)
ret = v4l2_fwnode_endpoint_parse(ep, &vep);
if (!ret) {
asd = v4l2_async_notifier_add_fwnode_remote_subdev(
&isp->notifier, ep, sizeof(*isd));
if (!IS_ERR(asd)) {
isd = container_of(asd, struct isp_async_subdev, asd);
isd = v4l2_async_notifier_add_fwnode_remote_subdev(
&isp->notifier, ep, struct isp_async_subdev);
if (!IS_ERR(isd))
isp_parse_of_parallel_endpoint(isp->dev, &vep, &isd->bus);
}
}
fwnode_handle_put(ep);
@@ -2200,12 +2197,10 @@ static int isp_parse_of_endpoints(struct isp_device *isp)
}
if (!ret) {
asd = v4l2_async_notifier_add_fwnode_remote_subdev(
&isp->notifier, ep, sizeof(*isd));
if (!IS_ERR(asd)) {
isd = container_of(asd, struct isp_async_subdev, asd);
isd = v4l2_async_notifier_add_fwnode_remote_subdev(
&isp->notifier, ep, struct isp_async_subdev);
if (!IS_ERR(isd)) {
switch (vep.bus_type) {
case V4L2_MBUS_CSI2_DPHY:
isd->bus.interface =

View File

@@ -2259,7 +2259,7 @@ static int pxa_camera_pdata_from_dt(struct device *dev,
asd = v4l2_async_notifier_add_fwnode_remote_subdev(
&pcdev->notifier,
of_fwnode_handle(np),
sizeof(*asd));
struct v4l2_async_subdev);
if (IS_ERR(asd))
err = PTR_ERR(asd);
out:
@@ -2309,7 +2309,7 @@ static int pxa_camera_probe(struct platform_device *pdev)
&pcdev->notifier,
pcdev->pdata->sensor_i2c_adapter_id,
pcdev->pdata->sensor_i2c_address,
sizeof(*asd));
struct v4l2_async_subdev);
if (IS_ERR(asd))
err = PTR_ERR(asd);
} else if (pdev->dev.of_node) {

View File

@@ -655,7 +655,6 @@ static int camss_of_parse_ports(struct camss *camss)
for_each_endpoint_of_node(dev->of_node, node) {
struct camss_async_subdev *csd;
struct v4l2_async_subdev *asd;
if (!of_device_is_available(node))
continue;
@@ -667,17 +666,15 @@ static int camss_of_parse_ports(struct camss *camss)
goto err_cleanup;
}
asd = v4l2_async_notifier_add_fwnode_subdev(
csd = v4l2_async_notifier_add_fwnode_subdev(
&camss->notifier, of_fwnode_handle(remote),
sizeof(*csd));
struct camss_async_subdev);
of_node_put(remote);
if (IS_ERR(asd)) {
ret = PTR_ERR(asd);
if (IS_ERR(csd)) {
ret = PTR_ERR(csd);
goto err_cleanup;
}
csd = container_of(asd, struct camss_async_subdev, asd);
ret = camss_of_parse_endpoint_node(dev, node, csd);
if (ret < 0)
goto err_cleanup;

View File

@@ -642,7 +642,7 @@ static int rvin_parallel_parse_of(struct rvin_dev *vin)
}
asd = v4l2_async_notifier_add_fwnode_subdev(&vin->notifier, fwnode,
sizeof(*asd));
struct v4l2_async_subdev);
if (IS_ERR(asd)) {
ret = PTR_ERR(asd);
goto out;
@@ -842,7 +842,8 @@ static int rvin_mc_parse_of(struct rvin_dev *vin, unsigned int id)
}
asd = v4l2_async_notifier_add_fwnode_subdev(&vin->group->notifier,
fwnode, sizeof(*asd));
fwnode,
struct v4l2_async_subdev);
if (IS_ERR(asd)) {
ret = PTR_ERR(asd);
goto out;

View File

@@ -910,7 +910,7 @@ static int rcsi2_parse_dt(struct rcar_csi2 *priv)
priv->notifier.ops = &rcar_csi2_notify_ops;
asd = v4l2_async_notifier_add_fwnode_subdev(&priv->notifier, fwnode,
sizeof(*asd));
struct v4l2_async_subdev);
fwnode_handle_put(fwnode);
if (IS_ERR(asd))
return PTR_ERR(asd);

View File

@@ -1231,7 +1231,7 @@ static int rcar_drif_parse_subdevs(struct rcar_drif_sdr *sdr)
}
asd = v4l2_async_notifier_add_fwnode_subdev(notifier, fwnode,
sizeof(*asd));
struct v4l2_async_subdev);
fwnode_handle_put(fwnode);
if (IS_ERR(asd))
return PTR_ERR(asd);

View File

@@ -1495,7 +1495,6 @@ static int ceu_parse_platform_data(struct ceu_device *ceudev,
const struct ceu_platform_data *pdata)
{
const struct ceu_async_subdev *async_sd;
struct v4l2_async_subdev *asd;
struct ceu_subdev *ceu_sd;
unsigned int i;
int ret;
@@ -1511,15 +1510,14 @@ static int ceu_parse_platform_data(struct ceu_device *ceudev,
/* Setup the ceu subdevice and the async subdevice. */
async_sd = &pdata->subdevs[i];
asd = v4l2_async_notifier_add_i2c_subdev(&ceudev->notifier,
ceu_sd = v4l2_async_notifier_add_i2c_subdev(&ceudev->notifier,
async_sd->i2c_adapter_id,
async_sd->i2c_address,
sizeof(*ceu_sd));
if (IS_ERR(asd)) {
struct ceu_subdev);
if (IS_ERR(ceu_sd)) {
v4l2_async_notifier_cleanup(&ceudev->notifier);
return PTR_ERR(asd);
return PTR_ERR(ceu_sd);
}
ceu_sd = to_ceu_subdev(asd);
ceu_sd->mbus_flags = async_sd->flags;
ceudev->subdevs[i] = ceu_sd;
}
@@ -1534,7 +1532,6 @@ static int ceu_parse_dt(struct ceu_device *ceudev)
{
struct device_node *of = ceudev->dev->of_node;
struct device_node *ep;
struct v4l2_async_subdev *asd;
struct ceu_subdev *ceu_sd;
unsigned int i;
int num_ep;
@@ -1576,14 +1573,13 @@ static int ceu_parse_dt(struct ceu_device *ceudev)
}
/* Setup the ceu subdevice and the async subdevice. */
asd = v4l2_async_notifier_add_fwnode_remote_subdev(
ceu_sd = v4l2_async_notifier_add_fwnode_remote_subdev(
&ceudev->notifier, of_fwnode_handle(ep),
sizeof(*ceu_sd));
if (IS_ERR(asd)) {
ret = PTR_ERR(asd);
struct ceu_subdev);
if (IS_ERR(ceu_sd)) {
ret = PTR_ERR(ceu_sd);
goto error_cleanup;
}
ceu_sd = to_ceu_subdev(asd);
ceu_sd->mbus_flags = fw_ep.bus.parallel.flags;
ceudev->subdevs[i] = ceu_sd;

View File

@@ -251,8 +251,7 @@ static int rkisp1_subdev_notifier(struct rkisp1_device *rkisp1)
struct v4l2_fwnode_endpoint vep = {
.bus_type = V4L2_MBUS_CSI2_DPHY
};
struct rkisp1_sensor_async *rk_asd = NULL;
struct v4l2_async_subdev *asd;
struct rkisp1_sensor_async *rk_asd;
struct fwnode_handle *ep;
ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(rkisp1->dev),
@@ -265,14 +264,13 @@ static int rkisp1_subdev_notifier(struct rkisp1_device *rkisp1)
if (ret)
goto err_parse;
asd = v4l2_async_notifier_add_fwnode_remote_subdev(ntf, ep,
sizeof(*rk_asd));
if (IS_ERR(asd)) {
ret = PTR_ERR(asd);
rk_asd = v4l2_async_notifier_add_fwnode_remote_subdev(ntf, ep,
struct rkisp1_sensor_async);
if (IS_ERR(rk_asd)) {
ret = PTR_ERR(rk_asd);
goto err_parse;
}
rk_asd = container_of(asd, struct rkisp1_sensor_async, asd);
rk_asd->mbus_type = vep.bus_type;
rk_asd->mbus_flags = vep.bus.mipi_csi2.flags;
rk_asd->lanes = vep.bus.mipi_csi2.num_data_lanes;

View File

@@ -1820,7 +1820,8 @@ static int dcmi_graph_init(struct stm32_dcmi *dcmi)
v4l2_async_notifier_init(&dcmi->notifier);
asd = v4l2_async_notifier_add_fwnode_remote_subdev(
&dcmi->notifier, of_fwnode_handle(ep), sizeof(*asd));
&dcmi->notifier, of_fwnode_handle(ep),
struct v4l2_async_subdev);
of_node_put(ep);

Some files were not shown because too many files have changed in this diff Show More