From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ZGildrEZ" 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-media@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