Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / media / v4l2-core / v4l2-async.c
blobe3ab003a6c851881475e2c77ada44482c6e7e0d2
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * V4L2 asynchronous subdevice registration API
5 * Copyright (C) 2012-2013, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
6 */
8 #include <linux/device.h>
9 #include <linux/err.h>
10 #include <linux/i2c.h>
11 #include <linux/list.h>
12 #include <linux/mm.h>
13 #include <linux/module.h>
14 #include <linux/mutex.h>
15 #include <linux/of.h>
16 #include <linux/platform_device.h>
17 #include <linux/slab.h>
18 #include <linux/types.h>
20 #include <media/v4l2-async.h>
21 #include <media/v4l2-device.h>
22 #include <media/v4l2-fwnode.h>
23 #include <media/v4l2-subdev.h>
25 static int v4l2_async_notifier_call_bound(struct v4l2_async_notifier *n,
26 struct v4l2_subdev *subdev,
27 struct v4l2_async_subdev *asd)
29 if (!n->ops || !n->ops->bound)
30 return 0;
32 return n->ops->bound(n, subdev, asd);
35 static void v4l2_async_notifier_call_unbind(struct v4l2_async_notifier *n,
36 struct v4l2_subdev *subdev,
37 struct v4l2_async_subdev *asd)
39 if (!n->ops || !n->ops->unbind)
40 return;
42 n->ops->unbind(n, subdev, asd);
45 static int v4l2_async_notifier_call_complete(struct v4l2_async_notifier *n)
47 if (!n->ops || !n->ops->complete)
48 return 0;
50 return n->ops->complete(n);
53 static bool match_i2c(struct v4l2_async_notifier *notifier,
54 struct v4l2_subdev *sd, struct v4l2_async_subdev *asd)
56 #if IS_ENABLED(CONFIG_I2C)
57 struct i2c_client *client = i2c_verify_client(sd->dev);
59 return client &&
60 asd->match.i2c.adapter_id == client->adapter->nr &&
61 asd->match.i2c.address == client->addr;
62 #else
63 return false;
64 #endif
67 static bool match_devname(struct v4l2_async_notifier *notifier,
68 struct v4l2_subdev *sd, struct v4l2_async_subdev *asd)
70 return !strcmp(asd->match.device_name, dev_name(sd->dev));
73 static bool match_fwnode(struct v4l2_async_notifier *notifier,
74 struct v4l2_subdev *sd, struct v4l2_async_subdev *asd)
76 struct fwnode_handle *other_fwnode;
77 struct fwnode_handle *dev_fwnode;
78 bool asd_fwnode_is_ep;
79 bool sd_fwnode_is_ep;
80 struct device *dev;
83 * Both the subdev and the async subdev can provide either an endpoint
84 * fwnode or a device fwnode. Start with the simple case of direct
85 * fwnode matching.
87 if (sd->fwnode == asd->match.fwnode)
88 return true;
91 * Otherwise, check if the sd fwnode and the asd fwnode refer to an
92 * endpoint or a device. If they're of the same type, there's no match.
93 * Technically speaking this checks if the nodes refer to a connected
94 * endpoint, which is the simplest check that works for both OF and
95 * ACPI. This won't make a difference, as drivers should not try to
96 * match unconnected endpoints.
98 sd_fwnode_is_ep = fwnode_graph_is_endpoint(sd->fwnode);
99 asd_fwnode_is_ep = fwnode_graph_is_endpoint(asd->match.fwnode);
101 if (sd_fwnode_is_ep == asd_fwnode_is_ep)
102 return false;
105 * The sd and asd fwnodes are of different types. Get the device fwnode
106 * parent of the endpoint fwnode, and compare it with the other fwnode.
108 if (sd_fwnode_is_ep) {
109 dev_fwnode = fwnode_graph_get_port_parent(sd->fwnode);
110 other_fwnode = asd->match.fwnode;
111 } else {
112 dev_fwnode = fwnode_graph_get_port_parent(asd->match.fwnode);
113 other_fwnode = sd->fwnode;
116 fwnode_handle_put(dev_fwnode);
118 if (dev_fwnode != other_fwnode)
119 return false;
122 * We have a heterogeneous match. Retrieve the struct device of the side
123 * that matched on a device fwnode to print its driver name.
125 if (sd_fwnode_is_ep)
126 dev = notifier->v4l2_dev ? notifier->v4l2_dev->dev
127 : notifier->sd->dev;
128 else
129 dev = sd->dev;
131 if (dev && dev->driver) {
132 if (sd_fwnode_is_ep)
133 dev_warn(dev, "Driver %s uses device fwnode, incorrect match may occur\n",
134 dev->driver->name);
135 dev_notice(dev, "Consider updating driver %s to match on endpoints\n",
136 dev->driver->name);
139 return true;
142 static bool match_custom(struct v4l2_async_notifier *notifier,
143 struct v4l2_subdev *sd, struct v4l2_async_subdev *asd)
145 if (!asd->match.custom.match)
146 /* Match always */
147 return true;
149 return asd->match.custom.match(sd->dev, asd);
152 static LIST_HEAD(subdev_list);
153 static LIST_HEAD(notifier_list);
154 static DEFINE_MUTEX(list_lock);
156 static struct v4l2_async_subdev *
157 v4l2_async_find_match(struct v4l2_async_notifier *notifier,
158 struct v4l2_subdev *sd)
160 bool (*match)(struct v4l2_async_notifier *notifier,
161 struct v4l2_subdev *sd, struct v4l2_async_subdev *asd);
162 struct v4l2_async_subdev *asd;
164 list_for_each_entry(asd, &notifier->waiting, list) {
165 /* bus_type has been verified valid before */
166 switch (asd->match_type) {
167 case V4L2_ASYNC_MATCH_CUSTOM:
168 match = match_custom;
169 break;
170 case V4L2_ASYNC_MATCH_DEVNAME:
171 match = match_devname;
172 break;
173 case V4L2_ASYNC_MATCH_I2C:
174 match = match_i2c;
175 break;
176 case V4L2_ASYNC_MATCH_FWNODE:
177 match = match_fwnode;
178 break;
179 default:
180 /* Cannot happen, unless someone breaks us */
181 WARN_ON(true);
182 return NULL;
185 /* match cannot be NULL here */
186 if (match(notifier, sd, asd))
187 return asd;
190 return NULL;
193 /* Compare two async sub-device descriptors for equivalence */
194 static bool asd_equal(struct v4l2_async_subdev *asd_x,
195 struct v4l2_async_subdev *asd_y)
197 if (asd_x->match_type != asd_y->match_type)
198 return false;
200 switch (asd_x->match_type) {
201 case V4L2_ASYNC_MATCH_DEVNAME:
202 return strcmp(asd_x->match.device_name,
203 asd_y->match.device_name) == 0;
204 case V4L2_ASYNC_MATCH_I2C:
205 return asd_x->match.i2c.adapter_id ==
206 asd_y->match.i2c.adapter_id &&
207 asd_x->match.i2c.address ==
208 asd_y->match.i2c.address;
209 case V4L2_ASYNC_MATCH_FWNODE:
210 return asd_x->match.fwnode == asd_y->match.fwnode;
211 default:
212 break;
215 return false;
218 /* Find the sub-device notifier registered by a sub-device driver. */
219 static struct v4l2_async_notifier *
220 v4l2_async_find_subdev_notifier(struct v4l2_subdev *sd)
222 struct v4l2_async_notifier *n;
224 list_for_each_entry(n, &notifier_list, list)
225 if (n->sd == sd)
226 return n;
228 return NULL;
231 /* Get v4l2_device related to the notifier if one can be found. */
232 static struct v4l2_device *
233 v4l2_async_notifier_find_v4l2_dev(struct v4l2_async_notifier *notifier)
235 while (notifier->parent)
236 notifier = notifier->parent;
238 return notifier->v4l2_dev;
242 * Return true if all child sub-device notifiers are complete, false otherwise.
244 static bool
245 v4l2_async_notifier_can_complete(struct v4l2_async_notifier *notifier)
247 struct v4l2_subdev *sd;
249 if (!list_empty(&notifier->waiting))
250 return false;
252 list_for_each_entry(sd, &notifier->done, async_list) {
253 struct v4l2_async_notifier *subdev_notifier =
254 v4l2_async_find_subdev_notifier(sd);
256 if (subdev_notifier &&
257 !v4l2_async_notifier_can_complete(subdev_notifier))
258 return false;
261 return true;
265 * Complete the master notifier if possible. This is done when all async
266 * sub-devices have been bound; v4l2_device is also available then.
268 static int
269 v4l2_async_notifier_try_complete(struct v4l2_async_notifier *notifier)
271 /* Quick check whether there are still more sub-devices here. */
272 if (!list_empty(&notifier->waiting))
273 return 0;
275 /* Check the entire notifier tree; find the root notifier first. */
276 while (notifier->parent)
277 notifier = notifier->parent;
279 /* This is root if it has v4l2_dev. */
280 if (!notifier->v4l2_dev)
281 return 0;
283 /* Is everything ready? */
284 if (!v4l2_async_notifier_can_complete(notifier))
285 return 0;
287 return v4l2_async_notifier_call_complete(notifier);
290 static int
291 v4l2_async_notifier_try_all_subdevs(struct v4l2_async_notifier *notifier);
293 static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,
294 struct v4l2_device *v4l2_dev,
295 struct v4l2_subdev *sd,
296 struct v4l2_async_subdev *asd)
298 struct v4l2_async_notifier *subdev_notifier;
299 int ret;
301 ret = v4l2_device_register_subdev(v4l2_dev, sd);
302 if (ret < 0)
303 return ret;
305 ret = v4l2_async_notifier_call_bound(notifier, sd, asd);
306 if (ret < 0) {
307 v4l2_device_unregister_subdev(sd);
308 return ret;
311 /* Remove from the waiting list */
312 list_del(&asd->list);
313 sd->asd = asd;
314 sd->notifier = notifier;
316 /* Move from the global subdevice list to notifier's done */
317 list_move(&sd->async_list, &notifier->done);
320 * See if the sub-device has a notifier. If not, return here.
322 subdev_notifier = v4l2_async_find_subdev_notifier(sd);
323 if (!subdev_notifier || subdev_notifier->parent)
324 return 0;
327 * Proceed with checking for the sub-device notifier's async
328 * sub-devices, and return the result. The error will be handled by the
329 * caller.
331 subdev_notifier->parent = notifier;
333 return v4l2_async_notifier_try_all_subdevs(subdev_notifier);
336 /* Test all async sub-devices in a notifier for a match. */
337 static int
338 v4l2_async_notifier_try_all_subdevs(struct v4l2_async_notifier *notifier)
340 struct v4l2_device *v4l2_dev =
341 v4l2_async_notifier_find_v4l2_dev(notifier);
342 struct v4l2_subdev *sd;
344 if (!v4l2_dev)
345 return 0;
347 again:
348 list_for_each_entry(sd, &subdev_list, async_list) {
349 struct v4l2_async_subdev *asd;
350 int ret;
352 asd = v4l2_async_find_match(notifier, sd);
353 if (!asd)
354 continue;
356 ret = v4l2_async_match_notify(notifier, v4l2_dev, sd, asd);
357 if (ret < 0)
358 return ret;
361 * v4l2_async_match_notify() may lead to registering a
362 * new notifier and thus changing the async subdevs
363 * list. In order to proceed safely from here, restart
364 * parsing the list from the beginning.
366 goto again;
369 return 0;
372 static void v4l2_async_cleanup(struct v4l2_subdev *sd)
374 v4l2_device_unregister_subdev(sd);
376 * Subdevice driver will reprobe and put the subdev back
377 * onto the list
379 list_del_init(&sd->async_list);
380 sd->asd = NULL;
383 /* Unbind all sub-devices in the notifier tree. */
384 static void
385 v4l2_async_notifier_unbind_all_subdevs(struct v4l2_async_notifier *notifier)
387 struct v4l2_subdev *sd, *tmp;
389 list_for_each_entry_safe(sd, tmp, &notifier->done, async_list) {
390 struct v4l2_async_notifier *subdev_notifier =
391 v4l2_async_find_subdev_notifier(sd);
393 if (subdev_notifier)
394 v4l2_async_notifier_unbind_all_subdevs(subdev_notifier);
396 v4l2_async_notifier_call_unbind(notifier, sd, sd->asd);
397 v4l2_async_cleanup(sd);
399 list_move(&sd->async_list, &subdev_list);
402 notifier->parent = NULL;
405 /* See if an async sub-device can be found in a notifier's lists. */
406 static bool
407 __v4l2_async_notifier_has_async_subdev(struct v4l2_async_notifier *notifier,
408 struct v4l2_async_subdev *asd)
410 struct v4l2_async_subdev *asd_y;
411 struct v4l2_subdev *sd;
413 list_for_each_entry(asd_y, &notifier->waiting, list)
414 if (asd_equal(asd, asd_y))
415 return true;
417 list_for_each_entry(sd, &notifier->done, async_list) {
418 if (WARN_ON(!sd->asd))
419 continue;
421 if (asd_equal(asd, sd->asd))
422 return true;
425 return false;
429 * Find out whether an async sub-device was set up already or
430 * whether it exists in a given notifier before @this_index.
431 * If @this_index < 0, search the notifier's entire @asd_list.
433 static bool
434 v4l2_async_notifier_has_async_subdev(struct v4l2_async_notifier *notifier,
435 struct v4l2_async_subdev *asd,
436 int this_index)
438 struct v4l2_async_subdev *asd_y;
439 int j = 0;
441 lockdep_assert_held(&list_lock);
443 /* Check that an asd is not being added more than once. */
444 list_for_each_entry(asd_y, &notifier->asd_list, asd_list) {
445 if (this_index >= 0 && j++ >= this_index)
446 break;
447 if (asd_equal(asd, asd_y))
448 return true;
451 /* Check that an asd does not exist in other notifiers. */
452 list_for_each_entry(notifier, &notifier_list, list)
453 if (__v4l2_async_notifier_has_async_subdev(notifier, asd))
454 return true;
456 return false;
459 static int v4l2_async_notifier_asd_valid(struct v4l2_async_notifier *notifier,
460 struct v4l2_async_subdev *asd,
461 int this_index)
463 struct device *dev =
464 notifier->v4l2_dev ? notifier->v4l2_dev->dev : NULL;
466 if (!asd)
467 return -EINVAL;
469 switch (asd->match_type) {
470 case V4L2_ASYNC_MATCH_CUSTOM:
471 case V4L2_ASYNC_MATCH_DEVNAME:
472 case V4L2_ASYNC_MATCH_I2C:
473 case V4L2_ASYNC_MATCH_FWNODE:
474 if (v4l2_async_notifier_has_async_subdev(notifier, asd,
475 this_index)) {
476 dev_dbg(dev, "subdev descriptor already listed in this or other notifiers\n");
477 return -EEXIST;
479 break;
480 default:
481 dev_err(dev, "Invalid match type %u on %p\n",
482 asd->match_type, asd);
483 return -EINVAL;
486 return 0;
489 void v4l2_async_notifier_init(struct v4l2_async_notifier *notifier)
491 INIT_LIST_HEAD(&notifier->asd_list);
493 EXPORT_SYMBOL(v4l2_async_notifier_init);
495 static int __v4l2_async_notifier_register(struct v4l2_async_notifier *notifier)
497 struct v4l2_async_subdev *asd;
498 int ret, i = 0;
500 INIT_LIST_HEAD(&notifier->waiting);
501 INIT_LIST_HEAD(&notifier->done);
503 mutex_lock(&list_lock);
505 list_for_each_entry(asd, &notifier->asd_list, asd_list) {
506 ret = v4l2_async_notifier_asd_valid(notifier, asd, i++);
507 if (ret)
508 goto err_unlock;
510 list_add_tail(&asd->list, &notifier->waiting);
513 ret = v4l2_async_notifier_try_all_subdevs(notifier);
514 if (ret < 0)
515 goto err_unbind;
517 ret = v4l2_async_notifier_try_complete(notifier);
518 if (ret < 0)
519 goto err_unbind;
521 /* Keep also completed notifiers on the list */
522 list_add(&notifier->list, &notifier_list);
524 mutex_unlock(&list_lock);
526 return 0;
528 err_unbind:
530 * On failure, unbind all sub-devices registered through this notifier.
532 v4l2_async_notifier_unbind_all_subdevs(notifier);
534 err_unlock:
535 mutex_unlock(&list_lock);
537 return ret;
540 int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
541 struct v4l2_async_notifier *notifier)
543 int ret;
545 if (WARN_ON(!v4l2_dev || notifier->sd))
546 return -EINVAL;
548 notifier->v4l2_dev = v4l2_dev;
550 ret = __v4l2_async_notifier_register(notifier);
551 if (ret)
552 notifier->v4l2_dev = NULL;
554 return ret;
556 EXPORT_SYMBOL(v4l2_async_notifier_register);
558 int v4l2_async_subdev_notifier_register(struct v4l2_subdev *sd,
559 struct v4l2_async_notifier *notifier)
561 int ret;
563 if (WARN_ON(!sd || notifier->v4l2_dev))
564 return -EINVAL;
566 notifier->sd = sd;
568 ret = __v4l2_async_notifier_register(notifier);
569 if (ret)
570 notifier->sd = NULL;
572 return ret;
574 EXPORT_SYMBOL(v4l2_async_subdev_notifier_register);
576 static void
577 __v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier)
579 if (!notifier || (!notifier->v4l2_dev && !notifier->sd))
580 return;
582 v4l2_async_notifier_unbind_all_subdevs(notifier);
584 notifier->sd = NULL;
585 notifier->v4l2_dev = NULL;
587 list_del(&notifier->list);
590 void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier)
592 mutex_lock(&list_lock);
594 __v4l2_async_notifier_unregister(notifier);
596 mutex_unlock(&list_lock);
598 EXPORT_SYMBOL(v4l2_async_notifier_unregister);
600 static void __v4l2_async_notifier_cleanup(struct v4l2_async_notifier *notifier)
602 struct v4l2_async_subdev *asd, *tmp;
604 if (!notifier || !notifier->asd_list.next)
605 return;
607 list_for_each_entry_safe(asd, tmp, &notifier->asd_list, asd_list) {
608 switch (asd->match_type) {
609 case V4L2_ASYNC_MATCH_FWNODE:
610 fwnode_handle_put(asd->match.fwnode);
611 break;
612 default:
613 break;
616 list_del(&asd->asd_list);
617 kfree(asd);
621 void v4l2_async_notifier_cleanup(struct v4l2_async_notifier *notifier)
623 mutex_lock(&list_lock);
625 __v4l2_async_notifier_cleanup(notifier);
627 mutex_unlock(&list_lock);
629 EXPORT_SYMBOL_GPL(v4l2_async_notifier_cleanup);
631 int v4l2_async_notifier_add_subdev(struct v4l2_async_notifier *notifier,
632 struct v4l2_async_subdev *asd)
634 int ret;
636 mutex_lock(&list_lock);
638 ret = v4l2_async_notifier_asd_valid(notifier, asd, -1);
639 if (ret)
640 goto unlock;
642 list_add_tail(&asd->asd_list, &notifier->asd_list);
644 unlock:
645 mutex_unlock(&list_lock);
646 return ret;
648 EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_subdev);
650 struct v4l2_async_subdev *
651 v4l2_async_notifier_add_fwnode_subdev(struct v4l2_async_notifier *notifier,
652 struct fwnode_handle *fwnode,
653 unsigned int asd_struct_size)
655 struct v4l2_async_subdev *asd;
656 int ret;
658 asd = kzalloc(asd_struct_size, GFP_KERNEL);
659 if (!asd)
660 return ERR_PTR(-ENOMEM);
662 asd->match_type = V4L2_ASYNC_MATCH_FWNODE;
663 asd->match.fwnode = fwnode_handle_get(fwnode);
665 ret = v4l2_async_notifier_add_subdev(notifier, asd);
666 if (ret) {
667 fwnode_handle_put(fwnode);
668 kfree(asd);
669 return ERR_PTR(ret);
672 return asd;
674 EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_fwnode_subdev);
677 v4l2_async_notifier_add_fwnode_remote_subdev(struct v4l2_async_notifier *notif,
678 struct fwnode_handle *endpoint,
679 struct v4l2_async_subdev *asd)
681 struct fwnode_handle *remote;
682 int ret;
684 remote = fwnode_graph_get_remote_port_parent(endpoint);
685 if (!remote)
686 return -ENOTCONN;
688 asd->match_type = V4L2_ASYNC_MATCH_FWNODE;
689 asd->match.fwnode = remote;
691 ret = v4l2_async_notifier_add_subdev(notif, asd);
692 if (ret)
693 fwnode_handle_put(remote);
695 return ret;
697 EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_fwnode_remote_subdev);
699 struct v4l2_async_subdev *
700 v4l2_async_notifier_add_i2c_subdev(struct v4l2_async_notifier *notifier,
701 int adapter_id, unsigned short address,
702 unsigned int asd_struct_size)
704 struct v4l2_async_subdev *asd;
705 int ret;
707 asd = kzalloc(asd_struct_size, GFP_KERNEL);
708 if (!asd)
709 return ERR_PTR(-ENOMEM);
711 asd->match_type = V4L2_ASYNC_MATCH_I2C;
712 asd->match.i2c.adapter_id = adapter_id;
713 asd->match.i2c.address = address;
715 ret = v4l2_async_notifier_add_subdev(notifier, asd);
716 if (ret) {
717 kfree(asd);
718 return ERR_PTR(ret);
721 return asd;
723 EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_i2c_subdev);
725 struct v4l2_async_subdev *
726 v4l2_async_notifier_add_devname_subdev(struct v4l2_async_notifier *notifier,
727 const char *device_name,
728 unsigned int asd_struct_size)
730 struct v4l2_async_subdev *asd;
731 int ret;
733 asd = kzalloc(asd_struct_size, GFP_KERNEL);
734 if (!asd)
735 return ERR_PTR(-ENOMEM);
737 asd->match_type = V4L2_ASYNC_MATCH_DEVNAME;
738 asd->match.device_name = device_name;
740 ret = v4l2_async_notifier_add_subdev(notifier, asd);
741 if (ret) {
742 kfree(asd);
743 return ERR_PTR(ret);
746 return asd;
748 EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_devname_subdev);
750 int v4l2_async_register_subdev(struct v4l2_subdev *sd)
752 struct v4l2_async_notifier *subdev_notifier;
753 struct v4l2_async_notifier *notifier;
754 int ret;
757 * No reference taken. The reference is held by the device
758 * (struct v4l2_subdev.dev), and async sub-device does not
759 * exist independently of the device at any point of time.
761 if (!sd->fwnode && sd->dev)
762 sd->fwnode = dev_fwnode(sd->dev);
764 mutex_lock(&list_lock);
766 INIT_LIST_HEAD(&sd->async_list);
768 list_for_each_entry(notifier, &notifier_list, list) {
769 struct v4l2_device *v4l2_dev =
770 v4l2_async_notifier_find_v4l2_dev(notifier);
771 struct v4l2_async_subdev *asd;
773 if (!v4l2_dev)
774 continue;
776 asd = v4l2_async_find_match(notifier, sd);
777 if (!asd)
778 continue;
780 ret = v4l2_async_match_notify(notifier, v4l2_dev, sd, asd);
781 if (ret)
782 goto err_unbind;
784 ret = v4l2_async_notifier_try_complete(notifier);
785 if (ret)
786 goto err_unbind;
788 goto out_unlock;
791 /* None matched, wait for hot-plugging */
792 list_add(&sd->async_list, &subdev_list);
794 out_unlock:
795 mutex_unlock(&list_lock);
797 return 0;
799 err_unbind:
801 * Complete failed. Unbind the sub-devices bound through registering
802 * this async sub-device.
804 subdev_notifier = v4l2_async_find_subdev_notifier(sd);
805 if (subdev_notifier)
806 v4l2_async_notifier_unbind_all_subdevs(subdev_notifier);
808 if (sd->asd)
809 v4l2_async_notifier_call_unbind(notifier, sd, sd->asd);
810 v4l2_async_cleanup(sd);
812 mutex_unlock(&list_lock);
814 return ret;
816 EXPORT_SYMBOL(v4l2_async_register_subdev);
818 void v4l2_async_unregister_subdev(struct v4l2_subdev *sd)
820 mutex_lock(&list_lock);
822 __v4l2_async_notifier_unregister(sd->subdev_notifier);
823 __v4l2_async_notifier_cleanup(sd->subdev_notifier);
824 kfree(sd->subdev_notifier);
825 sd->subdev_notifier = NULL;
827 if (sd->asd) {
828 struct v4l2_async_notifier *notifier = sd->notifier;
830 list_add(&sd->asd->list, &notifier->waiting);
832 v4l2_async_notifier_call_unbind(notifier, sd, sd->asd);
835 v4l2_async_cleanup(sd);
837 mutex_unlock(&list_lock);
839 EXPORT_SYMBOL(v4l2_async_unregister_subdev);