From nobody Fri Sep 20 01:29:29 2024 Received: from mail-oo1-f48.google.com (mail-oo1-f48.google.com [209.85.161.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47FEA1591F8 for ; Mon, 15 Apr 2024 19:34:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713209675; cv=none; b=ic7qR4ze1S+2OJYampcJMsC5bv4sGAg3vQXqNcuG1T0EBDAJqrhcNbFNMT8NR7w07/zCzcNcgOoQj38Kf7DOcvOXBU9qwk29dku6uWHtAGSjy+Bcw92b9BhwO/B+oIqjQyIbhrX9RAgC9cgh+hAxqKEXUUz8lKCHtXDgRebN/9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713209675; c=relaxed/simple; bh=pkDHUvzM/3se4qU8yUrUNq79FeC7MKupjn4wDvpoFwE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Em4qTJmRUOfs2LIN/u5nzSgMFPwoAlZdS/LbPGU8gfhVoSVqeZDPkgBecXM0Qxa30JZiZCTnrFzhxS8nB6wcWqYB6iLG8hYn2UNvKlSRThg5WC8Us70CkYRrZN96AqcSb+Ig0aELL5NArsC11UYLIaSYM2/AUO6p+QtqVrgQpLY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=QYMJSCyQ; arc=none smtp.client-ip=209.85.161.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="QYMJSCyQ" Received: by mail-oo1-f48.google.com with SMTP id 006d021491bc7-5aa318db8a0so2414931eaf.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=vger.kernel.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=QYMJSCyQu2pYKBMrqNgWiQMA1aCst9SYKIqikmRxzmY52VuUPd47LQSHB4A8FAOoNe GoRnjaDRfZtd4YOqjawhovTXVtgjpUb2DcL7wuwLMUKLzVpuak6Macw9bONnoK0mGYFs DHrrqPs4QTJykLWjzpi3FrcxPl4AUXNIhzyr0= 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=o6M6agtTqEkGAGBNOhR/+6vk/aevysXgqOJ84WTpA5xUaCZ77LzG2R4rrJJ1M7pSz2 eYQCn9iloH838lwGcGbuIAV3Xxag2wAqEHB/nZ5rSO4Sos8U5N20mOCilY982Vf89GI9 SAfzYGAopcrclcWTSR8vx+rBx8NosUS5t8IDsXUiEHDf078ZVCKL6aEFVJgnOrsF5xM8 D13Tfo7OLjLw7Z4te6VYz8ZeCQ9O8OlZ6/u1XgMy1RFmj8/oYfjGnPz/vAEc/7VcuA5r ifKQdao7k5cLKTloXRobVxfOhajAa3VQiIteLlMwx2ywfqd3MKzWGpzD/LhdXHaNOyiT +/JA== X-Forwarded-Encrypted: i=1; AJvYcCXKh2DahTYnmM93gBYRtQqmVZ8IMqL5VfFq4I09cFKtazq5L2736EQcmWrRug8JkDn+wMSxTpc8xPVCWiRKYKxK1yxy00NLlSnvD0eh X-Gm-Message-State: AOJu0YzDI98/8tygLc9WM2YRqNODuuvL8JfzSwYefnmp3zfS4jM5bdPL VSvQgNkvhIxFTaRxZO9i7f9C1hsqZ8c1pyGAIdqxst3v901cpuFfRcsiNxj6Sg== 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 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-Transfer-Encoding: quoted-printable 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?Niklas_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 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 th= e index variable of the iterator on line 1850 drivers/media/usb/uvc/uvc_ctrl.c:2195:17-23: ERROR: invalid reference to th= e 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_c= trl.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 ro= llback, list_for_each_entry(entity, &chain->entities, chain) { ret =3D uvc_ctrl_commit_entity(chain->dev, entity, rollback, &err_ctrl); - if (ret < 0) + if (ret < 0) { + if (ctrls) + ctrls->error_idx =3D + uvc_ctrl_find_ctrl_idx(entity, ctrls, + err_ctrl); goto done; + } } =20 if (!rollback) uvc_ctrl_send_events(handle, ctrls->controls, ctrls->count); done: - if (ret < 0 && ctrls) - ctrls->error_idx =3D 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 *d= ev, 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; =20 /* Find the extension unit. */ - found =3D false; - list_for_each_entry(entity, &chain->entities, chain) { - if (UVC_ENTITY_TYPE(entity) =3D=3D UVC_VC_EXTENSION_UNIT && - entity->id =3D=3D xqry->unit) { - found =3D true; + entity =3D NULL; + list_for_each_entry(iter, &chain->entities, chain) { + if (UVC_ENTITY_TYPE(iter) =3D=3D UVC_VC_EXTENSION_UNIT && + iter->id =3D=3D xqry->unit) { + entity =3D iter; break; } } =20 - if (!found) { + if (!entity) { uvc_dbg(chain->dev, CONTROL, "Extension unit %u not found\n", xqry->unit); return -ENOENT; --=20 2.44.0.683.g7961c838ac-goog