Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp819335pxb; Tue, 3 Nov 2020 13:26:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJxhH/VDMEVvI0Hk8mbom3MekqjAboTAm78iOtof/b1VEfkS0zdAUczhEqm0Wzb+DiPSfPzW X-Received: by 2002:a50:b5e1:: with SMTP id a88mr14071224ede.5.1604438813354; Tue, 03 Nov 2020 13:26:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604438813; cv=none; d=google.com; s=arc-20160816; b=QUW8FoflNwQE7aTvDRu8kdRQljSEQo0UNU//KFBQ5lE74P59YO7zq9PQrj3Kd16JxL 4+71oTokRloTTU2bzuf930qiJ3z5eQswoUXvC41AOexg9+nPs2ZH8RWNS2Q0jjGFCkfr s/KGIrR3aPe7+YbS//FWhDK+eQinYC618ee5j2IipP8s1ZPSKM2TIqo5G9cF40B569A6 t04grLPA5SIhVK9u2cVC9ElK3qkzJJ2FnWH21xfJCw+zR7uWUR00f+mYdHGouGe0C4hW QBLuyJDFeZO3UI/683/crLB/z3qGJSDBGobnuKMLxHPuDeL2uT5p0s20+k5MdLSNVlYc zGWQ== 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=Fn1CkhfIJlqXTEQBvmSWm2ZE7iWb9a55LKe4LLzYcHs=; b=Y+XQ8yB/r7Fjgd4+IrJtBJZU92a1pUNvw9kI39yHklWKn/SUfkZJoJ2wfHSSToMhcV eYfhd12lG21x4wxq4kFdjThORfAiwmSStJsBYuBwAiaFtO8dvmTu0uTaEC6WuOywj9JM ERzAOz+jHvF7z7LrVJGry4jqnq7Xr7rLHaO8dXQ4BNpLMPjfPOzOi1BJaFGlQ22iYQSt 6+0h7obUCdj9j4N0Ed+qiOD7L6Sd7IxRP++iPZOlbGesaAt9F1z+4HFXBp3ZObRdtwLC O0OkG7MQl1uxxU2glYVLqSBQLo6lFwM9zv5+MbzDgCU2Z0n6c2aiMSA+7nMURkWjziMl uudQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="g/Bisenc"; 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 j15si9868180eds.511.2020.11.03.13.26.28; Tue, 03 Nov 2020 13:26:53 -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="g/Bisenc"; 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 S2388300AbgKCVXv (ORCPT + 99 others); Tue, 3 Nov 2020 16:23:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:42120 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387948AbgKCVEJ (ORCPT ); Tue, 3 Nov 2020 16:04:09 -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 AB45B205ED; Tue, 3 Nov 2020 21:04:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437449; bh=HIdxGsPh3dLmu5Mvr40uHDIRJNb8g73/lmYsiUUoTtE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g/Bisenc9dBX7KttjuF25Kpuw8Oo0quiuQIMbTZR5jsYehcXTHwvUnswsKJwje7ad KirT0APFYL6g/ONs8FRDjK2XR93fRdtzAVrIzD3UZcranMheCR+i67QPXK+Y0r4AQ3 fleAbgtpT1cID8CcdK7QIJJ2hP3ShyUcN0UYMJ3U= 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 4.19 080/191] media: uvcvideo: Fix dereference of out-of-bound list iterator Date: Tue, 3 Nov 2020 21:36:12 +0100 Message-Id: <20201103203241.704909550@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203232.656475008@linuxfoundation.org> References: <20201103203232.656475008@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 abfc49901222e..843dc19bada05 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1853,30 +1853,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