From patchwork Mon Jul 17 13:18:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 704247 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFCF1EB64DC for ; Mon, 17 Jul 2023 13:21:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230100AbjGQNVx (ORCPT ); Mon, 17 Jul 2023 09:21:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229954AbjGQNVg (ORCPT ); Mon, 17 Jul 2023 09:21:36 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 453321FD6 for ; Mon, 17 Jul 2023 06:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689600055; x=1721136055; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JmpHmS2RKGPfNneYRVrUsB805bMYBIYSLG2ZtEZZ0BI=; b=SPfqIOru07N6DTTrxKV7NvLh9x64NtMnE4rNHwN9cxOSKG5uT5m494OQ K1sRv1x0R9bB2Nz9TvkTmlhVQqx4DU663lP0TIjI4IU2VvormKZJpAbqm 5u7qSxp3Fzja5yq5la89O7HThHSMcJWQ884fvswQg7wHKggtQak23jeMq /faO/aQjsWGuqm8cPJd6I4hvl7lpiOiieYLoDF6vbQGC8xenVhAK3Bipm OMfQ1Z1tDGdtlV2HjAE+e4T4Xhm3K6A2Fcbm1vwOUBXvYZT3C9id+0MAx 0B1z2ZHdBVEaJzAYKvKWA/E4Pf1AxM7jGHpc+KuarBpk8DYAEpRFpTakW w==; X-IronPort-AV: E=McAfee;i="6600,9927,10774"; a="432097403" X-IronPort-AV: E=Sophos;i="6.01,211,1684825200"; d="scan'208";a="432097403" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jul 2023 06:20:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10774"; a="726541898" X-IronPort-AV: E=Sophos;i="6.01,211,1684825200"; d="scan'208";a="726541898" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jul 2023 06:20:27 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by kekkonen.fi.intel.com (Postfix) with ESMTP id F2F53120ECF; Mon, 17 Jul 2023 16:20:15 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.96) (envelope-from ) id 1qLO8G-004s0j-0P; Mon, 17 Jul 2023 16:19:20 +0300 From: Sakari Ailus To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, Philipp Zabel , hverkuil@xs4all.nl, Francesco Dolcini , aishwarya.kothari@toradex.com, Robert Foss , Todor Tomov , Hyun Kwon , bingbu.cao@intel.com, niklas.soderlund@ragnatech.se, Kieran Bingham , Benjamin Mugnier , Sylvain Petinot , Eugen Hristev , Nicolas Ferre , Maxime Ripard , Rui Miguel Silva , Fabio Estevam , Bryan O'Donoghue , Sylwester Nawrocki , Dafna Hirschfeld , Hugues Fruchet , Yong Deng , Paul Kocialkowski , "Lad, Prabhakar" , Benoit Parrot , Steve Longerbeam , Thierry Reding , Jonathan Hunter , Sowjanya Komatineni , Marco Felsch Subject: [PATCH v5 12/38] media: v4l: async: Clean up testing for duplicate async subdevs Date: Mon, 17 Jul 2023 16:18:43 +0300 Message-Id: <20230717131909.1160787-13-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230717131909.1160787-1-sakari.ailus@linux.intel.com> References: <20230717131909.1160787-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 Tested-by: Philipp Zabel # imx6qp Tested-by: Niklas Söderlund # rcar + adv746x Tested-by: Aishwarya Kothari # Apalis i.MX6Q with TC358743 Tested-by: Lad Prabhakar # Renesas RZ/G2L SMARC --- drivers/media/v4l2-core/v4l2-async.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c index c5781124337a..9b79bcc1af82 100644 --- a/drivers/media/v4l2-core/v4l2-async.c +++ b/drivers/media/v4l2-core/v4l2-async.c @@ -519,23 +519,23 @@ __v4l2_async_nf_has_async_subdev(struct v4l2_async_notifier *notifier, } /* - * 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; } @@ -550,7 +550,7 @@ v4l2_async_nf_has_async_subdev(struct v4l2_async_notifier *notifier, 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); @@ -560,7 +560,7 @@ static int v4l2_async_nf_asd_valid(struct v4l2_async_notifier *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; } @@ -583,7 +583,7 @@ EXPORT_SYMBOL(v4l2_async_nf_init); 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); @@ -591,7 +591,7 @@ static int __v4l2_async_nf_register(struct v4l2_async_notifier *notifier) 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; @@ -725,7 +725,7 @@ static int __v4l2_async_nf_add_subdev(struct v4l2_async_notifier *notifier, 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;