Skip to content

Commit 8857e46

Browse files
Sakari Ailusrkhuangtao
authored andcommitted
FROMLIST: v4l: async: Prepare for async sub-device notifiers
Refactor the V4L2 async framework a little in preparation for async sub-device notifiers. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> (cherry picked from commit b0a3d090cf6c1f793758b5c900169f11e29669e1) 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: Id6ea225545d16192ca8f6c10f99415b6bf4f22f0 Reviewed-on: https://chromium-review.googlesource.com/693694 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 5013058 commit 8857e46

1 file changed

Lines changed: 47 additions & 19 deletions

File tree

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

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,13 @@ static struct v4l2_async_subdev *v4l2_async_find_match(
129129
}
130130

131131
static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,
132+
struct v4l2_device *v4l2_dev,
132133
struct v4l2_subdev *sd,
133134
struct v4l2_async_subdev *asd)
134135
{
135136
int ret;
136137

137-
ret = v4l2_device_register_subdev(notifier->v4l2_dev, sd);
138+
ret = v4l2_device_register_subdev(v4l2_dev, sd);
138139
if (ret < 0)
139140
return ret;
140141

@@ -158,6 +159,31 @@ static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,
158159
return 0;
159160
}
160161

162+
/* Test all async sub-devices in a notifier for a match. */
163+
static int v4l2_async_notifier_try_all_subdevs(
164+
struct v4l2_async_notifier *notifier)
165+
{
166+
struct v4l2_device *v4l2_dev = notifier->v4l2_dev;
167+
struct v4l2_subdev *sd, *tmp;
168+
169+
list_for_each_entry_safe(sd, tmp, &subdev_list, async_list) {
170+
struct v4l2_async_subdev *asd;
171+
int ret;
172+
173+
asd = v4l2_async_find_match(notifier, sd);
174+
if (!asd)
175+
continue;
176+
177+
ret = v4l2_async_match_notify(notifier, v4l2_dev, sd, asd);
178+
if (ret < 0) {
179+
mutex_unlock(&list_lock);
180+
return ret;
181+
}
182+
}
183+
184+
return 0;
185+
}
186+
161187
static void v4l2_async_cleanup(struct v4l2_subdev *sd)
162188
{
163189
v4l2_device_unregister_subdev(sd);
@@ -167,17 +193,15 @@ static void v4l2_async_cleanup(struct v4l2_subdev *sd)
167193
sd->dev = NULL;
168194
}
169195

170-
int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
171-
struct v4l2_async_notifier *notifier)
196+
static int __v4l2_async_notifier_register(struct v4l2_async_notifier *notifier)
172197
{
173-
struct v4l2_subdev *sd, *tmp;
174198
struct v4l2_async_subdev *asd;
199+
int ret;
175200
int i;
176201

177-
if (!v4l2_dev || notifier->num_subdevs > V4L2_MAX_SUBDEVS)
202+
if (notifier->num_subdevs > V4L2_MAX_SUBDEVS)
178203
return -EINVAL;
179204

180-
notifier->v4l2_dev = v4l2_dev;
181205
INIT_LIST_HEAD(&notifier->waiting);
182206
INIT_LIST_HEAD(&notifier->done);
183207

@@ -210,18 +234,10 @@ int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
210234

211235
mutex_lock(&list_lock);
212236

213-
list_for_each_entry_safe(sd, tmp, &subdev_list, async_list) {
214-
int ret;
215-
216-
asd = v4l2_async_find_match(notifier, sd);
217-
if (!asd)
218-
continue;
219-
220-
ret = v4l2_async_match_notify(notifier, sd, asd);
221-
if (ret < 0) {
222-
mutex_unlock(&list_lock);
223-
return ret;
224-
}
237+
ret = v4l2_async_notifier_try_all_subdevs(notifier);
238+
if (ret) {
239+
mutex_unlock(&list_lock);
240+
return ret;
225241
}
226242

227243
/* Keep also completed notifiers on the list */
@@ -231,6 +247,17 @@ int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
231247

232248
return 0;
233249
}
250+
251+
int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
252+
struct v4l2_async_notifier *notifier)
253+
{
254+
if (WARN_ON(!v4l2_dev))
255+
return -EINVAL;
256+
257+
notifier->v4l2_dev = v4l2_dev;
258+
259+
return __v4l2_async_notifier_register(notifier);
260+
}
234261
EXPORT_SYMBOL(v4l2_async_notifier_register);
235262

236263
void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier)
@@ -307,7 +334,8 @@ int v4l2_async_register_subdev(struct v4l2_subdev *sd)
307334
struct v4l2_async_subdev *asd = v4l2_async_find_match(notifier,
308335
sd);
309336
if (asd) {
310-
int ret = v4l2_async_match_notify(notifier, sd, asd);
337+
int ret = v4l2_async_match_notify(
338+
notifier, notifier->v4l2_dev, sd, asd);
311339
mutex_unlock(&list_lock);
312340
return ret;
313341
}

0 commit comments

Comments
 (0)