Skip to content

Commit 62c6668

Browse files
ezequielgarciagregkh
authored andcommitted
media: v4l2-async: Clean v4l2_async_notifier_add_fwnode_remote_subdev
[ Upstream commit c1cf3d8 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6bfcb61 commit 62c6668

12 files changed

Lines changed: 96 additions & 142 deletions

File tree

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,8 @@ static int cio2_parse_firmware(struct cio2_device *cio2)
14761476
struct v4l2_fwnode_endpoint vep = {
14771477
.bus_type = V4L2_MBUS_CSI2_DPHY
14781478
};
1479-
struct sensor_async_subdev *s_asd = NULL;
1479+
struct sensor_async_subdev *s_asd;
1480+
struct v4l2_async_subdev *asd;
14801481
struct fwnode_handle *ep;
14811482

14821483
ep = fwnode_graph_get_endpoint_by_id(
@@ -1490,27 +1491,23 @@ static int cio2_parse_firmware(struct cio2_device *cio2)
14901491
if (ret)
14911492
goto err_parse;
14921493

1493-
s_asd = kzalloc(sizeof(*s_asd), GFP_KERNEL);
1494-
if (!s_asd) {
1495-
ret = -ENOMEM;
1494+
asd = v4l2_async_notifier_add_fwnode_remote_subdev(
1495+
&cio2->notifier, ep, sizeof(*s_asd));
1496+
if (IS_ERR(asd)) {
1497+
ret = PTR_ERR(asd);
14961498
goto err_parse;
14971499
}
14981500

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

1502-
ret = v4l2_async_notifier_add_fwnode_remote_subdev(
1503-
&cio2->notifier, ep, &s_asd->asd);
1504-
if (ret)
1505-
goto err_parse;
1506-
15071505
fwnode_handle_put(ep);
15081506

15091507
continue;
15101508

15111509
err_parse:
15121510
fwnode_handle_put(ep);
1513-
kfree(s_asd);
15141511
return ret;
15151512
}
15161513

‎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/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
@@ -673,26 +673,26 @@ v4l2_async_notifier_add_fwnode_subdev(struct v4l2_async_notifier *notifier,
673673
}
674674
EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_fwnode_subdev);
675675

676-
int
676+
struct v4l2_async_subdev *
677677
v4l2_async_notifier_add_fwnode_remote_subdev(struct v4l2_async_notifier *notif,
678678
struct fwnode_handle *endpoint,
679-
struct v4l2_async_subdev *asd)
679+
unsigned int asd_struct_size)
680680
{
681+
struct v4l2_async_subdev *asd;
681682
struct fwnode_handle *remote;
682-
int ret;
683683

684684
remote = fwnode_graph_get_remote_port_parent(endpoint);
685685
if (!remote)
686-
return -ENOTCONN;
686+
return ERR_PTR(-ENOTCONN);
687687

688-
asd->match_type = V4L2_ASYNC_MATCH_FWNODE;
689-
asd->match.fwnode = remote;
690-
691-
ret = v4l2_async_notifier_add_subdev(notif, asd);
692-
if (ret)
693-
fwnode_handle_put(remote);
694-
695-
return ret;
688+
asd = v4l2_async_notifier_add_fwnode_subdev(notif, remote,
689+
asd_struct_size);
690+
/*
691+
* Calling v4l2_async_notifier_add_fwnode_subdev grabs a refcount,
692+
* so drop the one we got in fwnode_graph_get_remote_port_parent.
693+
*/
694+
fwnode_handle_put(remote);
695+
return asd;
696696
}
697697
EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_fwnode_remote_subdev);
698698

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,19 +1942,13 @@ static int imx_csi_async_register(struct csi_priv *priv)
19421942
port, 0,
19431943
FWNODE_GRAPH_ENDPOINT_NEXT);
19441944
if (ep) {
1945-
asd = kzalloc(sizeof(*asd), GFP_KERNEL);
1946-
if (!asd) {
1947-
fwnode_handle_put(ep);
1948-
return -ENOMEM;
1949-
}
1950-
1951-
ret = v4l2_async_notifier_add_fwnode_remote_subdev(
1952-
&priv->notifier, ep, asd);
1945+
asd = v4l2_async_notifier_add_fwnode_remote_subdev(
1946+
&priv->notifier, ep, sizeof(*asd));
19531947

19541948
fwnode_handle_put(ep);
19551949

1956-
if (ret) {
1957-
kfree(asd);
1950+
if (IS_ERR(asd)) {
1951+
ret = PTR_ERR(asd);
19581952
/* OK if asd already exists */
19591953
if (ret != -EEXIST)
19601954
return ret;

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ static int csi2_async_register(struct csi2_dev *csi2)
557557
struct v4l2_fwnode_endpoint vep = {
558558
.bus_type = V4L2_MBUS_CSI2_DPHY,
559559
};
560-
struct v4l2_async_subdev *asd = NULL;
560+
struct v4l2_async_subdev *asd;
561561
struct fwnode_handle *ep;
562562
int ret;
563563

@@ -577,19 +577,13 @@ static int csi2_async_register(struct csi2_dev *csi2)
577577
dev_dbg(csi2->dev, "data lanes: %d\n", csi2->bus.num_data_lanes);
578578
dev_dbg(csi2->dev, "flags: 0x%08x\n", csi2->bus.flags);
579579

580-
asd = kzalloc(sizeof(*asd), GFP_KERNEL);
581-
if (!asd) {
582-
ret = -ENOMEM;
583-
goto err_parse;
584-
}
585-
586-
ret = v4l2_async_notifier_add_fwnode_remote_subdev(
587-
&csi2->notifier, ep, asd);
588-
if (ret)
589-
goto err_parse;
590-
580+
asd = v4l2_async_notifier_add_fwnode_remote_subdev(
581+
&csi2->notifier, ep, sizeof(*asd));
591582
fwnode_handle_put(ep);
592583

584+
if (IS_ERR(asd))
585+
return PTR_ERR(asd);
586+
593587
csi2->notifier.ops = &csi2_notify_ops;
594588

595589
ret = v4l2_async_subdev_notifier_register(&csi2->sd,
@@ -601,7 +595,6 @@ static int csi2_async_register(struct csi2_dev *csi2)
601595

602596
err_parse:
603597
fwnode_handle_put(ep);
604-
kfree(asd);
605598
return ret;
606599
}
607600

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ static const struct v4l2_async_notifier_operations imx7_csi_notify_ops = {
11911191

11921192
static int imx7_csi_async_register(struct imx7_csi *csi)
11931193
{
1194-
struct v4l2_async_subdev *asd = NULL;
1194+
struct v4l2_async_subdev *asd;
11951195
struct fwnode_handle *ep;
11961196
int ret;
11971197

@@ -1200,19 +1200,13 @@ static int imx7_csi_async_register(struct imx7_csi *csi)
12001200
ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(csi->dev), 0, 0,
12011201
FWNODE_GRAPH_ENDPOINT_NEXT);
12021202
if (ep) {
1203-
asd = kzalloc(sizeof(*asd), GFP_KERNEL);
1204-
if (!asd) {
1205-
fwnode_handle_put(ep);
1206-
return -ENOMEM;
1207-
}
1208-
1209-
ret = v4l2_async_notifier_add_fwnode_remote_subdev(
1210-
&csi->notifier, ep, asd);
1203+
asd = v4l2_async_notifier_add_fwnode_remote_subdev(
1204+
&csi->notifier, ep, sizeof(*asd));
12111205

12121206
fwnode_handle_put(ep);
12131207

1214-
if (ret) {
1215-
kfree(asd);
1208+
if (IS_ERR(asd)) {
1209+
ret = PTR_ERR(asd);
12161210
/* OK if asd already exists */
12171211
if (ret != -EEXIST)
12181212
return ret;

‎drivers/staging/media/imx/imx7-mipi-csis.c‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ static int mipi_csis_async_register(struct csi_state *state)
10061006
struct v4l2_fwnode_endpoint vep = {
10071007
.bus_type = V4L2_MBUS_CSI2_DPHY,
10081008
};
1009-
struct v4l2_async_subdev *asd = NULL;
1009+
struct v4l2_async_subdev *asd;
10101010
struct fwnode_handle *ep;
10111011
int ret;
10121012

@@ -1026,17 +1026,13 @@ static int mipi_csis_async_register(struct csi_state *state)
10261026
dev_dbg(state->dev, "data lanes: %d\n", state->bus.num_data_lanes);
10271027
dev_dbg(state->dev, "flags: 0x%08x\n", state->bus.flags);
10281028

1029-
asd = kzalloc(sizeof(*asd), GFP_KERNEL);
1030-
if (!asd) {
1031-
ret = -ENOMEM;
1029+
asd = v4l2_async_notifier_add_fwnode_remote_subdev(
1030+
&state->notifier, ep, sizeof(*asd));
1031+
if (IS_ERR(asd)) {
1032+
ret = PTR_ERR(asd);
10321033
goto err_parse;
10331034
}
10341035

1035-
ret = v4l2_async_notifier_add_fwnode_remote_subdev(
1036-
&state->notifier, ep, asd);
1037-
if (ret)
1038-
goto err_parse;
1039-
10401036
fwnode_handle_put(ep);
10411037

10421038
state->notifier.ops = &mipi_csis_notify_ops;
@@ -1050,7 +1046,6 @@ static int mipi_csis_async_register(struct csi_state *state)
10501046

10511047
err_parse:
10521048
fwnode_handle_put(ep);
1053-
kfree(asd);
10541049

10551050
return ret;
10561051
}

0 commit comments

Comments
 (0)