From patchwork Fri Apr 19 09:47:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13636224 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 40CFAC04FFE for ; Fri, 19 Apr 2024 11:01:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sfo0iM2eHw1fSqYwx52VgfUncVEx/GOextdrvZCGbus=; b=xgu1SsOL6WHHzY /tIecCzVxQAx44fG07Gm/YcXF7AjwBIbeKMnblVanEtgYAx58u9/Cxfc7poRZgWAVSDAJug7jL58i E/haPVzD5cUHlEEDFpb/eE0CCzt92vdPQExBrAYhoHp9Ait1CeiTzDGPeliGvlgNTItev2NzYDag6 Kp5XjGNbEnwV1qye5MOCimnl5uZWzkUxUIfp9zOZc2kjVIk5OWgOXlJA8Z1CaiERVVH3WEdmojJdx 8QZ643GdhnWftxJk0/hYfrz4E5jSeilc224p3ZAOk8ZczFyn3q50EUYrI6duhhlaMmUhaIMfL8KJW BgmzsW9YaWpqGKzqh7hw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxlzn-00000005Nng-3zek; Fri, 19 Apr 2024 11:01:31 +0000 Received: from mail-qk1-x72c.google.com ([2607:f8b0:4864:20::72c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxksB-000000058qt-0WBc for linux-arm-kernel@lists.infradead.org; Fri, 19 Apr 2024 09:49:38 +0000 Received: by mail-qk1-x72c.google.com with SMTP id af79cd13be357-78f02298dc6so151324685a.1 for ; Fri, 19 Apr 2024 02:49:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1713520163; x=1714124963; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=2ozatrqAUW665TsgI+DgE6yWy8Evw1+ngHGTHDukygk=; b=cYzd7AR+I0kDzZxmUOUBO7rkmvOlZ1IERsxkRG+PSGAMSSB+vRpVW6xk5g+TwPdPx4 BmowT1Hx9KJM15grRacDI0iOc9JEcbAt3A414bdTWILrUAbSH0c3JJKFWBr6N/gKM41R S8LLeV3md4IpDJA26CfMHGh5XWhqi1R8eyXYI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713520163; x=1714124963; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2ozatrqAUW665TsgI+DgE6yWy8Evw1+ngHGTHDukygk=; b=P+Y0CeWnOHEnNKUvAAWsHXPb6cMs+s8khF7PPLCXPutOPYu/Jutx1iz1ft+Inlt3Zh IY8p+lNhADsQb4hP1wLlWVS8q1wbImL9EM/iXOhA6A75Lf+SUoPJiRZfy3xGLNSKlBd0 oSekHrXxyEKOilkJ5wHduwAF+AbCSHFHtOnIwsXltc4qfdhgMhw7s4+WSXC6pgSY5nWV OdyNULpYrzbQjs2EYVss/Ek7uMZxr6pQBAE3vzJ5AlhrbtVryReQDmnGBCql8MCzCN7D PN2gTsWjdwQyueLU7gE+yjMYGjTlHBGb6YgahBFlWjP4UGorIiOZdFMrk9XMa6HwGTTr Q0Yw== X-Forwarded-Encrypted: i=1; AJvYcCUe1rjdLnLuJlnYn0Mlf96ve6rdPzz4GVRvZ/gWGEJKfn+co9Hbx9kzGtsSYe26khytINDN35XRZzhbg1yUBlhFlPWkjUJELV4FpQvzDPFvt46ICX8= X-Gm-Message-State: AOJu0Ywbc0PDHz30G9j7WSDaLcmMpJ9KhKzbJps7jvkm+vP3+1jBLP8O +bUIE/d3HQUZYjIoztW2b02W+P1iNYh3TlErbgIEJeDWoF9MZ/d54BcpWQipMA== X-Google-Smtp-Source: AGHT+IGs3CfAvghko2vWhqg08VmqqoJ6LlEsRGr+WfzIJbh8ON10G5msy3tcDSad7YCzEwumD2LtKA== X-Received: by 2002:a05:620a:44c3:b0:78e:e679:23cf with SMTP id y3-20020a05620a44c300b0078ee67923cfmr7789538qkp.1.1713520161754; Fri, 19 Apr 2024 02:49:21 -0700 (PDT) Received: from denia.c.googlers.com (114.152.245.35.bc.googleusercontent.com. [35.245.152.114]) by smtp.gmail.com with ESMTPSA id dt14-20020a05620a478e00b0078d735ca917sm1434532qkb.123.2024.04.19.02.49.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 02:49:21 -0700 (PDT) From: Ricardo Ribalda Date: Fri, 19 Apr 2024 09:47:49 +0000 Subject: [PATCH v2 03/26] media: uvcvideo: Refactor iterators MIME-Version: 1.0 Message-Id: <20240419-fix-cocci-v2-3-2119e692309c@chromium.org> References: <20240419-fix-cocci-v2-0-2119e692309c@chromium.org> In-Reply-To: <20240419-fix-cocci-v2-0-2119e692309c@chromium.org> To: Martin Tuma , Mauro Carvalho Chehab , Laurent Pinchart , 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 , Benjamin Mugnier , Sylvain Petinot , Stanimir Varbanov , Vikash Garodia , Bryan O'Donoghue , Bjorn Andersson , Konrad Dybcio Cc: 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, Ricardo Ribalda , Sergey Senozhatsky X-Mailer: b4 0.12.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240419_024935_337000_7F765F0C X-CRM114-Status: GOOD ( 17.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Reviewed-by: Sergey Senozhatsky 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) { 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) { + 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;