Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp795836pxb; Tue, 3 Nov 2020 12:46:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJz3Rp62Bk42QF1EWJbfUI791oY/XuxBhJV+quvT1AxCb0esEvgEsimSjyAJXkNK8p8EaOCw X-Received: by 2002:a17:906:f753:: with SMTP id jp19mr21539414ejb.280.1604436361926; Tue, 03 Nov 2020 12:46:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604436361; cv=none; d=google.com; s=arc-20160816; b=1DsJe2uTLddp3z8of5bspHnV1v0n14F/P8CwxsWX1jTHCSlhXo+h53Kiq8siEK2QKW 2O3gPR5+IsfqEeM43rSKURy1mMbgN3TxW8AMzmqG/3YoNxfhVuzE5PdJc0VLndXvZdNk LQElS0ysrN27TXAF5B+QalaD84TCEqGhb1yaXRZw1Wja0TVJJ521HUmo+TQP3OOCArGl EzXRuampMYXbB+sgil1DsTJin1gaWfDNlOZW2LFx1qy1IEfTzaixsM4M9z7Wy3B947oi fGogZehcjreb0XuYdYf+Y5EdKU5ul1Ku/T/vgtFlD7AiZRLMwnjZk4pT1GTSrivrGhPR oIcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tB1ORG57bUZ6N28uzLHwO3KFi2IvOA3mVKKz5nxhGpk=; b=Pa1blDlkcD30JRaa91yarMD/tHkOYcrI0xIy1IVaPfaoJiRjIzn+fZl/OgJldSff75 JNaeqw8qJ+Vhx2wXunJo+hzfOtATrCik4xirTLxZ+W92gpCHIAScqSU6XmoyittboBf7 0lFRFu1OzupO2R80CVFddx4sx9U3ZhfxDTwmhL1UNqukorgp9AmkgvbMooCs5QqnSaE3 S8zBACl3mkwqRmvwvdEZRlf63nIdfwbXsibJaZrYR1/xMU3gvUkNpSqnsjGXxPNO9x2D 6K8ID/7lP1wBhonoFDylPUlHIw/e91WGwg9g3F2t+v8hp3lmLgiOeSz9z+QWscsSzfPq cFLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1MULf3h9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lr3si11384ejb.40.2020.11.03.12.45.38; Tue, 03 Nov 2020 12:46:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1MULf3h9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730673AbgKCUnP (ORCPT + 99 others); Tue, 3 Nov 2020 15:43:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:56614 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729964AbgKCUnO (ORCPT ); Tue, 3 Nov 2020 15:43:14 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 49C282224E; Tue, 3 Nov 2020 20:43:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436193; bh=J8KuJl1/K8rhrVW1l2iJSlUTzFLshYrulf04j/Hssg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1MULf3h9uDqnuWkMmT3384S+K2orwvWmYyaKkAs/ApYfRJmL7r8zCRVuh1wHPIq2Y v6394R/DCm4hPDzQhmAwA2/a6+vk6N+qqmJCs0r0PAaETnRbgLnkYava9PKNHpl6pi ailvrQa4cRf9AJMc8DpGBTv3NNgtcxseK5nXcgSI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Daniel W. S. Almeida" , Laurent Pinchart , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.9 105/391] media: uvcvideo: Fix dereference of out-of-bound list iterator Date: Tue, 3 Nov 2020 21:32:36 +0100 Message-Id: <20201103203353.910358959@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203348.153465465@linuxfoundation.org> References: <20201103203348.153465465@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel W. S. Almeida [ Upstream commit f875bcc375c738bf2f599ff2e1c5b918dbd07c45 ] Fixes the following coccinelle report: drivers/media/usb/uvc/uvc_ctrl.c:1860:5-11: ERROR: invalid reference to the index variable of the iterator on line 1854 by adding a boolean variable to check if the loop has found the Found using - Coccinelle (http://coccinelle.lip6.fr) [Replace cursor variable with bool found] Signed-off-by: Daniel W. S. Almeida Signed-off-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/uvc/uvc_ctrl.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index a30a8a731eda8..c13ed95cb06fe 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1848,30 +1848,35 @@ int uvc_xu_ctrl_query(struct uvc_video_chain *chain, { struct uvc_entity *entity; struct uvc_control *ctrl; - unsigned int i, found = 0; + unsigned int i; + bool found; u32 reqflags; u16 size; u8 *data = NULL; 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) + entity->id == xqry->unit) { + found = true; break; + } } - if (entity->id != xqry->unit) { + if (!found) { uvc_trace(UVC_TRACE_CONTROL, "Extension unit %u not found.\n", xqry->unit); return -ENOENT; } /* Find the control and perform delayed initialization if needed. */ + found = false; for (i = 0; i < entity->ncontrols; ++i) { ctrl = &entity->controls[i]; if (ctrl->index == xqry->selector - 1) { - found = 1; + found = true; break; } } -- 2.27.0