2019-06-04 16:11:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2013-01-08 18:06:31 +08:00
|
|
|
/*
|
|
|
|
* V4L2 asynchronous subdevice registration API
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012-2013, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
|
|
|
|
*/
|
|
|
|
|
2021-01-09 01:17:28 +08:00
|
|
|
#include <linux/debugfs.h>
|
2013-01-08 18:06:31 +08:00
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/list.h>
|
[media] v4l2-core: Use kvmalloc() for potentially big allocations
There are multiple places where arrays or otherwise variable sized
buffer are allocated through V4L2 core code, including things like
controls, memory pages, staging buffers for ioctls and so on. Such
allocations can potentially require an order > 0 allocation from the
page allocator, which is not guaranteed to be fulfilled and is likely to
fail on a system with severe memory fragmentation (e.g. a system with
very long uptime).
Since the memory being allocated is intended to be used by the CPU
exclusively, we can consider using vmalloc() as a fallback and this is
exactly what the recently merged kvmalloc() helpers do. A kmalloc() call
is still attempted, even for order > 0 allocations, but it is done
with __GFP_NORETRY and __GFP_NOWARN, with expectation of failing if
requested memory is not available instantly. Only then the vmalloc()
fallback is used. This should give us fast and more reliable allocations
even on systems with higher memory pressure and/or more fragmentation,
while still retaining the same performance level on systems not
suffering from such conditions.
While at it, replace explicit array size calculations on changed
allocations with kvmalloc_array().
Purposedly not touching videobuf1, as it is deprecated, has only few
users remaining and would rather be seen removed instead.
Signed-off-by: Tomasz Figa <tfiga@chromium.org>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-06-19 11:53:43 +08:00
|
|
|
#include <linux/mm.h>
|
2013-01-08 18:06:31 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/mutex.h>
|
2016-08-16 17:54:59 +08:00
|
|
|
#include <linux/of.h>
|
2013-01-08 18:06:31 +08:00
|
|
|
#include <linux/platform_device.h>
|
2021-01-09 01:17:28 +08:00
|
|
|
#include <linux/seq_file.h>
|
2013-01-08 18:06:31 +08:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
|
|
|
|
#include <media/v4l2-async.h>
|
|
|
|
#include <media/v4l2-device.h>
|
2017-08-17 23:28:21 +08:00
|
|
|
#include <media/v4l2-fwnode.h>
|
2013-01-08 18:06:31 +08:00
|
|
|
#include <media/v4l2-subdev.h>
|
|
|
|
|
2023-01-28 04:37:25 +08:00
|
|
|
#include "v4l2-subdev-priv.h"
|
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
static int v4l2_async_nf_call_bound(struct v4l2_async_notifier *n,
|
|
|
|
struct v4l2_subdev *subdev,
|
|
|
|
struct v4l2_async_subdev *asd)
|
2017-09-01 20:27:32 +08:00
|
|
|
{
|
|
|
|
if (!n->ops || !n->ops->bound)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return n->ops->bound(n, subdev, asd);
|
|
|
|
}
|
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
static void v4l2_async_nf_call_unbind(struct v4l2_async_notifier *n,
|
|
|
|
struct v4l2_subdev *subdev,
|
|
|
|
struct v4l2_async_subdev *asd)
|
2017-09-01 20:27:32 +08:00
|
|
|
{
|
|
|
|
if (!n->ops || !n->ops->unbind)
|
|
|
|
return;
|
|
|
|
|
|
|
|
n->ops->unbind(n, subdev, asd);
|
|
|
|
}
|
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
static int v4l2_async_nf_call_complete(struct v4l2_async_notifier *n)
|
2017-09-01 20:27:32 +08:00
|
|
|
{
|
|
|
|
if (!n->ops || !n->ops->complete)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return n->ops->complete(n);
|
|
|
|
}
|
|
|
|
|
2022-06-15 03:10:48 +08:00
|
|
|
static void v4l2_async_nf_call_destroy(struct v4l2_async_notifier *n,
|
|
|
|
struct v4l2_async_subdev *asd)
|
|
|
|
{
|
|
|
|
if (!n->ops || !n->ops->destroy)
|
|
|
|
return;
|
|
|
|
|
|
|
|
n->ops->destroy(asd);
|
|
|
|
}
|
|
|
|
|
2020-07-01 14:21:39 +08:00
|
|
|
static bool match_i2c(struct v4l2_async_notifier *notifier,
|
|
|
|
struct v4l2_subdev *sd, struct v4l2_async_subdev *asd)
|
2013-01-08 18:06:31 +08:00
|
|
|
{
|
2013-06-24 16:13:51 +08:00
|
|
|
#if IS_ENABLED(CONFIG_I2C)
|
2015-06-12 03:18:01 +08:00
|
|
|
struct i2c_client *client = i2c_verify_client(sd->dev);
|
2018-10-05 05:10:46 +08:00
|
|
|
|
2013-01-08 18:06:31 +08:00
|
|
|
return client &&
|
|
|
|
asd->match.i2c.adapter_id == client->adapter->nr &&
|
|
|
|
asd->match.i2c.address == client->addr;
|
2013-06-24 16:13:51 +08:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2013-01-08 18:06:31 +08:00
|
|
|
}
|
|
|
|
|
2022-07-06 01:40:54 +08:00
|
|
|
static bool
|
|
|
|
match_fwnode_one(struct v4l2_async_notifier *notifier,
|
|
|
|
struct v4l2_subdev *sd, struct fwnode_handle *sd_fwnode,
|
|
|
|
struct v4l2_async_subdev *asd)
|
2016-08-16 17:54:59 +08:00
|
|
|
{
|
2020-07-01 14:21:38 +08:00
|
|
|
struct fwnode_handle *other_fwnode;
|
|
|
|
struct fwnode_handle *dev_fwnode;
|
|
|
|
bool asd_fwnode_is_ep;
|
|
|
|
bool sd_fwnode_is_ep;
|
2020-07-01 14:21:40 +08:00
|
|
|
struct device *dev;
|
2020-07-01 14:21:38 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Both the subdev and the async subdev can provide either an endpoint
|
|
|
|
* fwnode or a device fwnode. Start with the simple case of direct
|
|
|
|
* fwnode matching.
|
|
|
|
*/
|
2022-07-06 01:40:54 +08:00
|
|
|
if (sd_fwnode == asd->match.fwnode)
|
2021-01-07 21:28:35 +08:00
|
|
|
return true;
|
|
|
|
|
2020-07-01 14:21:38 +08:00
|
|
|
/*
|
|
|
|
* Otherwise, check if the sd fwnode and the asd fwnode refer to an
|
|
|
|
* endpoint or a device. If they're of the same type, there's no match.
|
|
|
|
* Technically speaking this checks if the nodes refer to a connected
|
|
|
|
* endpoint, which is the simplest check that works for both OF and
|
|
|
|
* ACPI. This won't make a difference, as drivers should not try to
|
|
|
|
* match unconnected endpoints.
|
|
|
|
*/
|
2022-07-06 01:40:54 +08:00
|
|
|
sd_fwnode_is_ep = fwnode_graph_is_endpoint(sd_fwnode);
|
2020-07-01 14:21:38 +08:00
|
|
|
asd_fwnode_is_ep = fwnode_graph_is_endpoint(asd->match.fwnode);
|
|
|
|
|
|
|
|
if (sd_fwnode_is_ep == asd_fwnode_is_ep)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The sd and asd fwnodes are of different types. Get the device fwnode
|
|
|
|
* parent of the endpoint fwnode, and compare it with the other fwnode.
|
|
|
|
*/
|
|
|
|
if (sd_fwnode_is_ep) {
|
2022-07-06 01:40:54 +08:00
|
|
|
dev_fwnode = fwnode_graph_get_port_parent(sd_fwnode);
|
2020-07-01 14:21:38 +08:00
|
|
|
other_fwnode = asd->match.fwnode;
|
|
|
|
} else {
|
|
|
|
dev_fwnode = fwnode_graph_get_port_parent(asd->match.fwnode);
|
2022-07-06 01:40:54 +08:00
|
|
|
other_fwnode = sd_fwnode;
|
2020-07-01 14:21:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fwnode_handle_put(dev_fwnode);
|
|
|
|
|
2020-07-01 14:21:40 +08:00
|
|
|
if (dev_fwnode != other_fwnode)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have a heterogeneous match. Retrieve the struct device of the side
|
|
|
|
* that matched on a device fwnode to print its driver name.
|
|
|
|
*/
|
|
|
|
if (sd_fwnode_is_ep)
|
|
|
|
dev = notifier->v4l2_dev ? notifier->v4l2_dev->dev
|
|
|
|
: notifier->sd->dev;
|
|
|
|
else
|
|
|
|
dev = sd->dev;
|
|
|
|
|
|
|
|
if (dev && dev->driver) {
|
|
|
|
if (sd_fwnode_is_ep)
|
|
|
|
dev_warn(dev, "Driver %s uses device fwnode, incorrect match may occur\n",
|
|
|
|
dev->driver->name);
|
|
|
|
dev_notice(dev, "Consider updating driver %s to match on endpoints\n",
|
|
|
|
dev->driver->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2016-08-16 17:54:59 +08:00
|
|
|
}
|
|
|
|
|
2022-07-06 01:40:54 +08:00
|
|
|
static bool match_fwnode(struct v4l2_async_notifier *notifier,
|
|
|
|
struct v4l2_subdev *sd, struct v4l2_async_subdev *asd)
|
|
|
|
{
|
|
|
|
if (match_fwnode_one(notifier, sd, sd->fwnode, asd))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* Also check the secondary fwnode. */
|
|
|
|
if (IS_ERR_OR_NULL(sd->fwnode->secondary))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return match_fwnode_one(notifier, sd, sd->fwnode->secondary, asd);
|
|
|
|
}
|
|
|
|
|
2013-01-08 18:06:31 +08:00
|
|
|
static LIST_HEAD(subdev_list);
|
|
|
|
static LIST_HEAD(notifier_list);
|
|
|
|
static DEFINE_MUTEX(list_lock);
|
|
|
|
|
2018-10-05 05:10:46 +08:00
|
|
|
static struct v4l2_async_subdev *
|
|
|
|
v4l2_async_find_match(struct v4l2_async_notifier *notifier,
|
|
|
|
struct v4l2_subdev *sd)
|
2013-01-08 18:06:31 +08:00
|
|
|
{
|
2020-07-01 14:21:39 +08:00
|
|
|
bool (*match)(struct v4l2_async_notifier *notifier,
|
|
|
|
struct v4l2_subdev *sd, struct v4l2_async_subdev *asd);
|
2013-01-08 18:06:31 +08:00
|
|
|
struct v4l2_async_subdev *asd;
|
|
|
|
|
|
|
|
list_for_each_entry(asd, ¬ifier->waiting, list) {
|
|
|
|
/* bus_type has been verified valid before */
|
2013-07-19 23:14:46 +08:00
|
|
|
switch (asd->match_type) {
|
|
|
|
case V4L2_ASYNC_MATCH_I2C:
|
2013-01-08 18:06:31 +08:00
|
|
|
match = match_i2c;
|
|
|
|
break;
|
2016-08-16 17:54:59 +08:00
|
|
|
case V4L2_ASYNC_MATCH_FWNODE:
|
|
|
|
match = match_fwnode;
|
|
|
|
break;
|
2013-01-08 18:06:31 +08:00
|
|
|
default:
|
|
|
|
/* Cannot happen, unless someone breaks us */
|
|
|
|
WARN_ON(true);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* match cannot be NULL here */
|
2020-07-01 14:21:39 +08:00
|
|
|
if (match(notifier, sd, asd))
|
2013-01-08 18:06:31 +08:00
|
|
|
return asd;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-09-30 03:54:05 +08:00
|
|
|
/* Compare two async sub-device descriptors for equivalence */
|
|
|
|
static bool asd_equal(struct v4l2_async_subdev *asd_x,
|
|
|
|
struct v4l2_async_subdev *asd_y)
|
|
|
|
{
|
|
|
|
if (asd_x->match_type != asd_y->match_type)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (asd_x->match_type) {
|
|
|
|
case V4L2_ASYNC_MATCH_I2C:
|
|
|
|
return asd_x->match.i2c.adapter_id ==
|
|
|
|
asd_y->match.i2c.adapter_id &&
|
|
|
|
asd_x->match.i2c.address ==
|
|
|
|
asd_y->match.i2c.address;
|
|
|
|
case V4L2_ASYNC_MATCH_FWNODE:
|
|
|
|
return asd_x->match.fwnode == asd_y->match.fwnode;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-25 08:54:31 +08:00
|
|
|
/* Find the sub-device notifier registered by a sub-device driver. */
|
2018-10-05 05:10:46 +08:00
|
|
|
static struct v4l2_async_notifier *
|
|
|
|
v4l2_async_find_subdev_notifier(struct v4l2_subdev *sd)
|
2017-09-25 08:54:31 +08:00
|
|
|
{
|
|
|
|
struct v4l2_async_notifier *n;
|
|
|
|
|
|
|
|
list_for_each_entry(n, ¬ifier_list, list)
|
|
|
|
if (n->sd == sd)
|
|
|
|
return n;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get v4l2_device related to the notifier if one can be found. */
|
2018-10-05 05:10:46 +08:00
|
|
|
static struct v4l2_device *
|
2021-03-06 01:13:12 +08:00
|
|
|
v4l2_async_nf_find_v4l2_dev(struct v4l2_async_notifier *notifier)
|
2017-09-25 08:54:31 +08:00
|
|
|
{
|
|
|
|
while (notifier->parent)
|
|
|
|
notifier = notifier->parent;
|
|
|
|
|
|
|
|
return notifier->v4l2_dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return true if all child sub-device notifiers are complete, false otherwise.
|
|
|
|
*/
|
2018-10-05 05:10:46 +08:00
|
|
|
static bool
|
2021-03-06 01:13:12 +08:00
|
|
|
v4l2_async_nf_can_complete(struct v4l2_async_notifier *notifier)
|
2017-09-25 08:54:31 +08:00
|
|
|
{
|
|
|
|
struct v4l2_subdev *sd;
|
|
|
|
|
|
|
|
if (!list_empty(¬ifier->waiting))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
list_for_each_entry(sd, ¬ifier->done, async_list) {
|
|
|
|
struct v4l2_async_notifier *subdev_notifier =
|
|
|
|
v4l2_async_find_subdev_notifier(sd);
|
|
|
|
|
|
|
|
if (subdev_notifier &&
|
2021-03-06 01:13:12 +08:00
|
|
|
!v4l2_async_nf_can_complete(subdev_notifier))
|
2017-09-25 08:54:31 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Complete the master notifier if possible. This is done when all async
|
|
|
|
* sub-devices have been bound; v4l2_device is also available then.
|
|
|
|
*/
|
2018-10-05 05:10:46 +08:00
|
|
|
static int
|
2021-03-06 01:13:12 +08:00
|
|
|
v4l2_async_nf_try_complete(struct v4l2_async_notifier *notifier)
|
2017-09-25 08:54:31 +08:00
|
|
|
{
|
|
|
|
/* Quick check whether there are still more sub-devices here. */
|
|
|
|
if (!list_empty(¬ifier->waiting))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Check the entire notifier tree; find the root notifier first. */
|
|
|
|
while (notifier->parent)
|
|
|
|
notifier = notifier->parent;
|
|
|
|
|
|
|
|
/* This is root if it has v4l2_dev. */
|
|
|
|
if (!notifier->v4l2_dev)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Is everything ready? */
|
2021-03-06 01:13:12 +08:00
|
|
|
if (!v4l2_async_nf_can_complete(notifier))
|
2017-09-25 08:54:31 +08:00
|
|
|
return 0;
|
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
return v4l2_async_nf_call_complete(notifier);
|
2017-09-25 08:54:31 +08:00
|
|
|
}
|
|
|
|
|
2018-10-05 05:10:46 +08:00
|
|
|
static int
|
2021-03-06 01:13:12 +08:00
|
|
|
v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier);
|
2017-09-25 08:54:31 +08:00
|
|
|
|
2022-03-03 06:03:04 +08:00
|
|
|
static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
|
|
|
|
struct v4l2_subdev *sd)
|
|
|
|
{
|
|
|
|
struct media_link *link = NULL;
|
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
|
|
|
|
|
|
|
|
if (sd->entity.function != MEDIA_ENT_F_LENS &&
|
|
|
|
sd->entity.function != MEDIA_ENT_F_FLASH)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
link = media_create_ancillary_link(&n->sd->entity, &sd->entity);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return IS_ERR(link) ? PTR_ERR(link) : 0;
|
|
|
|
}
|
|
|
|
|
2017-09-05 00:44:39 +08:00
|
|
|
static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,
|
2017-09-25 08:48:08 +08:00
|
|
|
struct v4l2_device *v4l2_dev,
|
2017-09-05 00:44:39 +08:00
|
|
|
struct v4l2_subdev *sd,
|
|
|
|
struct v4l2_async_subdev *asd)
|
2013-01-08 18:06:31 +08:00
|
|
|
{
|
2017-09-25 08:54:31 +08:00
|
|
|
struct v4l2_async_notifier *subdev_notifier;
|
2013-01-08 18:06:31 +08:00
|
|
|
int ret;
|
|
|
|
|
2017-09-25 08:48:08 +08:00
|
|
|
ret = v4l2_device_register_subdev(v4l2_dev, sd);
|
2017-09-01 20:27:32 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2013-01-08 18:06:31 +08:00
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
ret = v4l2_async_nf_call_bound(notifier, sd, asd);
|
2013-01-08 18:06:31 +08:00
|
|
|
if (ret < 0) {
|
2017-07-17 22:04:20 +08:00
|
|
|
v4l2_device_unregister_subdev(sd);
|
2013-01-08 18:06:31 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-03-03 06:03:04 +08:00
|
|
|
/*
|
|
|
|
* Depending of the function of the entities involved, we may want to
|
|
|
|
* create links between them (for example between a sensor and its lens
|
|
|
|
* or between a sensor's source pad and the connected device's sink
|
|
|
|
* pad).
|
|
|
|
*/
|
|
|
|
ret = v4l2_async_create_ancillary_links(notifier, sd);
|
|
|
|
if (ret) {
|
|
|
|
v4l2_async_nf_call_unbind(notifier, sd, asd);
|
|
|
|
v4l2_device_unregister_subdev(sd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
[media] v4l2-async: failing functions shouldn't have side effects
v4l2-async had several functions doing some operations and then
not undoing the operations in a failure situation. For example,
v4l2_async_test_notify() moved a subdev into notifier's done list
even if registering the subdev (v4l2_device_register_subdev) failed.
If the subdev was allocated and v4l2_async_register_subdev() called
from the driver's probe() function, as usually, the probe()
function freed the allocated subdev and returned a failure.
Nevertheless, the subdev was still left into the notifier's done
list, causing an access to already freed memory when the notifier
was later unregistered.
A hand-edited call trace leaving freed subdevs into the notifier:
v4l2_async_register_notifier(notifier, asd)
cameradrv_probe
sd = devm_kzalloc()
v4l2_async_register_subdev(sd)
v4l2_async_test_notify(notifier, sd, asd)
list_move(sd, ¬ifier->done)
v4l2_device_register_subdev(notifier->v4l2_dev, sd)
cameradrv_registered(sd) -> fails
->v4l2_async_register_subdev returns failure
->cameradrv_probe returns failure
->devres frees the allocated sd
->sd was freed but it still remains in the notifier's list.
This patch fixes this and several other cases where a failing
function could leave nodes into a linked list while the caller
might free the node due to a failure.
Signed-off-by: Tuukka Toivonen <tuukka.toivonen@intel.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-01-27 18:32:56 +08:00
|
|
|
/* Remove from the waiting list */
|
|
|
|
list_del(&asd->list);
|
|
|
|
sd->asd = asd;
|
|
|
|
sd->notifier = notifier;
|
|
|
|
|
|
|
|
/* Move from the global subdevice list to notifier's done */
|
|
|
|
list_move(&sd->async_list, ¬ifier->done);
|
|
|
|
|
2017-09-25 08:54:31 +08:00
|
|
|
/*
|
|
|
|
* See if the sub-device has a notifier. If not, return here.
|
|
|
|
*/
|
|
|
|
subdev_notifier = v4l2_async_find_subdev_notifier(sd);
|
|
|
|
if (!subdev_notifier || subdev_notifier->parent)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Proceed with checking for the sub-device notifier's async
|
|
|
|
* sub-devices, and return the result. The error will be handled by the
|
|
|
|
* caller.
|
|
|
|
*/
|
|
|
|
subdev_notifier->parent = notifier;
|
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
return v4l2_async_nf_try_all_subdevs(subdev_notifier);
|
2013-01-08 18:06:31 +08:00
|
|
|
}
|
|
|
|
|
2017-09-25 08:48:08 +08:00
|
|
|
/* Test all async sub-devices in a notifier for a match. */
|
2018-10-05 05:10:46 +08:00
|
|
|
static int
|
2021-03-06 01:13:12 +08:00
|
|
|
v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier)
|
2017-09-25 08:48:08 +08:00
|
|
|
{
|
2017-09-25 08:54:31 +08:00
|
|
|
struct v4l2_device *v4l2_dev =
|
2021-03-06 01:13:12 +08:00
|
|
|
v4l2_async_nf_find_v4l2_dev(notifier);
|
2017-09-25 08:54:31 +08:00
|
|
|
struct v4l2_subdev *sd;
|
|
|
|
|
|
|
|
if (!v4l2_dev)
|
|
|
|
return 0;
|
2017-09-25 08:48:08 +08:00
|
|
|
|
2017-09-25 08:54:31 +08:00
|
|
|
again:
|
|
|
|
list_for_each_entry(sd, &subdev_list, async_list) {
|
2017-09-25 08:48:08 +08:00
|
|
|
struct v4l2_async_subdev *asd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
asd = v4l2_async_find_match(notifier, sd);
|
|
|
|
if (!asd)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ret = v4l2_async_match_notify(notifier, v4l2_dev, sd, asd);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2017-09-25 08:54:31 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* v4l2_async_match_notify() may lead to registering a
|
|
|
|
* new notifier and thus changing the async subdevs
|
|
|
|
* list. In order to proceed safely from here, restart
|
|
|
|
* parsing the list from the beginning.
|
|
|
|
*/
|
|
|
|
goto again;
|
2017-09-25 08:48:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-22 19:01:33 +08:00
|
|
|
static void v4l2_async_cleanup(struct v4l2_subdev *sd)
|
2013-01-08 18:06:31 +08:00
|
|
|
{
|
|
|
|
v4l2_device_unregister_subdev(sd);
|
2018-10-05 05:10:46 +08:00
|
|
|
/*
|
|
|
|
* Subdevice driver will reprobe and put the subdev back
|
|
|
|
* onto the list
|
|
|
|
*/
|
2013-07-22 19:01:33 +08:00
|
|
|
list_del_init(&sd->async_list);
|
|
|
|
sd->asd = NULL;
|
2013-01-08 18:06:31 +08:00
|
|
|
}
|
|
|
|
|
2017-09-25 08:54:31 +08:00
|
|
|
/* Unbind all sub-devices in the notifier tree. */
|
2018-10-05 05:10:46 +08:00
|
|
|
static void
|
2023-03-07 21:49:44 +08:00
|
|
|
v4l2_async_nf_unbind_all_subdevs(struct v4l2_async_notifier *notifier,
|
|
|
|
bool readd)
|
2017-10-02 18:24:54 +08:00
|
|
|
{
|
|
|
|
struct v4l2_subdev *sd, *tmp;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(sd, tmp, ¬ifier->done, async_list) {
|
2017-09-25 08:54:31 +08:00
|
|
|
struct v4l2_async_notifier *subdev_notifier =
|
|
|
|
v4l2_async_find_subdev_notifier(sd);
|
|
|
|
|
|
|
|
if (subdev_notifier)
|
2023-03-07 21:49:44 +08:00
|
|
|
v4l2_async_nf_unbind_all_subdevs(subdev_notifier, true);
|
2017-09-25 08:54:31 +08:00
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
v4l2_async_nf_call_unbind(notifier, sd, sd->asd);
|
2023-03-07 21:49:44 +08:00
|
|
|
if (readd)
|
|
|
|
list_add_tail(&sd->asd->list, ¬ifier->waiting);
|
2017-10-02 18:24:54 +08:00
|
|
|
v4l2_async_cleanup(sd);
|
|
|
|
|
|
|
|
list_move(&sd->async_list, &subdev_list);
|
|
|
|
}
|
2017-09-25 08:54:31 +08:00
|
|
|
|
|
|
|
notifier->parent = NULL;
|
2017-10-02 18:24:54 +08:00
|
|
|
}
|
|
|
|
|
2018-09-30 03:54:05 +08:00
|
|
|
/* See if an async sub-device can be found in a notifier's lists. */
|
|
|
|
static bool
|
2021-03-06 01:13:12 +08:00
|
|
|
__v4l2_async_nf_has_async_subdev(struct v4l2_async_notifier *notifier,
|
|
|
|
struct v4l2_async_subdev *asd)
|
2017-09-20 15:51:54 +08:00
|
|
|
{
|
2018-09-30 03:54:05 +08:00
|
|
|
struct v4l2_async_subdev *asd_y;
|
2017-09-20 15:51:54 +08:00
|
|
|
struct v4l2_subdev *sd;
|
|
|
|
|
2018-09-30 03:54:05 +08:00
|
|
|
list_for_each_entry(asd_y, ¬ifier->waiting, list)
|
|
|
|
if (asd_equal(asd, asd_y))
|
2017-09-20 15:51:54 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
list_for_each_entry(sd, ¬ifier->done, async_list) {
|
|
|
|
if (WARN_ON(!sd->asd))
|
|
|
|
continue;
|
|
|
|
|
2018-09-30 03:54:05 +08:00
|
|
|
if (asd_equal(asd, sd->asd))
|
2017-09-20 15:51:54 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-09-30 03:54:05 +08:00
|
|
|
* Find out whether an async sub-device was set up already or
|
2017-09-20 15:51:54 +08:00
|
|
|
* whether it exists in a given notifier before @this_index.
|
2018-09-30 03:54:19 +08:00
|
|
|
* If @this_index < 0, search the notifier's entire @asd_list.
|
2017-09-20 15:51:54 +08:00
|
|
|
*/
|
2018-09-30 03:54:05 +08:00
|
|
|
static bool
|
2021-03-06 01:13:12 +08:00
|
|
|
v4l2_async_nf_has_async_subdev(struct v4l2_async_notifier *notifier,
|
|
|
|
struct v4l2_async_subdev *asd, int this_index)
|
2017-09-20 15:51:54 +08:00
|
|
|
{
|
media: v4l2: async: Add v4l2_async_notifier_add_subdev
v4l2_async_notifier_add_subdev() adds an asd to the notifier. It checks
that no other equivalent asd's have already been added to this notifier's
asd list, or to other registered notifier's waiting or done lists, and
increments num_subdevs.
v4l2_async_notifier_add_subdev() does not make use of the notifier subdevs
array, otherwise it would have to re-allocate the array every time the
function was called. In place of the subdevs array, the function adds
the newly allocated asd to a new master asd_list. The function will
return error with a WARN() if it is ever called with the subdevs array
allocated.
Drivers are now required to call a v4l2_async_notifier_init(), before the
first call to v4l2_async_notifier_add_subdev(), in order to initialize
the asd_list.
In v4l2_async_notifier_has_async_subdev(), __v4l2_async_notifier_register(),
and v4l2_async_notifier_cleanup(), maintain backward compatibility with
the subdevs array, by alternatively operate on the subdevs array or a
non-empty notifier->asd_list.
Signed-off-by: Steve Longerbeam <slongerbeam@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-30 03:54:06 +08:00
|
|
|
struct v4l2_async_subdev *asd_y;
|
2018-09-30 03:54:19 +08:00
|
|
|
int j = 0;
|
2017-09-20 15:51:54 +08:00
|
|
|
|
|
|
|
lockdep_assert_held(&list_lock);
|
|
|
|
|
2018-09-30 03:54:05 +08:00
|
|
|
/* Check that an asd is not being added more than once. */
|
2018-09-30 03:54:19 +08:00
|
|
|
list_for_each_entry(asd_y, ¬ifier->asd_list, asd_list) {
|
|
|
|
if (this_index >= 0 && j++ >= this_index)
|
|
|
|
break;
|
|
|
|
if (asd_equal(asd, asd_y))
|
|
|
|
return true;
|
2017-09-20 15:51:54 +08:00
|
|
|
}
|
|
|
|
|
2018-09-30 03:54:05 +08:00
|
|
|
/* Check that an asd does not exist in other notifiers. */
|
2017-09-20 15:51:54 +08:00
|
|
|
list_for_each_entry(notifier, ¬ifier_list, list)
|
2021-03-06 01:13:12 +08:00
|
|
|
if (__v4l2_async_nf_has_async_subdev(notifier, asd))
|
2017-09-20 15:51:54 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
static int v4l2_async_nf_asd_valid(struct v4l2_async_notifier *notifier,
|
|
|
|
struct v4l2_async_subdev *asd,
|
|
|
|
int this_index)
|
2013-01-08 18:06:31 +08:00
|
|
|
{
|
2017-09-20 15:51:54 +08:00
|
|
|
struct device *dev =
|
|
|
|
notifier->v4l2_dev ? notifier->v4l2_dev->dev : NULL;
|
media: v4l2: async: Add v4l2_async_notifier_add_subdev
v4l2_async_notifier_add_subdev() adds an asd to the notifier. It checks
that no other equivalent asd's have already been added to this notifier's
asd list, or to other registered notifier's waiting or done lists, and
increments num_subdevs.
v4l2_async_notifier_add_subdev() does not make use of the notifier subdevs
array, otherwise it would have to re-allocate the array every time the
function was called. In place of the subdevs array, the function adds
the newly allocated asd to a new master asd_list. The function will
return error with a WARN() if it is ever called with the subdevs array
allocated.
Drivers are now required to call a v4l2_async_notifier_init(), before the
first call to v4l2_async_notifier_add_subdev(), in order to initialize
the asd_list.
In v4l2_async_notifier_has_async_subdev(), __v4l2_async_notifier_register(),
and v4l2_async_notifier_cleanup(), maintain backward compatibility with
the subdevs array, by alternatively operate on the subdevs array or a
non-empty notifier->asd_list.
Signed-off-by: Steve Longerbeam <slongerbeam@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-30 03:54:06 +08:00
|
|
|
|
|
|
|
if (!asd)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
switch (asd->match_type) {
|
|
|
|
case V4L2_ASYNC_MATCH_I2C:
|
|
|
|
case V4L2_ASYNC_MATCH_FWNODE:
|
2021-03-06 01:13:12 +08:00
|
|
|
if (v4l2_async_nf_has_async_subdev(notifier, asd, this_index)) {
|
media: v4l2: async: Add v4l2_async_notifier_add_subdev
v4l2_async_notifier_add_subdev() adds an asd to the notifier. It checks
that no other equivalent asd's have already been added to this notifier's
asd list, or to other registered notifier's waiting or done lists, and
increments num_subdevs.
v4l2_async_notifier_add_subdev() does not make use of the notifier subdevs
array, otherwise it would have to re-allocate the array every time the
function was called. In place of the subdevs array, the function adds
the newly allocated asd to a new master asd_list. The function will
return error with a WARN() if it is ever called with the subdevs array
allocated.
Drivers are now required to call a v4l2_async_notifier_init(), before the
first call to v4l2_async_notifier_add_subdev(), in order to initialize
the asd_list.
In v4l2_async_notifier_has_async_subdev(), __v4l2_async_notifier_register(),
and v4l2_async_notifier_cleanup(), maintain backward compatibility with
the subdevs array, by alternatively operate on the subdevs array or a
non-empty notifier->asd_list.
Signed-off-by: Steve Longerbeam <slongerbeam@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-30 03:54:06 +08:00
|
|
|
dev_dbg(dev, "subdev descriptor already listed in this or other notifiers\n");
|
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(dev, "Invalid match type %u on %p\n",
|
|
|
|
asd->match_type, asd);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
void v4l2_async_nf_init(struct v4l2_async_notifier *notifier)
|
media: v4l2: async: Add v4l2_async_notifier_add_subdev
v4l2_async_notifier_add_subdev() adds an asd to the notifier. It checks
that no other equivalent asd's have already been added to this notifier's
asd list, or to other registered notifier's waiting or done lists, and
increments num_subdevs.
v4l2_async_notifier_add_subdev() does not make use of the notifier subdevs
array, otherwise it would have to re-allocate the array every time the
function was called. In place of the subdevs array, the function adds
the newly allocated asd to a new master asd_list. The function will
return error with a WARN() if it is ever called with the subdevs array
allocated.
Drivers are now required to call a v4l2_async_notifier_init(), before the
first call to v4l2_async_notifier_add_subdev(), in order to initialize
the asd_list.
In v4l2_async_notifier_has_async_subdev(), __v4l2_async_notifier_register(),
and v4l2_async_notifier_cleanup(), maintain backward compatibility with
the subdevs array, by alternatively operate on the subdevs array or a
non-empty notifier->asd_list.
Signed-off-by: Steve Longerbeam <slongerbeam@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-30 03:54:06 +08:00
|
|
|
{
|
|
|
|
INIT_LIST_HEAD(¬ifier->asd_list);
|
|
|
|
}
|
2021-03-06 01:13:12 +08:00
|
|
|
EXPORT_SYMBOL(v4l2_async_nf_init);
|
media: v4l2: async: Add v4l2_async_notifier_add_subdev
v4l2_async_notifier_add_subdev() adds an asd to the notifier. It checks
that no other equivalent asd's have already been added to this notifier's
asd list, or to other registered notifier's waiting or done lists, and
increments num_subdevs.
v4l2_async_notifier_add_subdev() does not make use of the notifier subdevs
array, otherwise it would have to re-allocate the array every time the
function was called. In place of the subdevs array, the function adds
the newly allocated asd to a new master asd_list. The function will
return error with a WARN() if it is ever called with the subdevs array
allocated.
Drivers are now required to call a v4l2_async_notifier_init(), before the
first call to v4l2_async_notifier_add_subdev(), in order to initialize
the asd_list.
In v4l2_async_notifier_has_async_subdev(), __v4l2_async_notifier_register(),
and v4l2_async_notifier_cleanup(), maintain backward compatibility with
the subdevs array, by alternatively operate on the subdevs array or a
non-empty notifier->asd_list.
Signed-off-by: Steve Longerbeam <slongerbeam@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-30 03:54:06 +08:00
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
static int __v4l2_async_nf_register(struct v4l2_async_notifier *notifier)
|
media: v4l2: async: Add v4l2_async_notifier_add_subdev
v4l2_async_notifier_add_subdev() adds an asd to the notifier. It checks
that no other equivalent asd's have already been added to this notifier's
asd list, or to other registered notifier's waiting or done lists, and
increments num_subdevs.
v4l2_async_notifier_add_subdev() does not make use of the notifier subdevs
array, otherwise it would have to re-allocate the array every time the
function was called. In place of the subdevs array, the function adds
the newly allocated asd to a new master asd_list. The function will
return error with a WARN() if it is ever called with the subdevs array
allocated.
Drivers are now required to call a v4l2_async_notifier_init(), before the
first call to v4l2_async_notifier_add_subdev(), in order to initialize
the asd_list.
In v4l2_async_notifier_has_async_subdev(), __v4l2_async_notifier_register(),
and v4l2_async_notifier_cleanup(), maintain backward compatibility with
the subdevs array, by alternatively operate on the subdevs array or a
non-empty notifier->asd_list.
Signed-off-by: Steve Longerbeam <slongerbeam@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-30 03:54:06 +08:00
|
|
|
{
|
2013-01-08 18:06:31 +08:00
|
|
|
struct v4l2_async_subdev *asd;
|
2018-09-30 03:54:19 +08:00
|
|
|
int ret, i = 0;
|
2013-01-08 18:06:31 +08:00
|
|
|
|
|
|
|
INIT_LIST_HEAD(¬ifier->waiting);
|
|
|
|
INIT_LIST_HEAD(¬ifier->done);
|
|
|
|
|
2017-09-20 15:51:54 +08:00
|
|
|
mutex_lock(&list_lock);
|
|
|
|
|
2018-09-30 03:54:19 +08:00
|
|
|
list_for_each_entry(asd, ¬ifier->asd_list, asd_list) {
|
2021-03-06 01:13:12 +08:00
|
|
|
ret = v4l2_async_nf_asd_valid(notifier, asd, i++);
|
2018-09-30 03:54:19 +08:00
|
|
|
if (ret)
|
|
|
|
goto err_unlock;
|
2013-01-08 18:06:31 +08:00
|
|
|
|
2018-09-30 03:54:19 +08:00
|
|
|
list_add_tail(&asd->list, ¬ifier->waiting);
|
2013-01-08 18:06:31 +08:00
|
|
|
}
|
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
ret = v4l2_async_nf_try_all_subdevs(notifier);
|
2017-09-20 15:51:54 +08:00
|
|
|
if (ret < 0)
|
2017-09-25 08:54:31 +08:00
|
|
|
goto err_unbind;
|
2013-01-08 18:06:31 +08:00
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
ret = v4l2_async_nf_try_complete(notifier);
|
2017-09-20 15:51:54 +08:00
|
|
|
if (ret < 0)
|
2017-09-25 08:54:31 +08:00
|
|
|
goto err_unbind;
|
2017-10-02 18:24:54 +08:00
|
|
|
|
[media] v4l2-async: failing functions shouldn't have side effects
v4l2-async had several functions doing some operations and then
not undoing the operations in a failure situation. For example,
v4l2_async_test_notify() moved a subdev into notifier's done list
even if registering the subdev (v4l2_device_register_subdev) failed.
If the subdev was allocated and v4l2_async_register_subdev() called
from the driver's probe() function, as usually, the probe()
function freed the allocated subdev and returned a failure.
Nevertheless, the subdev was still left into the notifier's done
list, causing an access to already freed memory when the notifier
was later unregistered.
A hand-edited call trace leaving freed subdevs into the notifier:
v4l2_async_register_notifier(notifier, asd)
cameradrv_probe
sd = devm_kzalloc()
v4l2_async_register_subdev(sd)
v4l2_async_test_notify(notifier, sd, asd)
list_move(sd, ¬ifier->done)
v4l2_device_register_subdev(notifier->v4l2_dev, sd)
cameradrv_registered(sd) -> fails
->v4l2_async_register_subdev returns failure
->cameradrv_probe returns failure
->devres frees the allocated sd
->sd was freed but it still remains in the notifier's list.
This patch fixes this and several other cases where a failing
function could leave nodes into a linked list while the caller
might free the node due to a failure.
Signed-off-by: Tuukka Toivonen <tuukka.toivonen@intel.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-01-27 18:32:56 +08:00
|
|
|
/* Keep also completed notifiers on the list */
|
|
|
|
list_add(¬ifier->list, ¬ifier_list);
|
|
|
|
|
2013-01-08 18:06:31 +08:00
|
|
|
mutex_unlock(&list_lock);
|
|
|
|
|
|
|
|
return 0;
|
2017-10-02 18:24:54 +08:00
|
|
|
|
2017-09-25 08:54:31 +08:00
|
|
|
err_unbind:
|
|
|
|
/*
|
|
|
|
* On failure, unbind all sub-devices registered through this notifier.
|
|
|
|
*/
|
2023-03-07 21:49:44 +08:00
|
|
|
v4l2_async_nf_unbind_all_subdevs(notifier, false);
|
2017-10-02 18:24:54 +08:00
|
|
|
|
2017-09-20 15:51:54 +08:00
|
|
|
err_unlock:
|
2017-10-02 18:24:54 +08:00
|
|
|
mutex_unlock(&list_lock);
|
|
|
|
|
|
|
|
return ret;
|
2013-01-08 18:06:31 +08:00
|
|
|
}
|
2017-09-25 08:48:08 +08:00
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
int v4l2_async_nf_register(struct v4l2_device *v4l2_dev,
|
|
|
|
struct v4l2_async_notifier *notifier)
|
2017-09-25 08:48:08 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2017-09-25 08:54:31 +08:00
|
|
|
if (WARN_ON(!v4l2_dev || notifier->sd))
|
2017-09-25 08:48:08 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
notifier->v4l2_dev = v4l2_dev;
|
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
ret = __v4l2_async_nf_register(notifier);
|
2017-09-25 08:48:08 +08:00
|
|
|
if (ret)
|
|
|
|
notifier->v4l2_dev = NULL;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2021-03-06 01:13:12 +08:00
|
|
|
EXPORT_SYMBOL(v4l2_async_nf_register);
|
2013-01-08 18:06:31 +08:00
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
int v4l2_async_subdev_nf_register(struct v4l2_subdev *sd,
|
|
|
|
struct v4l2_async_notifier *notifier)
|
2017-09-25 08:54:31 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (WARN_ON(!sd || notifier->v4l2_dev))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
notifier->sd = sd;
|
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
ret = __v4l2_async_nf_register(notifier);
|
2017-09-25 08:54:31 +08:00
|
|
|
if (ret)
|
|
|
|
notifier->sd = NULL;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2021-03-06 01:13:12 +08:00
|
|
|
EXPORT_SYMBOL(v4l2_async_subdev_nf_register);
|
2017-09-25 08:54:31 +08:00
|
|
|
|
2018-10-05 05:10:46 +08:00
|
|
|
static void
|
2021-03-06 01:13:12 +08:00
|
|
|
__v4l2_async_nf_unregister(struct v4l2_async_notifier *notifier)
|
2013-01-08 18:06:31 +08:00
|
|
|
{
|
2017-09-25 06:47:44 +08:00
|
|
|
if (!notifier || (!notifier->v4l2_dev && !notifier->sd))
|
2013-07-03 18:49:06 +08:00
|
|
|
return;
|
|
|
|
|
2023-03-07 21:49:44 +08:00
|
|
|
v4l2_async_nf_unbind_all_subdevs(notifier, false);
|
2013-01-08 18:06:31 +08:00
|
|
|
|
2017-09-25 08:54:31 +08:00
|
|
|
notifier->sd = NULL;
|
2013-07-03 18:49:06 +08:00
|
|
|
notifier->v4l2_dev = NULL;
|
2017-09-25 08:54:31 +08:00
|
|
|
|
|
|
|
list_del(¬ifier->list);
|
2017-09-25 06:47:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
void v4l2_async_nf_unregister(struct v4l2_async_notifier *notifier)
|
2017-09-25 06:47:44 +08:00
|
|
|
{
|
|
|
|
mutex_lock(&list_lock);
|
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
__v4l2_async_nf_unregister(notifier);
|
2017-09-25 08:54:31 +08:00
|
|
|
|
|
|
|
mutex_unlock(&list_lock);
|
2013-01-08 18:06:31 +08:00
|
|
|
}
|
2021-03-06 01:13:12 +08:00
|
|
|
EXPORT_SYMBOL(v4l2_async_nf_unregister);
|
2013-01-08 18:06:31 +08:00
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
static void __v4l2_async_nf_cleanup(struct v4l2_async_notifier *notifier)
|
2017-08-17 23:28:21 +08:00
|
|
|
{
|
media: v4l2: async: Add v4l2_async_notifier_add_subdev
v4l2_async_notifier_add_subdev() adds an asd to the notifier. It checks
that no other equivalent asd's have already been added to this notifier's
asd list, or to other registered notifier's waiting or done lists, and
increments num_subdevs.
v4l2_async_notifier_add_subdev() does not make use of the notifier subdevs
array, otherwise it would have to re-allocate the array every time the
function was called. In place of the subdevs array, the function adds
the newly allocated asd to a new master asd_list. The function will
return error with a WARN() if it is ever called with the subdevs array
allocated.
Drivers are now required to call a v4l2_async_notifier_init(), before the
first call to v4l2_async_notifier_add_subdev(), in order to initialize
the asd_list.
In v4l2_async_notifier_has_async_subdev(), __v4l2_async_notifier_register(),
and v4l2_async_notifier_cleanup(), maintain backward compatibility with
the subdevs array, by alternatively operate on the subdevs array or a
non-empty notifier->asd_list.
Signed-off-by: Steve Longerbeam <slongerbeam@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-30 03:54:06 +08:00
|
|
|
struct v4l2_async_subdev *asd, *tmp;
|
2017-08-17 23:28:21 +08:00
|
|
|
|
2019-03-04 17:29:49 +08:00
|
|
|
if (!notifier || !notifier->asd_list.next)
|
2017-08-17 23:28:21 +08:00
|
|
|
return;
|
|
|
|
|
2018-09-30 03:54:19 +08:00
|
|
|
list_for_each_entry_safe(asd, tmp, ¬ifier->asd_list, asd_list) {
|
|
|
|
switch (asd->match_type) {
|
|
|
|
case V4L2_ASYNC_MATCH_FWNODE:
|
|
|
|
fwnode_handle_put(asd->match.fwnode);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2017-08-17 23:28:21 +08:00
|
|
|
}
|
|
|
|
|
2018-09-30 03:54:19 +08:00
|
|
|
list_del(&asd->asd_list);
|
2022-06-15 03:10:48 +08:00
|
|
|
v4l2_async_nf_call_destroy(notifier, asd);
|
2018-09-30 03:54:19 +08:00
|
|
|
kfree(asd);
|
2017-08-17 23:28:21 +08:00
|
|
|
}
|
media: v4l2: async: Add v4l2_async_notifier_add_subdev
v4l2_async_notifier_add_subdev() adds an asd to the notifier. It checks
that no other equivalent asd's have already been added to this notifier's
asd list, or to other registered notifier's waiting or done lists, and
increments num_subdevs.
v4l2_async_notifier_add_subdev() does not make use of the notifier subdevs
array, otherwise it would have to re-allocate the array every time the
function was called. In place of the subdevs array, the function adds
the newly allocated asd to a new master asd_list. The function will
return error with a WARN() if it is ever called with the subdevs array
allocated.
Drivers are now required to call a v4l2_async_notifier_init(), before the
first call to v4l2_async_notifier_add_subdev(), in order to initialize
the asd_list.
In v4l2_async_notifier_has_async_subdev(), __v4l2_async_notifier_register(),
and v4l2_async_notifier_cleanup(), maintain backward compatibility with
the subdevs array, by alternatively operate on the subdevs array or a
non-empty notifier->asd_list.
Signed-off-by: Steve Longerbeam <slongerbeam@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-30 03:54:06 +08:00
|
|
|
}
|
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
void v4l2_async_nf_cleanup(struct v4l2_async_notifier *notifier)
|
media: v4l2: async: Add v4l2_async_notifier_add_subdev
v4l2_async_notifier_add_subdev() adds an asd to the notifier. It checks
that no other equivalent asd's have already been added to this notifier's
asd list, or to other registered notifier's waiting or done lists, and
increments num_subdevs.
v4l2_async_notifier_add_subdev() does not make use of the notifier subdevs
array, otherwise it would have to re-allocate the array every time the
function was called. In place of the subdevs array, the function adds
the newly allocated asd to a new master asd_list. The function will
return error with a WARN() if it is ever called with the subdevs array
allocated.
Drivers are now required to call a v4l2_async_notifier_init(), before the
first call to v4l2_async_notifier_add_subdev(), in order to initialize
the asd_list.
In v4l2_async_notifier_has_async_subdev(), __v4l2_async_notifier_register(),
and v4l2_async_notifier_cleanup(), maintain backward compatibility with
the subdevs array, by alternatively operate on the subdevs array or a
non-empty notifier->asd_list.
Signed-off-by: Steve Longerbeam <slongerbeam@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-30 03:54:06 +08:00
|
|
|
{
|
|
|
|
mutex_lock(&list_lock);
|
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
__v4l2_async_nf_cleanup(notifier);
|
2017-08-17 23:28:21 +08:00
|
|
|
|
media: v4l2: async: Add v4l2_async_notifier_add_subdev
v4l2_async_notifier_add_subdev() adds an asd to the notifier. It checks
that no other equivalent asd's have already been added to this notifier's
asd list, or to other registered notifier's waiting or done lists, and
increments num_subdevs.
v4l2_async_notifier_add_subdev() does not make use of the notifier subdevs
array, otherwise it would have to re-allocate the array every time the
function was called. In place of the subdevs array, the function adds
the newly allocated asd to a new master asd_list. The function will
return error with a WARN() if it is ever called with the subdevs array
allocated.
Drivers are now required to call a v4l2_async_notifier_init(), before the
first call to v4l2_async_notifier_add_subdev(), in order to initialize
the asd_list.
In v4l2_async_notifier_has_async_subdev(), __v4l2_async_notifier_register(),
and v4l2_async_notifier_cleanup(), maintain backward compatibility with
the subdevs array, by alternatively operate on the subdevs array or a
non-empty notifier->asd_list.
Signed-off-by: Steve Longerbeam <slongerbeam@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-30 03:54:06 +08:00
|
|
|
mutex_unlock(&list_lock);
|
2017-08-17 23:28:21 +08:00
|
|
|
}
|
2021-03-06 01:13:12 +08:00
|
|
|
EXPORT_SYMBOL_GPL(v4l2_async_nf_cleanup);
|
2017-08-17 23:28:21 +08:00
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
int __v4l2_async_nf_add_subdev(struct v4l2_async_notifier *notifier,
|
|
|
|
struct v4l2_async_subdev *asd)
|
media: v4l2: async: Add v4l2_async_notifier_add_subdev
v4l2_async_notifier_add_subdev() adds an asd to the notifier. It checks
that no other equivalent asd's have already been added to this notifier's
asd list, or to other registered notifier's waiting or done lists, and
increments num_subdevs.
v4l2_async_notifier_add_subdev() does not make use of the notifier subdevs
array, otherwise it would have to re-allocate the array every time the
function was called. In place of the subdevs array, the function adds
the newly allocated asd to a new master asd_list. The function will
return error with a WARN() if it is ever called with the subdevs array
allocated.
Drivers are now required to call a v4l2_async_notifier_init(), before the
first call to v4l2_async_notifier_add_subdev(), in order to initialize
the asd_list.
In v4l2_async_notifier_has_async_subdev(), __v4l2_async_notifier_register(),
and v4l2_async_notifier_cleanup(), maintain backward compatibility with
the subdevs array, by alternatively operate on the subdevs array or a
non-empty notifier->asd_list.
Signed-off-by: Steve Longerbeam <slongerbeam@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-30 03:54:06 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&list_lock);
|
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
ret = v4l2_async_nf_asd_valid(notifier, asd, -1);
|
media: v4l2: async: Add v4l2_async_notifier_add_subdev
v4l2_async_notifier_add_subdev() adds an asd to the notifier. It checks
that no other equivalent asd's have already been added to this notifier's
asd list, or to other registered notifier's waiting or done lists, and
increments num_subdevs.
v4l2_async_notifier_add_subdev() does not make use of the notifier subdevs
array, otherwise it would have to re-allocate the array every time the
function was called. In place of the subdevs array, the function adds
the newly allocated asd to a new master asd_list. The function will
return error with a WARN() if it is ever called with the subdevs array
allocated.
Drivers are now required to call a v4l2_async_notifier_init(), before the
first call to v4l2_async_notifier_add_subdev(), in order to initialize
the asd_list.
In v4l2_async_notifier_has_async_subdev(), __v4l2_async_notifier_register(),
and v4l2_async_notifier_cleanup(), maintain backward compatibility with
the subdevs array, by alternatively operate on the subdevs array or a
non-empty notifier->asd_list.
Signed-off-by: Steve Longerbeam <slongerbeam@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-30 03:54:06 +08:00
|
|
|
if (ret)
|
|
|
|
goto unlock;
|
|
|
|
|
|
|
|
list_add_tail(&asd->asd_list, ¬ifier->asd_list);
|
|
|
|
|
|
|
|
unlock:
|
|
|
|
mutex_unlock(&list_lock);
|
|
|
|
return ret;
|
|
|
|
}
|
2021-03-06 01:13:12 +08:00
|
|
|
EXPORT_SYMBOL_GPL(__v4l2_async_nf_add_subdev);
|
media: v4l2: async: Add v4l2_async_notifier_add_subdev
v4l2_async_notifier_add_subdev() adds an asd to the notifier. It checks
that no other equivalent asd's have already been added to this notifier's
asd list, or to other registered notifier's waiting or done lists, and
increments num_subdevs.
v4l2_async_notifier_add_subdev() does not make use of the notifier subdevs
array, otherwise it would have to re-allocate the array every time the
function was called. In place of the subdevs array, the function adds
the newly allocated asd to a new master asd_list. The function will
return error with a WARN() if it is ever called with the subdevs array
allocated.
Drivers are now required to call a v4l2_async_notifier_init(), before the
first call to v4l2_async_notifier_add_subdev(), in order to initialize
the asd_list.
In v4l2_async_notifier_has_async_subdev(), __v4l2_async_notifier_register(),
and v4l2_async_notifier_cleanup(), maintain backward compatibility with
the subdevs array, by alternatively operate on the subdevs array or a
non-empty notifier->asd_list.
Signed-off-by: Steve Longerbeam <slongerbeam@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-30 03:54:06 +08:00
|
|
|
|
2018-09-30 03:54:07 +08:00
|
|
|
struct v4l2_async_subdev *
|
2021-03-06 01:13:12 +08:00
|
|
|
__v4l2_async_nf_add_fwnode(struct v4l2_async_notifier *notifier,
|
|
|
|
struct fwnode_handle *fwnode,
|
|
|
|
unsigned int asd_struct_size)
|
2018-09-30 03:54:07 +08:00
|
|
|
{
|
|
|
|
struct v4l2_async_subdev *asd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
asd = kzalloc(asd_struct_size, GFP_KERNEL);
|
|
|
|
if (!asd)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
asd->match_type = V4L2_ASYNC_MATCH_FWNODE;
|
2019-04-05 07:43:29 +08:00
|
|
|
asd->match.fwnode = fwnode_handle_get(fwnode);
|
2018-09-30 03:54:07 +08:00
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
ret = __v4l2_async_nf_add_subdev(notifier, asd);
|
2018-09-30 03:54:07 +08:00
|
|
|
if (ret) {
|
2019-04-05 07:43:29 +08:00
|
|
|
fwnode_handle_put(fwnode);
|
2018-09-30 03:54:07 +08:00
|
|
|
kfree(asd);
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return asd;
|
|
|
|
}
|
2021-03-06 01:13:12 +08:00
|
|
|
EXPORT_SYMBOL_GPL(__v4l2_async_nf_add_fwnode);
|
2018-09-30 03:54:07 +08:00
|
|
|
|
2021-01-18 09:52:45 +08:00
|
|
|
struct v4l2_async_subdev *
|
2021-03-06 01:13:12 +08:00
|
|
|
__v4l2_async_nf_add_fwnode_remote(struct v4l2_async_notifier *notif,
|
|
|
|
struct fwnode_handle *endpoint,
|
|
|
|
unsigned int asd_struct_size)
|
2019-02-28 21:25:28 +08:00
|
|
|
{
|
2021-01-18 09:52:45 +08:00
|
|
|
struct v4l2_async_subdev *asd;
|
2019-02-28 21:25:28 +08:00
|
|
|
struct fwnode_handle *remote;
|
|
|
|
|
2022-03-21 22:51:34 +08:00
|
|
|
remote = fwnode_graph_get_remote_endpoint(endpoint);
|
2019-02-28 21:25:28 +08:00
|
|
|
if (!remote)
|
2021-01-18 09:52:45 +08:00
|
|
|
return ERR_PTR(-ENOTCONN);
|
2019-02-28 21:25:28 +08:00
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
asd = __v4l2_async_nf_add_fwnode(notif, remote, asd_struct_size);
|
2021-01-18 09:52:45 +08:00
|
|
|
/*
|
2021-03-06 01:13:12 +08:00
|
|
|
* Calling __v4l2_async_nf_add_fwnode grabs a refcount,
|
2021-01-18 09:52:45 +08:00
|
|
|
* so drop the one we got in fwnode_graph_get_remote_port_parent.
|
|
|
|
*/
|
|
|
|
fwnode_handle_put(remote);
|
|
|
|
return asd;
|
2019-02-28 21:25:28 +08:00
|
|
|
}
|
2021-03-06 01:13:12 +08:00
|
|
|
EXPORT_SYMBOL_GPL(__v4l2_async_nf_add_fwnode_remote);
|
2019-02-28 21:25:28 +08:00
|
|
|
|
2018-09-30 03:54:07 +08:00
|
|
|
struct v4l2_async_subdev *
|
2021-03-06 01:13:12 +08:00
|
|
|
__v4l2_async_nf_add_i2c(struct v4l2_async_notifier *notifier, int adapter_id,
|
|
|
|
unsigned short address, unsigned int asd_struct_size)
|
2018-09-30 03:54:07 +08:00
|
|
|
{
|
|
|
|
struct v4l2_async_subdev *asd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
asd = kzalloc(asd_struct_size, GFP_KERNEL);
|
|
|
|
if (!asd)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
asd->match_type = V4L2_ASYNC_MATCH_I2C;
|
|
|
|
asd->match.i2c.adapter_id = adapter_id;
|
|
|
|
asd->match.i2c.address = address;
|
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
ret = __v4l2_async_nf_add_subdev(notifier, asd);
|
2018-09-30 03:54:07 +08:00
|
|
|
if (ret) {
|
|
|
|
kfree(asd);
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return asd;
|
|
|
|
}
|
2021-03-06 01:13:12 +08:00
|
|
|
EXPORT_SYMBOL_GPL(__v4l2_async_nf_add_i2c);
|
2018-09-30 03:54:07 +08:00
|
|
|
|
2013-01-08 18:06:31 +08:00
|
|
|
int v4l2_async_register_subdev(struct v4l2_subdev *sd)
|
|
|
|
{
|
2017-09-25 08:54:31 +08:00
|
|
|
struct v4l2_async_notifier *subdev_notifier;
|
2013-01-08 18:06:31 +08:00
|
|
|
struct v4l2_async_notifier *notifier;
|
2017-10-02 18:24:54 +08:00
|
|
|
int ret;
|
2013-01-08 18:06:31 +08:00
|
|
|
|
2015-06-12 03:18:01 +08:00
|
|
|
/*
|
|
|
|
* No reference taken. The reference is held by the device
|
|
|
|
* (struct v4l2_subdev.dev), and async sub-device does not
|
|
|
|
* exist independently of the device at any point of time.
|
|
|
|
*/
|
2016-08-27 07:17:25 +08:00
|
|
|
if (!sd->fwnode && sd->dev)
|
|
|
|
sd->fwnode = dev_fwnode(sd->dev);
|
2015-06-12 03:18:01 +08:00
|
|
|
|
2013-01-08 18:06:31 +08:00
|
|
|
mutex_lock(&list_lock);
|
|
|
|
|
2013-07-22 19:01:33 +08:00
|
|
|
INIT_LIST_HEAD(&sd->async_list);
|
2013-01-08 18:06:31 +08:00
|
|
|
|
|
|
|
list_for_each_entry(notifier, ¬ifier_list, list) {
|
2017-09-25 08:54:31 +08:00
|
|
|
struct v4l2_device *v4l2_dev =
|
2021-03-06 01:13:12 +08:00
|
|
|
v4l2_async_nf_find_v4l2_dev(notifier);
|
2017-09-25 08:54:31 +08:00
|
|
|
struct v4l2_async_subdev *asd;
|
2017-10-02 18:24:54 +08:00
|
|
|
|
2017-09-25 08:54:31 +08:00
|
|
|
if (!v4l2_dev)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
asd = v4l2_async_find_match(notifier, sd);
|
2017-10-02 18:24:54 +08:00
|
|
|
if (!asd)
|
|
|
|
continue;
|
|
|
|
|
2017-11-15 23:43:58 +08:00
|
|
|
ret = v4l2_async_match_notify(notifier, v4l2_dev, sd, asd);
|
2017-10-02 18:24:54 +08:00
|
|
|
if (ret)
|
2017-09-25 08:54:31 +08:00
|
|
|
goto err_unbind;
|
2017-10-02 18:24:54 +08:00
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
ret = v4l2_async_nf_try_complete(notifier);
|
2017-10-02 18:24:54 +08:00
|
|
|
if (ret)
|
2017-09-25 08:54:31 +08:00
|
|
|
goto err_unbind;
|
2017-10-02 18:24:54 +08:00
|
|
|
|
|
|
|
goto out_unlock;
|
2013-01-08 18:06:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* None matched, wait for hot-plugging */
|
2013-07-22 19:01:33 +08:00
|
|
|
list_add(&sd->async_list, &subdev_list);
|
2013-01-08 18:06:31 +08:00
|
|
|
|
2017-10-02 18:24:54 +08:00
|
|
|
out_unlock:
|
2013-01-08 18:06:31 +08:00
|
|
|
mutex_unlock(&list_lock);
|
|
|
|
|
|
|
|
return 0;
|
2017-10-02 18:24:54 +08:00
|
|
|
|
2017-09-25 08:54:31 +08:00
|
|
|
err_unbind:
|
|
|
|
/*
|
|
|
|
* Complete failed. Unbind the sub-devices bound through registering
|
|
|
|
* this async sub-device.
|
|
|
|
*/
|
|
|
|
subdev_notifier = v4l2_async_find_subdev_notifier(sd);
|
|
|
|
if (subdev_notifier)
|
2023-03-07 21:49:44 +08:00
|
|
|
v4l2_async_nf_unbind_all_subdevs(subdev_notifier, false);
|
2017-09-25 08:54:31 +08:00
|
|
|
|
|
|
|
if (sd->asd)
|
2021-03-06 01:13:12 +08:00
|
|
|
v4l2_async_nf_call_unbind(notifier, sd, sd->asd);
|
2017-10-02 18:24:54 +08:00
|
|
|
v4l2_async_cleanup(sd);
|
|
|
|
|
|
|
|
mutex_unlock(&list_lock);
|
|
|
|
|
|
|
|
return ret;
|
2013-01-08 18:06:31 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(v4l2_async_register_subdev);
|
|
|
|
|
|
|
|
void v4l2_async_unregister_subdev(struct v4l2_subdev *sd)
|
|
|
|
{
|
2021-01-08 06:54:58 +08:00
|
|
|
if (!sd->async_list.next)
|
|
|
|
return;
|
|
|
|
|
2023-01-28 04:37:25 +08:00
|
|
|
v4l2_subdev_put_privacy_led(sd);
|
|
|
|
|
2013-01-08 18:06:31 +08:00
|
|
|
mutex_lock(&list_lock);
|
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
__v4l2_async_nf_unregister(sd->subdev_notifier);
|
|
|
|
__v4l2_async_nf_cleanup(sd->subdev_notifier);
|
2017-09-25 06:47:44 +08:00
|
|
|
kfree(sd->subdev_notifier);
|
|
|
|
sd->subdev_notifier = NULL;
|
|
|
|
|
2017-10-03 14:26:32 +08:00
|
|
|
if (sd->asd) {
|
|
|
|
struct v4l2_async_notifier *notifier = sd->notifier;
|
2013-01-08 18:06:31 +08:00
|
|
|
|
2017-10-03 14:26:32 +08:00
|
|
|
list_add(&sd->asd->list, ¬ifier->waiting);
|
|
|
|
|
2021-03-06 01:13:12 +08:00
|
|
|
v4l2_async_nf_call_unbind(notifier, sd, sd->asd);
|
2017-10-03 14:26:32 +08:00
|
|
|
}
|
2013-01-08 18:06:31 +08:00
|
|
|
|
2017-10-03 04:16:52 +08:00
|
|
|
v4l2_async_cleanup(sd);
|
|
|
|
|
2013-01-08 18:06:31 +08:00
|
|
|
mutex_unlock(&list_lock);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(v4l2_async_unregister_subdev);
|
2021-01-09 01:17:28 +08:00
|
|
|
|
|
|
|
static void print_waiting_subdev(struct seq_file *s,
|
|
|
|
struct v4l2_async_subdev *asd)
|
|
|
|
{
|
|
|
|
switch (asd->match_type) {
|
|
|
|
case V4L2_ASYNC_MATCH_I2C:
|
|
|
|
seq_printf(s, " [i2c] dev=%d-%04x\n", asd->match.i2c.adapter_id,
|
|
|
|
asd->match.i2c.address);
|
|
|
|
break;
|
|
|
|
case V4L2_ASYNC_MATCH_FWNODE: {
|
|
|
|
struct fwnode_handle *devnode, *fwnode = asd->match.fwnode;
|
|
|
|
|
|
|
|
devnode = fwnode_graph_is_endpoint(fwnode) ?
|
|
|
|
fwnode_graph_get_port_parent(fwnode) :
|
|
|
|
fwnode_handle_get(fwnode);
|
|
|
|
|
|
|
|
seq_printf(s, " [fwnode] dev=%s, node=%pfw\n",
|
|
|
|
devnode->dev ? dev_name(devnode->dev) : "nil",
|
|
|
|
fwnode);
|
|
|
|
|
|
|
|
fwnode_handle_put(devnode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
2021-03-06 01:13:12 +08:00
|
|
|
v4l2_async_nf_name(struct v4l2_async_notifier *notifier)
|
2021-01-09 01:17:28 +08:00
|
|
|
{
|
|
|
|
if (notifier->v4l2_dev)
|
|
|
|
return notifier->v4l2_dev->name;
|
|
|
|
else if (notifier->sd)
|
|
|
|
return notifier->sd->name;
|
|
|
|
else
|
|
|
|
return "nil";
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pending_subdevs_show(struct seq_file *s, void *data)
|
|
|
|
{
|
|
|
|
struct v4l2_async_notifier *notif;
|
|
|
|
struct v4l2_async_subdev *asd;
|
|
|
|
|
|
|
|
mutex_lock(&list_lock);
|
|
|
|
|
|
|
|
list_for_each_entry(notif, ¬ifier_list, list) {
|
2021-03-06 01:13:12 +08:00
|
|
|
seq_printf(s, "%s:\n", v4l2_async_nf_name(notif));
|
2021-01-09 01:17:28 +08:00
|
|
|
list_for_each_entry(asd, ¬if->waiting, list)
|
|
|
|
print_waiting_subdev(s, asd);
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&list_lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DEFINE_SHOW_ATTRIBUTE(pending_subdevs);
|
|
|
|
|
2021-03-06 01:38:39 +08:00
|
|
|
static struct dentry *v4l2_async_debugfs_dir;
|
|
|
|
|
|
|
|
static int __init v4l2_async_init(void)
|
2021-01-09 01:17:28 +08:00
|
|
|
{
|
2021-03-06 01:38:39 +08:00
|
|
|
v4l2_async_debugfs_dir = debugfs_create_dir("v4l2-async", NULL);
|
|
|
|
debugfs_create_file("pending_async_subdevices", 0444,
|
|
|
|
v4l2_async_debugfs_dir, NULL,
|
2021-01-09 01:17:28 +08:00
|
|
|
&pending_subdevs_fops);
|
2021-03-06 01:38:39 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit v4l2_async_exit(void)
|
|
|
|
{
|
|
|
|
debugfs_remove_recursive(v4l2_async_debugfs_dir);
|
2021-01-09 01:17:28 +08:00
|
|
|
}
|
2021-03-06 01:38:39 +08:00
|
|
|
|
|
|
|
subsys_initcall(v4l2_async_init);
|
|
|
|
module_exit(v4l2_async_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
|
|
|
|
MODULE_AUTHOR("Sakari Ailus <sakari.ailus@linux.intel.com>");
|
|
|
|
MODULE_AUTHOR("Ezequiel Garcia <ezequiel@collabora.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|