From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5431F1A680C; Mon, 13 Apr 2026 16:41:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776098489; cv=none; b=JNQwkLTkj45JTI4pxNYYdgSjDyowC7/ZMBvnsra30xkk8uWV4I1G2zFfztgUa2WiB+T3PDXOQsOdekhIAZ3ey0H9MhHYQYqry1BOKid6hzjQ8FTts+UyYlQsL7eAJbmS9x8Z+KaC/NnLcLeErYs7RRoqe7Vj73kD70hITDk0be0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776098489; c=relaxed/simple; bh=UZilX/XYL3Ds2HbrnRveZvS//TG93H9p2YHUoTYEAv4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AWxeYnd8hUrw2XOAuPKVsUR6QPuTbJdHYcXlN5Rrl7rUQYs9JuZH0DFtxttbGfHD8noN2KjKcYbK3S6aXqaIjJr1f3pcYZV0EapF+ZkDbA7U0EPYhpKkwZoH4EsBMpx28XDBxMbyJG77oVpWVEOX+kOKeTaOyKm6K40ROgYxS9Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=swoIHeju; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="swoIHeju" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE681C2BCAF; Mon, 13 Apr 2026 16:41:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1776098489; bh=UZilX/XYL3Ds2HbrnRveZvS//TG93H9p2YHUoTYEAv4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=swoIHejuVX6PQZJ1pZ9dVk4/WKkFyCAieqezS8qDIynbJprAaTexZ452KiIHfF3uK tOXPDRfhkJn6klBDiFrv+1vTkE4VFsHFqYy+UshAZw4Onjsjnz6/blvw65wVL2UgBM FmdppALg8ukv8g2YJy0g4h34OofZj0C40xvb29nc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Angel4005 , Ricardo Ribalda , Hans de Goede , Hans Verkuil , Sasha Levin Subject: [PATCH 5.15 512/570] media: uvcvideo: Use heuristic to find stream entity Date: Mon, 13 Apr 2026 18:00:43 +0200 Message-ID: <20260413155849.628904394@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260413155830.386096114@linuxfoundation.org> References: <20260413155830.386096114@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ricardo Ribalda [ Upstream commit 758dbc756aad429da11c569c0d067f7fd032bcf7 ] Some devices, like the Grandstream GUV3100 webcam, have an invalid UVC descriptor where multiple entities share the same ID, this is invalid and makes it impossible to make a proper entity tree without heuristics. We have recently introduced a change in the way that we handle invalid entities that has caused a regression on broken devices. Implement a new heuristic to handle these devices properly. Reported-by: Angel4005 Closes: https://lore.kernel.org/linux-media/CAOzBiVuS7ygUjjhCbyWg-KiNx+HFTYnqH5+GJhd6cYsNLT=DaA@mail.gmail.com/ Fixes: 0e2ee70291e6 ("media: uvcvideo: Mark invalid entities with id UVC_INVALID_ENTITY_ID") Cc: stable@vger.kernel.org Signed-off-by: Ricardo Ribalda Reviewed-by: Hans de Goede Signed-off-by: Hans Verkuil Signed-off-by: Sasha Levin --- drivers/media/usb/uvc/uvc_driver.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index c39c1f237d10e..1cd68501fdc50 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -443,13 +443,26 @@ static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev, static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int id) { - struct uvc_streaming *stream; + struct uvc_streaming *stream, *last_stream; + unsigned int count = 0; list_for_each_entry(stream, &dev->streams, list) { + count += 1; + last_stream = stream; if (stream->header.bTerminalLink == id) return stream; } + /* + * If the streaming entity is referenced by an invalid ID, notify the + * user and use heuristics to guess the correct entity. + */ + if (count == 1 && id == UVC_INVALID_ENTITY_ID) { + dev_warn(&dev->intf->dev, + "UVC non compliance: Invalid USB header. The streaming entity has an invalid ID, guessing the correct one."); + return last_stream; + } + return NULL; } -- 2.53.0