}
/*
- * Find out whether an async sub-device was set up already or
- * whether it exists in a given notifier before @this_index.
- * If @this_index < 0, search the notifier's entire @asd_list.
+ * Find out whether an async sub-device was set up already or whether it exists
+ * in a given notifier. The skip_self argument is used to skip testing the same
+ * sub-device in the notifier in case the sub-device has been already added to
+ * the notifier.
*/
static bool
v4l2_async_nf_has_async_subdev(struct v4l2_async_notifier *notifier,
- struct v4l2_async_subdev *asd, int this_index)
+ struct v4l2_async_subdev *asd, bool skip_self)
{
struct v4l2_async_subdev *asd_y;
- int j = 0;
lockdep_assert_held(&list_lock);
/* Check that an asd is not being added more than once. */
list_for_each_entry(asd_y, ¬ifier->asd_list, asd_list) {
- if (this_index >= 0 && j++ >= this_index)
- break;
+ if (skip_self && asd == asd_y)
+ continue;
if (asd_equal(asd, asd_y))
return true;
}
static int v4l2_async_nf_asd_valid(struct v4l2_async_notifier *notifier,
struct v4l2_async_subdev *asd,
- int this_index)
+ bool skip_self)
{
struct device *dev = notifier_dev(notifier);
switch (asd->match_type) {
case V4L2_ASYNC_MATCH_I2C:
case V4L2_ASYNC_MATCH_FWNODE:
- if (v4l2_async_nf_has_async_subdev(notifier, asd, this_index)) {
+ if (v4l2_async_nf_has_async_subdev(notifier, asd, skip_self)) {
dev_dbg(dev, "v4l2-async: subdev descriptor already listed in a notifier\n");
return -EEXIST;
}
static int __v4l2_async_nf_register(struct v4l2_async_notifier *notifier)
{
struct v4l2_async_subdev *asd;
- int ret, i = 0;
+ int ret;
INIT_LIST_HEAD(¬ifier->waiting);
INIT_LIST_HEAD(¬ifier->done);
mutex_lock(&list_lock);
list_for_each_entry(asd, ¬ifier->asd_list, asd_list) {
- ret = v4l2_async_nf_asd_valid(notifier, asd, i++);
+ ret = v4l2_async_nf_asd_valid(notifier, asd, true);
if (ret)
goto err_unlock;
mutex_lock(&list_lock);
- ret = v4l2_async_nf_asd_valid(notifier, asd, -1);
+ ret = v4l2_async_nf_asd_valid(notifier, asd, false);
if (ret)
goto unlock;