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 84856C77B73 for ; Tue, 30 May 2023 06:01:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230136AbjE3GBU (ORCPT ); Tue, 30 May 2023 02:01:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229551AbjE3GBS (ORCPT ); Tue, 30 May 2023 02:01:18 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 902D0B0 for ; Mon, 29 May 2023 23:01:17 -0700 (PDT) Received: from pendragon.ideasonboard.com (om126205206011.34.openmobile.ne.jp [126.205.206.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E844E27C; Tue, 30 May 2023 08:00:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1685426454; bh=XIfCDRQRn0ELZJRrwrVc+RHzP3XPaJHcUkIjB31fD1g=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qmRR660qqwvsWjkdojwSvI4ySkQryWeFsGs5ApUG7eruWpzw6TsEw0GA5z0+oHHLg HEGk9RPju/y8J9yS4ca5vpgkHCpjh5BCO6mhG9O8sKKKIaNqy4KQMX6+M7sdbSWvJk KrOI6vpVo0sJyF7pyoqw5pYnX+5yuvyVocIa6qCI= Date: Tue, 30 May 2023 09:01:15 +0300 From: Laurent Pinchart To: Sakari Ailus Cc: linux-media@vger.kernel.org, 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: Re: [RESEND PATCH v3 16/32] media: v4l: async: Drop duplicate handling when adding connections Message-ID: <20230530060115.GU21633@pendragon.ideasonboard.com> References: <20230525091615.2324824-1-sakari.ailus@linux.intel.com> <20230525091615.2324824-17-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230525091615.2324824-17-sakari.ailus@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Hi Sakari, On Thu, May 25, 2023 at 12:15:59PM +0300, Sakari Ailus wrote: > The connections are checked for duplicates already when the notifier is > registered. This is effectively a sanity check for driver (and possibly > obscure firmware) bugs. Don't do this when adding the connection. Isn't it better to have this sanity check when the connection is added, instead of later when the notifier is registered ? The latter is more difficult to debug. If you want to avoid duplicate checks, could we drop the one at notifier registration time ? > Retain the int return type for now. It'll be needed very soon again. > > Signed-off-by: Sakari Ailus > --- > drivers/media/v4l2-core/v4l2-async.c | 23 +++++++---------------- > 1 file changed, 7 insertions(+), 16 deletions(-) > > diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c > index f51f0c37210c9..5dfc6d5f6a7c3 100644 > --- a/drivers/media/v4l2-core/v4l2-async.c > +++ b/drivers/media/v4l2-core/v4l2-async.c > @@ -475,8 +475,7 @@ v4l2_async_nf_has_async_match_entry(struct v4l2_async_notifier *notifier, > */ > static bool > v4l2_async_nf_has_async_match(struct v4l2_async_notifier *notifier, > - struct v4l2_async_match_desc *match, > - bool skip_self) > + struct v4l2_async_match_desc *match) > { > struct v4l2_async_connection *asc; > > @@ -484,7 +483,7 @@ v4l2_async_nf_has_async_match(struct v4l2_async_notifier *notifier, > > /* Check that an asd is not being added more than once. */ > list_for_each_entry(asc, ¬ifier->asc_list, asc_entry) { > - if (skip_self && &asc->match == match) > + if (&asc->match == match) > break; > if (v4l2_async_match_equal(&asc->match, match)) > return true; > @@ -499,16 +498,14 @@ v4l2_async_nf_has_async_match(struct v4l2_async_notifier *notifier, > } > > static int v4l2_async_nf_match_valid(struct v4l2_async_notifier *notifier, > - struct v4l2_async_match_desc *match, > - bool skip_self) > + struct v4l2_async_match_desc *match) > { > struct device *dev = notifier_dev(notifier); > > switch (match->type) { > case V4L2_ASYNC_MATCH_TYPE_I2C: > case V4L2_ASYNC_MATCH_TYPE_FWNODE: > - if (v4l2_async_nf_has_async_match(notifier, match, > - skip_self)) { > + if (v4l2_async_nf_has_async_match(notifier, match)) { > dev_dbg(dev, "v4l2-async: match descriptor already listed in a notifier\n"); > return -EEXIST; > } > @@ -539,7 +536,7 @@ static int __v4l2_async_nf_register(struct v4l2_async_notifier *notifier) > mutex_lock(&list_lock); > > list_for_each_entry(asc, ¬ifier->asc_list, asc_entry) { > - ret = v4l2_async_nf_match_valid(notifier, &asc->match, true); > + ret = v4l2_async_nf_match_valid(notifier, &asc->match); > if (ret) > goto err_unlock; > > @@ -668,19 +665,13 @@ EXPORT_SYMBOL_GPL(v4l2_async_nf_cleanup); > static int __v4l2_async_nf_add_connection(struct v4l2_async_notifier *notifier, > struct v4l2_async_connection *asc) > { > - int ret; > - > mutex_lock(&list_lock); > > - ret = v4l2_async_nf_match_valid(notifier, &asc->match, false); > - if (ret) > - goto unlock; > - > list_add_tail(&asc->asc_entry, ¬ifier->asc_list); > > -unlock: > mutex_unlock(&list_lock); > - return ret; > + > + return 0; > } > > struct v4l2_async_connection * -- Regards, Laurent Pinchart