Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp1225175lqb; Thu, 18 Apr 2024 04:05:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXy/eH+sStRe1LTSR8xOGpCPVzGPl8DQk7aJfPhZbG4ohkX2mH/kTbm8GMYxZPbRJQ1Tailr7rrbvZ7X1aNbdQlkwrqCXBwONb3aiVQbw== X-Google-Smtp-Source: AGHT+IEbheO/gSZA8/A2QFFgumL/Fi0+gDChj//GaQ380tlh5SBny8ux1QckmL1TEXuUR7JEiFqG X-Received: by 2002:a50:9ecf:0:b0:568:b622:f225 with SMTP id a73-20020a509ecf000000b00568b622f225mr1496912edf.30.1713438317118; Thu, 18 Apr 2024 04:05:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713438317; cv=pass; d=google.com; s=arc-20160816; b=H2zW8RBKgczhNR68HEUvTcif777UFr9VI80U8+GVhYX5PF5qrDHdMB5VuZmjJYoo2L qaQ9HgH0k4Xb8/aZodH7GFNIFV7wQr98z48ahS3Sr8eftpn6/ota7dYHf/ySq9+fzShO woBiCgCyfBAQVFmqWfzW6zyQBp6iNXEIeaACijqRuCEw/4NE1mGdieJCw6xAdrcPYlZ7 D0aHulOoiEBEU/YOz30ONN6Ie4O6u4Wac8kfdUdR0g27slfCv+AAXUZri2NbkBqzB8Uz 01bwqayExmiiv3bXg9HQq1ErZu0MisUXxEtj0n52s4+ZfiG40ybNkj3b1wKW3KXOtqm1 UV/A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=vES/vBSBusXR/H9HpKruMAeImGjC6h+pxbYmC0pkTqU=; fh=EWXaWrV+NNEysXm1o/RP9qQhWuk7+ngVBRGy4zSFZ1g=; b=GQP9ypHNZPSiiCblRNGMe/bejgjWehl9aG9zIR24Si/QibkTTq+B4hW+O0RyaupoQd sVxSa4cW86YbTJ1/ngp1jgFoZ6liEzF869TyUefy010MSsEaftHmyeSzfZkD75xSk6dq +nuJVybN6/Or53f+Xj+joThPlQPkvWr1TCRcmSSpbJGeagM3bXyW57Sz+q7jLUxvx7tg 3R4fwyXa682viUBlZNVVohQOPD+1sJtbRxSzT7Bzip+xrUrwnPpZjGd4ck1fR5J503Bm CpL9JMZXquJ+LcI3wo7vHFR2CWp9BrWPUMj0w3ZZaC0w/xiOXNbT4IKFj2zRaB1OShK2 Cp4w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=ZGildrEZ; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-149945-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149945-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id c13-20020a509f8d000000b00571c0a02327si326191edf.311.2024.04.18.04.05.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 04:05:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-149945-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=ZGildrEZ; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-149945-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149945-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D33561F22DA3 for ; Thu, 18 Apr 2024 11:05:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A89F15E7FA; Thu, 18 Apr 2024 11:04:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ZGildrEZ" Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CFEAE15E5B2; Thu, 18 Apr 2024 11:04:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713438292; cv=none; b=LkoESuy9BWbBYA/6/lEWsx0qgQoz1yTzh5NCWIzMukkJelF9O0chR2dQ+3YieZhx3SO1SoHOw1Ca8I7+QGsntZ0+GP5tCDJlPeg3C7C5yJ6W0yYKxZIICAHZjSwatBobZ1T9Dl4cLK9P8EJp368agrVzPi/h8Youin6Tgt7xxxQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713438292; c=relaxed/simple; bh=nVrJ30MzRcVeLHpwfXp7hOiRaAkKYzwTLRPhrFm0ixw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=alSGiumo+V9k2YRcQ2BaJNgIho4VRcDW+xSghTRst7h4GPLohSpZ3he6b4n3Cc4gEYjui15HX5qf7cU+Po39AsxsR6EQT3yatq8JQd3FJlJtz70LsuE/DDLNYqhpyw5VhkN40D5KnRpjQdgpebrfJyVOHa5POm7D0Udh7m229Sk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=ZGildrEZ; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from pendragon.ideasonboard.com (117.145-247-81.adsl-dyn.isp.belgacom.be [81.247.145.117]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8ACEBC8E; Thu, 18 Apr 2024 13:03:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713438237; bh=nVrJ30MzRcVeLHpwfXp7hOiRaAkKYzwTLRPhrFm0ixw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZGildrEZ8PscbwJPkrVEQ9AVQQ5ZqsFtIzLjmF9plRRPHNE6nYXij+2WJ4wHeQ/Vt tbErl0bgSpuTcVcaqqltDwf7r27d4aQqy4R23+6SvyevGzwbJqe+dJwie8wJOCDzuq WkVX5b8VtifCgZq58ru+v0enMsxJOUVui5DkYPqU= Date: Thu, 18 Apr 2024 14:04:38 +0300 From: Laurent Pinchart To: Ricardo Ribalda Cc: Martin Tuma , Mauro Carvalho Chehab , Hans Verkuil , Hugues Fruchet , Alain Volmat , Maxime Coquelin , Alexandre Torgue , Paul Kocialkowski , Greg Kroah-Hartman , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Sakari Ailus , Thierry Reding , Jonathan Hunter , Sowjanya Komatineni , Luca Ceresoli , Matthias Brugger , AngeloGioacchino Del Regno , Hans Verkuil , Sergey Kozlov , Abylay Ospan , Ezequiel Garcia , Dmitry Osipenko , Stanimir Varbanov , Vikash Garodia , Bryan O'Donoghue , Bjorn Andersson , Konrad Dybcio , Benjamin Mugnier , Sylvain Petinot , Jacopo Mondi , Kieran Bingham , Niklas =?utf-8?Q?S=C3=B6derlund?= , Pavel Machek , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-staging@lists.linux.dev, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: Re: [PATCH 03/35] media: uvcvideo: Refactor iterators Message-ID: <20240418110438.GX12561@pendragon.ideasonboard.com> References: <20240415-fix-cocci-v1-0-477afb23728b@chromium.org> <20240415-fix-cocci-v1-3-477afb23728b@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240415-fix-cocci-v1-3-477afb23728b@chromium.org> Hi Ricardo, Thank you for the patch. On Mon, Apr 15, 2024 at 07:34:20PM +0000, Ricardo Ribalda wrote: > Avoid using the iterators after the list_for_each() constructs. > This patch should be a NOP, but makes cocci, happier: > > drivers/media/usb/uvc/uvc_ctrl.c:1861:44-50: ERROR: invalid reference to the index variable of the iterator on line 1850 > drivers/media/usb/uvc/uvc_ctrl.c:2195:17-23: ERROR: invalid reference to the index variable of the iterator on line 2179 > > Signed-off-by: Ricardo Ribalda > --- > drivers/media/usb/uvc/uvc_ctrl.c | 24 +++++++++++++----------- > 1 file changed, 13 insertions(+), 11 deletions(-) > > diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c > index e59a463c2761..a4a987913430 100644 > --- a/drivers/media/usb/uvc/uvc_ctrl.c > +++ b/drivers/media/usb/uvc/uvc_ctrl.c > @@ -1850,16 +1850,18 @@ int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback, > list_for_each_entry(entity, &chain->entities, chain) { If we really want to ensure the iterator won't be used after the loop, it could be declared in the loop statement itself, now that the kernel has switched to a newer C version. > ret = uvc_ctrl_commit_entity(chain->dev, entity, rollback, > &err_ctrl); > - if (ret < 0) > + if (ret < 0) { > + if (ctrls) > + ctrls->error_idx = > + uvc_ctrl_find_ctrl_idx(entity, ctrls, > + err_ctrl); > goto done; > + } > } > > if (!rollback) > uvc_ctrl_send_events(handle, ctrls->controls, ctrls->count); > done: > - if (ret < 0 && ctrls) > - ctrls->error_idx = uvc_ctrl_find_ctrl_idx(entity, ctrls, > - err_ctrl); > mutex_unlock(&chain->ctrl_mutex); > return ret; > } > @@ -2165,7 +2167,7 @@ static int uvc_ctrl_init_xu_ctrl(struct uvc_device *dev, > int uvc_xu_ctrl_query(struct uvc_video_chain *chain, > struct uvc_xu_control_query *xqry) > { > - struct uvc_entity *entity; > + struct uvc_entity *entity, *iter; > struct uvc_control *ctrl; > unsigned int i; > bool found; > @@ -2175,16 +2177,16 @@ int uvc_xu_ctrl_query(struct uvc_video_chain *chain, > int ret; > > /* Find the extension unit. */ > - found = false; > - list_for_each_entry(entity, &chain->entities, chain) { > - if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT && > - entity->id == xqry->unit) { > - found = true; > + entity = NULL; > + list_for_each_entry(iter, &chain->entities, chain) { Same here, iter could be declared in the loop. > + if (UVC_ENTITY_TYPE(iter) == UVC_VC_EXTENSION_UNIT && > + iter->id == xqry->unit) { > + entity = iter; > break; > } > } > > - if (!found) { > + if (!entity) { > uvc_dbg(chain->dev, CONTROL, "Extension unit %u not found\n", > xqry->unit); > return -ENOENT; > -- Regards, Laurent Pinchart