Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp519943lqt; Fri, 19 Apr 2024 02:50:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWAlqLAU2YY8TsBpeXKAViekW/QK0odBiQ/QygZtzbkAgMl46DD2w3lShIwpVBLcw8SRB16pp3UjU7b3TUIphgpfi0G1cCsiZcHs/qRvw== X-Google-Smtp-Source: AGHT+IEHGnYLwChquI8vvv+RYF0m4KyZIQ5xyD6rEfaEFMF5SMZR/iN77GudHwl7vNC7umbu0oGz X-Received: by 2002:ac2:5294:0:b0:518:93b6:99f8 with SMTP id q20-20020ac25294000000b0051893b699f8mr1011878lfm.14.1713520233380; Fri, 19 Apr 2024 02:50:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713520233; cv=pass; d=google.com; s=arc-20160816; b=eYbyj2U+Bfv2ZvXsJNU8CbiIYJqnTmpwJu+JZCcGJrEcEZltqt5G/FUijGS0xRPD1c VYMdRAx5CPc4lpqiae5bZAUH9l6OgF783a6V5U6sBhEOOxaYMmBz2sfAEKDbfSYflZPs hsYIV2YxZYhPbP6uIcP48GA5BIlQx2MhUYu6drqcmJz9YqiHXx4SBebursUoC5osSka4 INEfpUpVcJKN+SUrBe7RJuU3Y1+IQIvd6yZN+To9UKDftx+IQVj5bGIBVuYbAsHdT+Yx fTkRGHNA56CAmJuncFNhKezD0WqWU1B2dtvhJMBS5H3SL8OtDcVKqwKFYCAiHZzWl5du lyzg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=2ozatrqAUW665TsgI+DgE6yWy8Evw1+ngHGTHDukygk=; fh=YipPsqutMDWaR/CHlqwvJFvrYHaw3lL+AHIgd51YKKo=; b=Engp3rtynAixd5fp9z2Z0M88yfwBFZj1imoHMF51rhFEMpdSW/p8KBTqKY4Y8hm9VY L99rbzmRzFPloGHWUjde80LUmiJSpqCp/l4NDwb/gCZqI60488vyqRs+5BGUEITwsOHg iATBrBsHlv26DGDqER96tM5KQREeFixE08kkcOA3ds3bkKYkJ9ObH6CXyiYc3kH0vGxE LlKiDTedAGtoCjna7xdxptVW/MIyrHA4IQw1tJSB4LCLkhxgkSfB9xlS9QXVI+XeB/HK S5MevNKJZJjRuffkgQy+J+qxlpMHAUR7XPB22Zk7r5XlshNGEf6Drk6D3Do3NAt3KH39 Ds2g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ltmAlTPH; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-151250-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151250-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dv22-20020a170906b81600b00a51c41eab82si1955925ejb.475.2024.04.19.02.50.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 02:50:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151250-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ltmAlTPH; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-151250-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151250-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 E8F741F21FCB for ; Fri, 19 Apr 2024 09:50:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7FF5B7E77B; Fri, 19 Apr 2024 09:49:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ltmAlTPH" Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (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 9CEBB7E789 for ; Fri, 19 Apr 2024 09:49:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520166; cv=none; b=amaI1UmTiOowfQd395/kVqgkeKCOpUvK0zm41XfpiNGux8bRX/aGvJ3KNO7pPGgVZ+b8p8l8ER9XFz3fW/ccz7eyhQSTLoQy5lx4umSCcEGfWZsEqlsgbaihIYgLj40hG08ifWv0AVWlVY/OugkmbjOqonGw0uBMeYYRvtcIanw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520166; c=relaxed/simple; bh=aCOVg/xdFhv2EBcNOEYrMjPDRpEiw9QSINiXOqCVcuo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IXERg+LObnO/CbIyih5O0Vs1PwjKhJMNYGwNJvhHOXgB4hL3rE26g0EsaRprV25rINbtmo0RfxRZMSLzAoeLjXz9w6r1fcLI2IdDuy0SvZ4/WvYzvtqVrc0BdFoJ+MTvVthcGFjAxDUKHxp+YNb0htvW8a1JcJyCwNRFtRgpjCY= 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=ltmAlTPH; arc=none smtp.client-ip=209.85.222.176 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 Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-78edc3ad5fdso150395985a.0 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=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=2ozatrqAUW665TsgI+DgE6yWy8Evw1+ngHGTHDukygk=; b=ltmAlTPHH6tGsIX0I0w3dE93cbNMtF1ZH09z0sz4thsRKJh827K5oGlDpl30ea9iNX DmHJbu0NvcLr6sm4pdiaVg+cLUPW0AQPDkCMJTkst0KTqBmYtHp73mnaliVOHSsWclaK gdIv1a2Ozp12QMGpbw0tP1gc2948oSCZDhYws= 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=qFJa8Q+k4ux/5qPXcAFU75sQ4dFCsxkUnud45cEr/AMf+TKq2SNaeq7AIOHahPTOnE s1RhgUA7yT9zYBFyiYKZCmOD8W52KL+X91Ii90BqYZ7KYPpyZlOkSbDsE2utoIZFgsPK cYCzGAhWoE+C2uwUN7lCDXP04N7BX8KEMhQ4eUtS8LpSiim80beQ9vQokIsbvouJIy2F BRfv9R+/SNIMwAp4H19BlNGo7h7szHst9LjdtW2yi6E7kBibOsH0G/9gqMr6rFxFGwI8 1f5hXFgggi7VxHoigCapiqRUtYykXAYOiOWUiOuQ7tiTbhcgGJJAarXZld220iesHFpr qzmA== X-Forwarded-Encrypted: i=1; AJvYcCV5lwWAh8AgtUUU8oQmOt3rkmn4looVdgB4hzBXMUhmVYRx4fp6oOJB15BeoJz2vKCa8TH06EfI6jVfjH9QBOXTe/mqcCsn0Jpa1k6e X-Gm-Message-State: AOJu0Yw3FAO0Y7uCTkjcwiwoxrwnEhOFWuvjCj9c67TB/D5me7aLxbNq EBcjVZM4ptTpx+972+kDv+Ri7uJcjZkVNMztZA9EJ1irbWTwEEnQ9Y7/UWr8Dw== 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 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: 7bit 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 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; -- 2.44.0.769.g3c40516874-goog