From patchwork Mon Apr 15 19:34:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13630642 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 E55BDC4345F for ; Mon, 15 Apr 2024 19:39:56 +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=6nr5NpTPg3+S6gVH+qauSg22tHuBGq1qfjLm59/dPm8=; b=XmlMnjYSMhPHLU uaiYfKP0oTMyGvkBLX/i0JjTMe1lh7QPaUjKZDwma4Fad2i668QrTHZGdQN1E25pgLJmX9k4509mS HS//xiJprwC/Gn4/Z9UvlnKzPPRrCOCwjwglGt249Bfm4Rlsch/wy1IcFX5fflHMrLSrR8Pol1UW8 Zi4zirpFzoryBjxXQvi4CE8ZIbjtKA5Xxt2giVGVY4tHBO1OzkLqWx+Q1ZQeHcAYZSw1rdV2RR20/ V43wwG2NgD3YYqdc/63rWtYoXOjS9QvH6LE03lznI/3fYVD2lHg3ziFzn0yk0baPQ8njGByr4cXYY xJVYAGlneMBwOoXFqs1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwSB8-00000009f2l-1AIr; Mon, 15 Apr 2024 19:39:46 +0000 Received: from mail-oa1-x2c.google.com ([2001:4860:4864:20::2c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwS66-00000009bqE-3bLl for linux-arm-kernel@lists.infradead.org; Mon, 15 Apr 2024 19:34:39 +0000 Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-22f01274622so2465032fac.1 for ; Mon, 15 Apr 2024 12:34:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1713209670; x=1713814470; 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=vq+7mr1szAOvpscJpegvOEKeeaK/lFJAotzxeoFP90w=; b=Dap2LoyWw3Fi1Z/EqT97uA7GS/XVpVRddFrGcjNzH9iBzbSYkJvkK/yQhqGb+aNQaP lXSewnUznfk1F25QudnR5Fg2SOEat7pg6lQ6R0/UClgGriU5TIMb16E8NbS+JFpkmJ/k u9HfERQiwVhZb3OIAsDuhk85JW0P4JATBiwvw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713209670; x=1713814470; 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=vq+7mr1szAOvpscJpegvOEKeeaK/lFJAotzxeoFP90w=; b=b0JqyYIf5hEM8/eJ2S4mVhFb8/G54XRIkkWmeV8ENfbsoH/AL6TllTgEntyqcAzBI1 HgUqa446Wke9YDgx5RwF89fwt/pC70t9AS9/1/sPwujxAhaxkheqCyku14uMgGlwOHd1 ZL4wvbFbmOcHRsfhYgCS5QWLRUSRz6xfr8BxwiISRRBRuzT3Cvk6Y1QLUQWLTlTbv+OU 0nLgQGWblZGLr5CzZUpvTQwMO65nVUmZY9TPH2XnppPZiwJ/VDSfiH5HanNpC7YLINwy EYReRsrlQk/cnbOUDn8u+zl1ca8hhKzqPN6lQgqzbBtqY/2vn022WGJEFHRO2J3CLadx /6dQ== X-Forwarded-Encrypted: i=1; AJvYcCVdc4IWaUiLO5NqjyV0rwA2W+6zHXvbMGUf3ii4LBNf+sATyK4yJPYJdcuJab4iAL0Bhb8PJwrFH/LlfQY93M6xrtj2LnN8/t+2F4rDcLpAFaEWl1Q= X-Gm-Message-State: AOJu0YyJloT0zC0K1VySiSBh2RYBkhkz1zAuMSr7PuhphbywnyriZlJP sHI+ay2KcjyJw4gF0R6sRtzmgkBCnXMrEQ3EosnGWNG0JraQBEvx8DVDAEY0UQ== X-Google-Smtp-Source: AGHT+IFDs72yHh14dMP/v3LcOXYq1AzGZaPkrHXx/btoSixg8uGduMLiI7a2hIPG7rGea4VcIV3D3Q== X-Received: by 2002:a05:6870:9a97:b0:22a:2e6:b82e with SMTP id hp23-20020a0568709a9700b0022a02e6b82emr13491647oab.38.1713209670403; Mon, 15 Apr 2024 12:34:30 -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 s26-20020ae9f71a000000b0078d3b54eb76sm6718055qkg.78.2024.04.15.12.34.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 12:34:29 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 15 Apr 2024 19:34:20 +0000 Subject: [PATCH 03/35] media: uvcvideo: Refactor iterators MIME-Version: 1.0 Message-Id: <20240415-fix-cocci-v1-3-477afb23728b@chromium.org> References: <20240415-fix-cocci-v1-0-477afb23728b@chromium.org> In-Reply-To: <20240415-fix-cocci-v1-0-477afb23728b@chromium.org> To: Martin Tuma , Mauro Carvalho Chehab , Laurent Pinchart , 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 , Laurent Pinchart , =?utf-8?q?Ni?= =?utf-8?q?klas_S=C3=B6derlund?= , Pavel Machek 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 X-Mailer: b4 0.12.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240415_123435_219729_89E63909 X-CRM114-Status: GOOD ( 17.41 ) 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 Signed-off-by: Ricardo Ribalda Reviewed-by: Sergey Senozhatsky --- 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;