Skip to content

Commit c1cf3d8

Browse files
ezequielgarciamchehab
authored andcommitted
media: v4l2-async: Clean v4l2_async_notifier_add_fwnode_remote_subdev
Change v4l2_async_notifier_add_fwnode_remote_subdev semantics so it allocates the struct v4l2_async_subdev pointer. This makes the API consistent: the v4l2-async subdevice addition functions have now a unified usage model. This model is simpler, as it makes v4l2-async responsible for the allocation and release of the subdevice descriptor, and no longer something the driver has to worry about. On the user side, the change makes the API simpler for the drivers to use and less error-prone. Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Reviewed-by: Helen Koike <helen.koike@collabora.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent 38a5023 commit c1cf3d8

12 files changed

Lines changed: 96 additions & 142 deletions

File tree

‎drivers/media/pci/intel/ipu3/ipu3-cio2-main.c‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,8 @@ static int cio2_parse_firmware(struct cio2_device *cio2)
14641464
struct v4l2_fwnode_endpoint vep = {
14651465
.bus_type = V4L2_MBUS_CSI2_DPHY
14661466
};
1467-
struct sensor_async_subdev *s_asd = NULL;
1467+
struct sensor_async_subdev *s_asd;
1468+
struct v4l2_async_subdev *asd;
14681469
struct fwnode_handle *ep;
14691470

