There's a need to verify that a single async sub-device isn't being added
multiple times, this would be an error. This takes place at the time of
adding the async sub-device to the notifier's list as well as when the
notifier is added to the global notifier's list.
Use the pointer to the sub-device for testing this instead of an index to
an array that is long gone. (There was an array of async sub-devices in
the notifier before it was converted to a linked list by commit
66beb323e4a0 ("media: v4l2: async: Remove notifier subdevs array").)
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Tested-by: Philipp Zabel <p.zabel@pengutronix.de> # imx6qp
Tested-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> # rcar + adv746x
Tested-by: Aishwarya Kothari <aishwarya.kothari@toradex.com> # Apalis i.MX6Q with TC358743
Tested-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> # Renesas RZ/G2L SMARC
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
- * 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,
*/
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;
{
struct v4l2_async_subdev *asd_y;
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) {
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;
}
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,
static int v4l2_async_nf_asd_valid(struct v4l2_async_notifier *notifier,
struct v4l2_async_subdev *asd,
{
struct device *dev = notifier_dev(notifier);
{
struct device *dev = notifier_dev(notifier);
switch (asd->match_type) {
case V4L2_ASYNC_MATCH_I2C:
case V4L2_ASYNC_MATCH_FWNODE:
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;
}
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;
static int __v4l2_async_nf_register(struct v4l2_async_notifier *notifier)
{
struct v4l2_async_subdev *asd;
INIT_LIST_HEAD(¬ifier->waiting);
INIT_LIST_HEAD(¬ifier->done);
INIT_LIST_HEAD(¬ifier->waiting);
INIT_LIST_HEAD(¬ifier->done);
mutex_lock(&list_lock);
list_for_each_entry(asd, ¬ifier->asd_list, asd_list) {
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;
if (ret)
goto err_unlock;
- ret = v4l2_async_nf_asd_valid(notifier, asd, -1);
+ ret = v4l2_async_nf_asd_valid(notifier, asd, false);