Skip to content

Commit 8c73730

Browse files
Sakari Ailusrkhuangtao
authored andcommitted
FROMLIST: v4l: async: Introduce helpers for calling async ops callbacks
Add three helper functions to call async operations callbacks. Besides simplifying callbacks, this allows async notifiers to have no ops set, i.e. it can be left NULL. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Acked-by: Pavel Machek <pavel@ucw.cz> (cherry picked from commit 6b4257572d7443669a1f83c6f90c2b43620fba6c) https://git.linuxtv.org/sailus/media_tree.git/log/?h=010f7f4393fd http://www.spinics.net/lists/linux-media/msg122688.html Signed-off-by: Marc Herbert <marc.herbert@intel.com> BUG=b:64133998 TEST=media device topology shows subdevs registered successfully TEST=no camera regression Change-Id: I2cb3051601dc068f60dc2072fb9b9a65b916d0a4 Reviewed-on: https://chromium-review.googlesource.com/693690 Commit-Ready: Tomasz Figa <tfiga@chromium.org> Tested-by: Hyungwoo Yang <hyungwoo.yang@intel.com> Reviewed-by: Tomasz Figa <tfiga@chromium.org> Signed-off-by: Jacob Chen <jacob2.chen@rock-chips.com>
1 parent 5e744b2 commit 8c73730

2 files changed

Lines changed: 37 additions & 13 deletions

File tree

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

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,34 @@
2424
#include <media/v4l2-fwnode.h>
2525
#include <media/v4l2-subdev.h>
2626

27+
static int v4l2_async_notifier_call_bound(struct v4l2_async_notifier *n,
28+
struct v4l2_subdev *subdev,
29+
struct v4l2_async_subdev *asd)
30+
{
31+
if (!n->ops || !n->ops->bound)
32+
return 0;
33+
34+
return n->ops->bound(n, subdev, asd);
35+
}
36+
37+
static void v4l2_async_notifier_call_unbind(struct v4l2_async_notifier *n,
38+
struct v4l2_subdev *subdev,
39+
struct v4l2_async_subdev *asd)
40+
{
41+
if (!n->ops || !n->ops->unbind)
42+
return;
43+
44+
n->ops->unbind(n, subdev, asd);
45+
}
46+
47+
static int v4l2_async_notifier_call_complete(struct v4l2_async_notifier *n)
48+
{
49+
if (!n->ops || !n->ops->complete)
50+
return 0;
51+
52+
return n->ops->complete(n);
53+
}
54+
2755
static bool match_i2c(struct v4l2_subdev *sd, struct v4l2_async_subdev *asd)
2856
{
2957
#if IS_ENABLED(CONFIG_I2C)
@@ -106,16 +134,13 @@ static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,
106134
{
107135
int ret;
108136

109-
if (notifier->ops->bound) {
110-
ret = notifier->ops->bound(notifier, sd, asd);
111-
if (ret < 0)
112-
return ret;
113-
}
137+
ret = v4l2_async_notifier_call_bound(notifier, sd, asd);
138+
if (ret < 0)
139+
return ret;
114140

115141
ret = v4l2_device_register_subdev(notifier->v4l2_dev, sd);
116142
if (ret < 0) {
117-
if (notifier->ops->unbind)
118-
notifier->ops->unbind(notifier, sd, asd);
143+
v4l2_async_notifier_call_unbind(notifier, sd, asd);
119144
return ret;
120145
}
121146

@@ -127,8 +152,8 @@ static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,
127152
/* Move from the global subdevice list to notifier's done */
128153
list_move(&sd->async_list, &notifier->done);
129154

130-
if (list_empty(&notifier->waiting) && notifier->ops->complete)
131-
return notifier->ops->complete(notifier);
155+
if (list_empty(&notifier->waiting))
156+
return v4l2_async_notifier_call_complete(notifier);
132157

133158
return 0;
134159
}
@@ -214,8 +239,7 @@ void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier)
214239
list_for_each_entry_safe(sd, tmp, &notifier->done, async_list) {
215240
v4l2_async_cleanup(sd);
216241

217-
if (notifier->ops->unbind)
218-
notifier->ops->unbind(notifier, sd, sd->asd);
242+
v4l2_async_notifier_call_unbind(notifier, sd, sd->asd);
219243

220244
list_move(&sd->async_list, &subdev_list);
221245
}
@@ -306,8 +330,7 @@ void v4l2_async_unregister_subdev(struct v4l2_subdev *sd)
306330

307331
v4l2_async_cleanup(sd);
308332

309-
if (notifier->ops->unbind)
310-
notifier->ops->unbind(notifier, sd, sd->asd);
333+
v4l2_async_notifier_call_unbind(notifier, sd, sd->asd);
311334

312335
mutex_unlock(&list_lock);
313336
}

include/media/v4l2-async.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,5 @@ int v4l2_async_register_subdev(struct v4l2_subdev *sd);
164164
* @sd: pointer to &struct v4l2_subdev
165165
*/
166166
void v4l2_async_unregister_subdev(struct v4l2_subdev *sd);
167+
167168
#endif

0 commit comments

Comments
 (0)