14701471
ep = fwnode_graph_get_endpoint_by_id(
@@ -1478,27 +1479,23 @@ static int cio2_parse_firmware(struct cio2_device *cio2)
14781479
if (ret)
14791480
goto err_parse;
14801481

1481-
s_asd = kzalloc(sizeof(*s_asd), GFP_KERNEL);
1482-
if (!s_asd) {
1483-
ret = -ENOMEM;
1482+
asd = v4l2_async_notifier_add_fwnode_remote_subdev(
1483+
&cio2->notifier, ep, sizeof(*s_asd));
1484+
if (IS_ERR(asd)) {
1485+
ret = PTR_ERR(asd);
14841486
goto err_parse;
14851487
}
14861488

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

1490-
ret = v4l2_async_notifier_add_fwnode_remote_subdev(
1491-
&cio2->notifier, ep, &s_asd->asd);
1492-
if (ret)
1493-
goto err_parse;
1494-
14951493
fwnode_handle_put(ep);
14961494

14971495
continue;
14981496

14991497
err_parse:
15001498
fwnode_handle_put(ep);
1501-
kfree(s_asd);
15021499
return ret;
15031500
}
15041501

‎drivers/media/platform/omap3isp/isp.c‎

Lines changed: 33 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,21 +2126,6 @@ static void isp_parse_of_csi1_endpoint(struct device *dev,
21262126
buscfg->bus.ccp2.crc = 1;
21272127
}
21282128

2129-
static int isp_alloc_isd(struct isp_async_subdev **isd,
2130-
struct isp_bus_cfg **buscfg)
2131-
{
2132-
struct isp_async_subdev *__isd;
2133-
2134-
__isd = kzalloc(sizeof(*__isd), GFP_KERNEL);
2135-
if (!__isd)
2136-
return -ENOMEM;
2137-
2138-
*isd = __isd;
2139-
*buscfg = &__isd->bus;
2140-
2141-
return 0;
2142-
}
2143-
21442129
static struct {
21452130
u32 phy;
21462131
u32 csi2_if;
@@ -2156,7 +2141,7 @@ static int isp_parse_of_endpoints(struct isp_device *isp)
21562141
{
21572142
struct fwnode_handle *ep;
21582143
struct isp_async_subdev *isd = NULL;
2159-
struct isp_bus_cfg *buscfg;
2144+
struct v4l2_async_subdev *asd;
21602145
unsigned int i;
21612146

21622147
ep = fwnode_graph_get_endpoint_by_id(
@@ -2174,20 +2159,15 @@ static int isp_parse_of_endpoints(struct isp_device *isp)
21742159
ret = v4l2_fwnode_endpoint_parse(ep, &vep);
21752160

21762161
if (!ret) {
2177-
ret = isp_alloc_isd(&isd, &buscfg);
2178-
if (ret)
2179-
return ret;
2180-
}
2181-
2182-
if (!ret) {
2183-
isp_parse_of_parallel_endpoint(isp->dev, &vep, buscfg);
2184-
ret = v4l2_async_notifier_add_fwnode_remote_subdev(
2185-
&isp->notifier, ep, &isd->asd);
2162+
asd = v4l2_async_notifier_add_fwnode_remote_subdev(
2163+
&isp->notifier, ep, sizeof(*isd));
2164+
if (!IS_ERR(asd)) {
2165+
isd = container_of(asd, struct isp_async_subdev, asd);
2166+
isp_parse_of_parallel_endpoint(isp->dev, &vep, &isd->bus);
2167+
}
21862168
}
21872169

21882170
fwnode_handle_put(ep);
2189-
if (ret)
2190-
kfree(isd);
21912171
}
21922172

21932173
for (i = 0; i < ARRAY_SIZE(isp_bus_interfaces); i++) {
@@ -2206,15 +2186,8 @@ static int isp_parse_of_endpoints(struct isp_device *isp)
22062186
dev_dbg(isp->dev, "parsing serial interface %u, node %pOF\n", i,
22072187
to_of_node(ep));
22082188

2209-
ret = isp_alloc_isd(&isd, &buscfg);
2210-
if (ret)
2211-
return ret;
2212-
22132189
ret = v4l2_fwnode_endpoint_parse(ep, &vep);
2214-
if (!ret) {
2215-
buscfg->interface = isp_bus_interfaces[i].csi2_if;
2216-
isp_parse_of_csi2_endpoint(isp->dev, &vep, buscfg);
2217-
} else if (ret == -ENXIO) {
2190+
if (ret == -ENXIO) {
22182191
vep = (struct v4l2_fwnode_endpoint)
22192192
{ .bus_type = V4L2_MBUS_CSI1 };
22202193
ret = v4l2_fwnode_endpoint_parse(ep, &vep);
@@ -2224,21 +2197,35 @@ static int isp_parse_of_endpoints(struct isp_device *isp)
22242197
{ .bus_type = V4L2_MBUS_CCP2 };
22252198
ret = v4l2_fwnode_endpoint_parse(ep, &vep);
22262199
}
2227-
if (!ret) {
2228-
buscfg->interface =
2229-
isp_bus_interfaces[i].csi1_if;
2230-
isp_parse_of_csi1_endpoint(isp->dev, &vep,
2231-
buscfg);
2232-
}
22332200
}
22342201

2235-
if (!ret)
2236-
ret = v4l2_async_notifier_add_fwnode_remote_subdev(
2237-
&isp->notifier, ep, &isd->asd);
2202+
if (!ret) {
2203+
asd = v4l2_async_notifier_add_fwnode_remote_subdev(
2204+
&isp->notifier, ep, sizeof(*isd));
2205+
2206+
if (!IS_ERR(asd)) {
2207+
isd = container_of(asd, struct isp_async_subdev, asd);
2208+
2209+
switch (vep.bus_type) {
2210+
case V4L2_MBUS_CSI2_DPHY:
2211+
isd->bus.interface =
2212+
isp_bus_interfaces[i].csi2_if;
2213+
isp_parse_of_csi2_endpoint(isp->dev, &vep, &isd->bus);
2214+
break;
2215+
case V4L2_MBUS_CSI1:
2216+
case V4L2_MBUS_CCP2:
2217+
isd->bus.interface =
2218+
isp_bus_interfaces[i].csi1_if;
2219+
isp_parse_of_csi1_endpoint(isp->dev, &vep,
2220+
&isd->bus);
2221+
break;
2222+
default:
2223+
break;
2224+
}
2225+
}
2226+
}
22382227

22392228
fwnode_handle_put(ep);
2240-
if (ret)
2241-
kfree(isd);
22422229
}
22432230

22442231
return 0;

‎drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ static int rkisp1_subdev_notifier(struct rkisp1_device *rkisp1)
252252
.bus_type = V4L2_MBUS_CSI2_DPHY
253253
};
254254
struct rkisp1_sensor_async *rk_asd = NULL;
255+
struct v4l2_async_subdev *asd;
255256
struct fwnode_handle *ep;
256257

257258
ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(rkisp1->dev),
@@ -264,21 +265,18 @@ static int rkisp1_subdev_notifier(struct rkisp1_device *rkisp1)
264265
if (ret)
265266
goto err_parse;
266267

267-
rk_asd = kzalloc(sizeof(*rk_asd), GFP_KERNEL);
268-
if (!rk_asd) {
269-
ret = -ENOMEM;
268+
asd = v4l2_async_notifier_add_fwnode_remote_subdev(ntf, ep,
269+
sizeof(*rk_asd));
270+
if (IS_ERR(asd)) {
271+
ret = PTR_ERR(asd);
270272
goto err_parse;
271273
}
272274

275+
rk_asd = container_of(asd, struct rkisp1_sensor_async, asd);
273276
rk_asd->mbus_type = vep.bus_type;
274277
rk_asd->mbus_flags = vep.bus.mipi_csi2.flags;
275278
rk_asd->lanes = vep.bus.mipi_csi2.num_data_lanes;
276279

277-
ret = v4l2_async_notifier_add_fwnode_remote_subdev(ntf, ep,
278-
&rk_asd->asd);
279-
if (ret)
280-
goto err_parse;
281-
282280
dev_dbg(rkisp1->dev, "registered ep id %d with %d lanes\n",
283281
vep.base.id, rk_asd->lanes);
284282

@@ -289,7 +287,6 @@ static int rkisp1_subdev_notifier(struct rkisp1_device *rkisp1)
289287
continue;
290288
err_parse:
291289
fwnode_handle_put(ep);
292-
kfree(rk_asd);
293290
v4l2_async_notifier_cleanup(ntf);
294291
return ret;
295292
}

‎drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ static int sun4i_csi_notifier_init(struct sun4i_csi *csi)
118118
struct v4l2_fwnode_endpoint vep = {
119119
.bus_type = V4L2_MBUS_PARALLEL,
120120
};
121+
struct v4l2_async_subdev *asd;
121122
struct fwnode_handle *ep;
122123
int ret;
123124

@@ -134,10 +135,12 @@ static int sun4i_csi_notifier_init(struct sun4i_csi *csi)
134135

135136
csi->bus = vep.bus.parallel;
136137

137-
ret = v4l2_async_notifier_add_fwnode_remote_subdev(&csi->notifier,
138-
ep, &csi->asd);
139-
if (ret)
138+
asd = v4l2_async_notifier_add_fwnode_remote_subdev(&csi->notifier,
139+
ep, sizeof(*asd));
140+
if (IS_ERR(asd)) {
141+
ret = PTR_ERR(asd);
140142
goto out;
143+
}
141144

142145
csi->notifier.ops = &sun4i_csi_notify_ops;
143146

‎drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ struct sun4i_csi {
139139
struct v4l2_mbus_framefmt subdev_fmt;
140140

141141
/* V4L2 Async variables */
142-
struct v4l2_async_subdev asd;
143142
struct v4l2_async_notifier notifier;
144143
struct v4l2_subdev *src_subdev;
145144
int src_pad;

‎drivers/media/platform/video-mux.c‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -370,19 +370,13 @@ static int video_mux_async_register(struct video_mux *vmux,
370370
if (!ep)
371371
continue;
372372

373-
asd = kzalloc(sizeof(*asd), GFP_KERNEL);
374-
if (!asd) {
375-
fwnode_handle_put(ep);
376-
return -ENOMEM;
377-
}
378-
379-
ret = v4l2_async_notifier_add_fwnode_remote_subdev(
380-
&vmux->notifier, ep, asd);
373+
asd = v4l2_async_notifier_add_fwnode_remote_subdev(
374+
&vmux->notifier, ep, sizeof(*asd));
381375

382376
fwnode_handle_put(ep);
383377

384-
if (ret) {
385-
kfree(asd);
378+
if (IS_ERR(asd)) {
379+
ret = PTR_ERR(asd);
386380
/* OK if asd already exists */
387381
if (ret != -EEXIST)
388382
return ret;

‎drivers/media/v4l2-core/v4l2-async.c‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -656,26 +656,26 @@ v4l2_async_notifier_add_fwnode_subdev(struct v4l2_async_notifier *notifier,
656656
}
657657
EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_fwnode_subdev);
658658

659-
int
659+
struct v4l2_async_subdev *
660660
v4l2_async_notifier_add_fwnode_remote_subdev(struct v4l2_async_notifier *notif,
661661
struct fwnode_handle *endpoint,
662-
struct v4l2_async_subdev *asd)
662+
unsigned int asd_struct_size)
663663
{
664+
struct v4l2_async_subdev *asd;
664665
struct fwnode_handle *remote;
665-
int ret;
666666

667667
remote = fwnode_graph_get_remote_port_parent(endpoint);
668668
if (!remote)
669-
return -ENOTCONN;
669+
return ERR_PTR(-ENOTCONN);
670670

671-
asd->match_type = V4L2_ASYNC_MATCH_FWNODE;
672-
asd->match.fwnode = remote;
673-
674-
ret = v4l2_async_notifier_add_subdev(notif, asd);
675-
if (ret)
676-
fwnode_handle_put(remote);
677-
678-
return ret;
671+
asd = v4l2_async_notifier_add_fwnode_subdev(notif, remote,
672+
asd_struct_size);
673+
/*
674+
* Calling v4l2_async_notifier_add_fwnode_subdev grabs a refcount,
675+
* so drop the one we got in fwnode_graph_get_remote_port_parent.
676+
*/
677+
fwnode_handle_put(remote);
678+
return asd;
679679
}
680680
EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_fwnode_remote_subdev);
681681

‎drivers/staging/media/imx/imx-media-csi.c‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,19 +1922,13 @@ static int imx_csi_async_register(struct csi_priv *priv)
19221922
port, 0,
19231923
FWNODE_GRAPH_ENDPOINT_NEXT);
19241924
if (ep) {
1925-
asd = kzalloc(sizeof(*asd), GFP_KERNEL);
1926-
if (!asd) {
1927-
fwnode_handle_put(ep);
1928-
return -ENOMEM;
1929-
}
1930-
1931-
ret = v4l2_async_notifier_add_fwnode_remote_subdev(
1932-
&priv->notifier, ep, asd);
1925+
asd = v4l2_async_notifier_add_fwnode_remote_subdev(
1926+
&priv->notifier, ep, sizeof(*asd));
19331927

19341928
fwnode_handle_put(ep);
19351929

1936-
if (ret) {
1937-
kfree(asd);
1930+
if (IS_ERR(asd)) {
1931+
ret = PTR_ERR(asd);
19381932
/* OK if asd already exists */
19391933
if (ret != -EEXIST)
19401934
return ret;

‎drivers/staging/media/imx/imx6-mipi-csi2.c‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ static int csi2_async_register(struct csi2_dev *csi2)
641641
struct v4l2_fwnode_endpoint vep = {
642642
.bus_type = V4L2_MBUS_CSI2_DPHY,
643643
};
644-
struct v4l2_async_subdev *asd = NULL;
644+
struct v4l2_async_subdev *asd;
645645
struct fwnode_handle *ep;
646646
int ret;
647647

@@ -661,19 +661,13 @@ static int csi2_async_register(struct csi2_dev *csi2)
661661
dev_dbg(csi2->dev, "data lanes: %d\n", vep.bus.mipi_csi2.num_data_lanes);
662662
dev_dbg(csi2->dev, "flags: 0x%08x\n", vep.bus.mipi_csi2.flags);
663663

664-
asd = kzalloc(sizeof(*asd), GFP_KERNEL);
665-
if (!asd) {
666-
ret = -ENOMEM;
667-
goto err_parse;
668-
}
669-
670-
ret = v4l2_async_notifier_add_fwnode_remote_subdev(
671-
&csi2->notifier, ep, asd);
672-
if (ret)
673-
goto err_parse;
674-
664+
asd = v4l2_async_notifier_add_fwnode_remote_subdev(
665+
&csi2->notifier, ep, sizeof(*asd));
675666
fwnode_handle_put(ep);
676667

668+
if (IS_ERR(asd))
669+
return PTR_ERR(asd);
670+
677671
csi2->notifier.ops = &csi2_notify_ops;
678672

679673
ret = v4l2_async_subdev_notifier_register(&csi2->sd,
@@ -685,7 +679,6 @@ static int csi2_async_register(struct csi2_dev *csi2)
685679

686680
err_parse:
687681
fwnode_handle_put(ep);
688-
kfree(asd);
689682
return ret;
690683
}
691684

0 commit comments

Comments
 (0)