From nobody Mon Feb 9 07:26:01 2026 Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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 B7E8625A659 for ; Tue, 21 Oct 2025 09:14:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761038086; cv=none; b=aN7eHaCp271joeaQsg/w6R2QlMKm5bP1HNeRRts8jMUajIKjtoP8YP96utgyRAVqfVLsCwtNj4pQFCUUv4NpLxei/NPvtT23aoayi85mDfXEAijiq+t/3ZDot7BarQmHkPqT0fVuhsJJW0irm6eFkBZw6ZGfjc3qL0HNVFuaQfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761038086; c=relaxed/simple; bh=RJz1gmSDlGr4YU/FQOkFmnqOy83pufixi4dMVGttuxo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=ERFEG6lzJaf7cSNDzk/GbwBuEA8aUH2+8Yw4hM92ZUpH5f9LmNAOxpU6+1WeLicm+ii77hOPtypKcVoHaG9WPNXhelwao2VU29nReQk9IAUC6OXQnNvUC1LqbQsOC+p4EczZ/sL+woiYUzpFSWCuz7EgKBQetSC5elZnDHHGxlw= 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=QJyrbGB5; arc=none smtp.client-ip=209.85.208.181 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="QJyrbGB5" Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-36639c30bb7so47903361fa.3 for ; Tue, 21 Oct 2025 02:14:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1761038083; x=1761642883; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=l8NKSLNa12tSl0xnMWLTKKteeShNaLZEYQs2solQ/gE=; b=QJyrbGB5TbkyDCgBX03C+IXe8AK6UFTH2FGixdSu8edV0Kkt/CG3esdjgpPHLb5rsm iRgsmzGxuVza/czLdJ37N6ec09K2BFLzTxuWShEK8nRf4xhW0KWBG8fhFYQNbe/jrXTr vtvbvFmPhLWuNVSjFDiSVBb3/bPqEmVin5VYM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761038083; x=1761642883; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=l8NKSLNa12tSl0xnMWLTKKteeShNaLZEYQs2solQ/gE=; b=iXG50mmRJXpt/zIs0hjFbXP9Wd1azLpZuLe5lC2wbv2NaQMDTqN5JaQntLTMhq/iHz tORT95KgRxZckBVhTHppKTnx3u5Ll3vIhNcPnpAivV7bDuYCsbXpDj6m3MDKSkQjpkWc VBBJSjlRTmB9H0tLhIlJIA3ZKXyVrRgBV/4hbxYHxOAgQ5cVxZTWXnUn0W6Pyd6fNBOT atKpCMYLoN1VBpqECfQwYLUsNsq2McaZSQt/lbgTTUyMlzjuYDBZqu+dIOJ6P7G8gPlC GMeD/loYDgI97iIyK1oNYD/76o31TlWv/j/tyhm0aqJGJ3FDGpbxem/3pU8qenzUK6lB HNIQ== X-Forwarded-Encrypted: i=1; AJvYcCXaui2d7atDyeUEz8R6oJTiOumSjXjPEWzsexQvBq3DR338XSjYeGXA4tFOBM4m4a5/Zr8RbcjXu3267ns=@vger.kernel.org X-Gm-Message-State: AOJu0Yx7JWsoh+ppM5ShJrqaaNJ/Rm7auZwQpbu2gtLPSTjSILS2S8es EHS7OUfH/C8NWolaCbSKAhJVa2wundzWtAU7Ygqn8Tw+bv2xO97jmeAiCkX8aic5fg== X-Gm-Gg: ASbGncsJPjpjf98Ih8DQcjPcCTA60rgEULIlPFZTYPSlSboSALKVbrB7j1Qdt4jesqr /flZXmBdK78ORURhFrDkFHtj7ytzhBPlWt0P7ICt8MKpuQdi8Pd5a9vAIftato3EibS4A8D8kIf KYHK80tETlCdnwZkmUWh53XDuSeL1LiKLOLGMho1f4rBlwWwzHRUjmOl3bxElCtKC+cDNbj2KNc 8vax3aMXLVSW8RxVATDNDk4ukakQQ0o2qITvHpCVjpm9D58u51hSXgapB0GCkGdH07U8D/i3WLM 0ScBYHgEBv1Ks6DFCt2dL2AwtpVvxd+cuyiqi89/6j24pTwI3oY6Zzg3U1ENYBDhjUbXe69CGdK q0J1D7aw3Nyk5ToA+kkMbNNILbgsUoBNgzTu6LyFnq14kKN8OyOccNwmHqoq61xkuLsNmLgSpFF uxPCc+XlIHoLW8E21Vt0m9IsiaWNf8vUA8HEFx/h7ptIOw3WXmgMXZuwc= X-Google-Smtp-Source: AGHT+IEPGiWt+dwmwhFaFuPI/HjRccA8O9WNKU+McJli7NGKFUa8kvu9epeIJvHuqYsATf6E9wBGhQ== X-Received: by 2002:a05:651c:1a1e:b0:365:e848:b7a2 with SMTP id 38308e7fff4ca-37797a6bfdemr47827171fa.33.1761038082750; Tue, 21 Oct 2025 02:14:42 -0700 (PDT) Received: from ribalda.c.googlers.com (166.141.88.34.bc.googleusercontent.com. [34.88.141.166]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-377a91b73d8sm27728341fa.2.2025.10.21.02.14.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Oct 2025 02:14:42 -0700 (PDT) From: Ricardo Ribalda Date: Tue, 21 Oct 2025 09:14:40 +0000 Subject: [PATCH] media: uvcvideo: Use heuristic to find stream entity 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: quoted-printable Message-Id: <20251021-uvc-grandstream-v1-1-801e3d08b271@chromium.org> X-B4-Tracking: v=1; b=H4sIAP9O92gC/x3MQQqAIBBA0avIrBN0oJCuEi3ERptFFmNFIN09a fkW/1coJEwFRlVB6ObCe26wnYKw+pxI89IMaLC3Bq2+7qCT+LyUU8hv2vQUokHn4oDQqkMo8vM fp/l9P2vf8P1hAAAA X-Change-ID: 20251021-uvc-grandstream-05ecf0288f62 To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Hans Verkuil , Thadeu Lima de Souza Cascardo , Angel4005 Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.14.2 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+HFTY= nqH5+GJhd6cYsNLT=3DDaA@mail.gmail.com/ Fixes: 0e2ee70291e6 ("media: uvcvideo: Mark invalid entities with id UVC_IN= VALID_ENTITY_ID") Signed-off-by: Ricardo Ribalda --- I have managed to get my hands into a Grandstream GUV3100 and implemented a new heuristics. (Thanks Yunke and Hidenori!). With this heuristics we can use this camera again (see the /dev/video0 in the topology). I have tested this change in a 6.6 kernel. Because the notebook that I used for testing has some issues running master. But for the purpose of this change this test should work. ~ # media-ctl --print-topology Media controller API version 6.6.99 Media device information ------------------------ driver uvcvideo model GRANDSTREAM GUV3100: GRANDSTREA serial bus info usb-0000:00:14.0-9 hw revision 0x409 driver version 6.6.99 Device topology - entity 1: GRANDSTREAM GUV3100: GRANDSTREA (1 pad, 1 link) type Node subtype V4L flags 1 device node name /dev/video0 pad0: SINK <- "Extension 3":1 [ENABLED,IMMUTABLE] - entity 4: GRANDSTREAM GUV3100: GRANDSTREA (0 pad, 0 link) type Node subtype V4L flags 0 device node name /dev/video1 - entity 8: Extension 3 (2 pads, 2 links, 0 routes) type V4L2 subdev subtype Unknown flags 0 pad0: SINK <- "Processing 2":1 [ENABLED,IMMUTABLE] pad1: SOURCE -> "GRANDSTREAM GUV3100: GRANDSTREA":0 [ENABLED,IMMUTABLE] - entity 11: Processing 2 (2 pads, 3 links, 0 routes) type V4L2 subdev subtype Unknown flags 0 pad0: SINK <- "Camera 1":0 [ENABLED,IMMUTABLE] pad1: SOURCE -> "Extension 3":0 [ENABLED,IMMUTABLE] -> "Extension 4":0 [ENABLED,IMMUTABLE] - entity 14: Extension 4 (2 pads, 1 link, 0 routes) type V4L2 subdev subtype Unknown flags 0 pad0: SINK <- "Processing 2":1 [ENABLED,IMMUTABLE] pad1: SOURCE - entity 17: Camera 1 (1 pad, 1 link, 0 routes) type V4L2 subdev subtype Sensor flags 0 pad0: SOURCE -> "Processing 2":0 [ENABLED,IMMUTABLE] --- drivers/media/usb/uvc/uvc_driver.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc= _driver.c index fb6afb8e84f00961f86fd8f840fba48d706d7a9a..4a8712d2d663ab0c31a1586ed7d= a6fd42f3ad3cc 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -168,12 +168,24 @@ static struct uvc_entity *uvc_entity_by_reference(str= uct uvc_device *dev, static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int = id) { struct uvc_streaming *stream; + unsigned int count =3D 0; =20 list_for_each_entry(stream, &dev->streams, list) { + count +=3D 1; if (stream->header.bTerminalLink =3D=3D id) return stream; } =20 + /* + * If the streaming entity is referenced by an invalid ID, notify the + * user and use heuristics to guess the correct entity. + */ + if (count =3D=3D 1 && id =3D=3D UVC_INVALID_ENTITY_ID) { + dev_warn(&dev->intf->dev, + "UVC non compliance: Invalid USB header. The streaming entity has an i= nvalid ID, guessing the correct one."); + return stream; + } + return NULL; } =20 --- base-commit: ea299a2164262ff787c9d33f46049acccd120672 change-id: 20251021-uvc-grandstream-05ecf0288f62 Best regards, --=20 Ricardo Ribalda