Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp917310pxx; Tue, 27 Oct 2020 03:58:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzttKUzMgbaPi8LmHQ/cI0JJBfvB69p+RbHsdyP35ry42YsC+keWcprnXlVl1CHS0S9Y25N X-Received: by 2002:a05:6402:1c10:: with SMTP id ck16mr1605490edb.7.1603796297088; Tue, 27 Oct 2020 03:58:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603796297; cv=none; d=google.com; s=arc-20160816; b=pAJSg2yKChxkpjEnHQawmA+8LiZjLHsDI0HccPVKIm7Ap0WYpTgfHg3yA1aUUsAW0Z UAC0Pf3X9XLP7w0uq0gozFIKQfb0QQNLlHpgsrhzioQNcpX2uXsKck2QGf9heNMsytCg /7vfIYbza2faLstzZqB5Ch214HnN5WDTQGPx/HwJ29SByyg5N56qPFOu77xWfDDaLYpg IIe7GbmijOl+HN5wsbMvZP561z/jjokb4SZmcP9mE/aA3+q6PDvI3unc0KP0/iETjv3a ucFxCxCJWzXrI7T1W9wzspNSPUW+NRRX/V86ncynSTT/9KrZaptxISekQC01LqKNFerc hhLw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xy9pkiaO/sCXowPYiDdBOKqqY8rLa62WwWqZY7P9I9M=; b=cm12/+8Gh947Q96L7s4TGkA5SEgNDrdqXp6DDykMw9HfBa5JBgLt4oVeSO+/YfG2Vm EKm/uhvVtshgMQczd3yLc+XCPMsKkZKRlqM261FpytnY6NdnflGSIoyTDrEKtQNqT8Tw 1gLdg0LTmiwkbZZI8QbngOLiyqoIJTLoQNLbeOKRgSRBiS5+VoTBjcKIx0Ra/ZNUOgkr gYW+aH6CKj7CFt7dFU3fPV/6rBkPc1KZeBb3oASjtn/xfleAyjX9ic55ipzi6LtSLIz1 NhYO9C2Mm67B4niHBs/AIPjN3bN63a7o7yxCWsUNNv3yjrqJIkD0oZj2oPyhEHCOVtxl H7ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RPZv+6jU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qn3si730268ejb.655.2020.10.27.03.57.55; Tue, 27 Oct 2020 03:58:17 -0700 (PDT) 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=RPZv+6jU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437617AbgJ0AEK (ORCPT + 99 others); Mon, 26 Oct 2020 20:04:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:35128 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2411013AbgJZXz6 (ORCPT ); Mon, 26 Oct 2020 19:55:58 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B38272151B; Mon, 26 Oct 2020 23:55:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603756557; bh=sJKzSfQY8uzihmpRwVTN/EAgVg3GpFoCkG/vfM+f3PY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RPZv+6jUqRSM3s4GlvydfBapttMaIgDgS1aYQzGSwAg5bDb9IMrbdZrg9BCTyS2Jc bNK8es2jqxuffbY4jOLJ3XwnV9eq+ozH1fMEYoLnjy7VdBmtpxhi9Hd8QdEbGWamPP a8mYYpl3OeVduAlrBvN3yfGE4ozZWJqnc1n1hDdc= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Daniel W. S. Almeida" , Laurent Pinchart , Mauro Carvalho Chehab , Sasha Levin , linux-media@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 33/80] media: uvcvideo: Fix dereference of out-of-bound list iterator Date: Mon, 26 Oct 2020 19:54:29 -0400 Message-Id: <20201026235516.1025100-33-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201026235516.1025100-1-sashal@kernel.org> References: <20201026235516.1025100-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 e399b9fad7574..aed84528758f6 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1844,30 +1844,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.25.1