From nobody Mon Feb 9 03:58:49 2026 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (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 3760132D0FD for ; Tue, 21 Oct 2025 10:36:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761042983; cv=none; b=iPVUpGg3HN1E0VUvDwGeRgjMJ13LT+meOmVLxexR74HlJ8kH7Jq6Na97Zgh4+lswdAc8W43NWWuNwrfGgFAsnwfigUAJd7+ex/OQr7VnbF8FsGOpMhxRsM3qe9G5PewU3am719O3F466HGDLnagk14lZ/uYs7/0kQjyYuLf5r6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761042983; c=relaxed/simple; bh=mu/cr0ccCQhZG4HUcvVpPbQl30IkLO8o/gI0SvZrpZ4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=Qr/R/TeSWd+v+lDXSXFcurrzPtE3AaqsetMCGvWWwuR1AcK6Z5Dh/u0iwEmxZF8woNFYOGFLGzf8JiJ/E2bKHx72ubnJsGRVIE40/0i7StEPE1C/X+xFC/HHCMqa6Q4EYZJvKTDtDVZZd1aGzsmg7OCwmkLeKO0Xjblwhg3qpeY= 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=ewrOJUn6; arc=none smtp.client-ip=209.85.167.53 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="ewrOJUn6" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-591c98ebe90so6025102e87.3 for ; Tue, 21 Oct 2025 03:36:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1761042979; x=1761647779; 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=/TafpqYvz7n63SFC71twwiYhEsv21pktmNXXlISP5Ho=; b=ewrOJUn6MwR5+0lFAAMHA8o9z9Liz6JolyrjOxVFtAf9V8SKaldjSf16KsNjDHYM0Z rIkxT9nW5lFYjylWHgyObBOQUGonvviQa+Ft2Hmkjd7/nrY+p3lpZF9SI0x4BYySS+FY pTY+wnD5muAqx+MTYMKqtKMg+cWenyiMw61j0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761042979; x=1761647779; 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=/TafpqYvz7n63SFC71twwiYhEsv21pktmNXXlISP5Ho=; b=JARgzxrES/eWQfaq8C67aJdAmcP5gYlm3pQFncFig3QtuuP0Sn/sgBs7PR7dtdLqUr hY/FtZwFf8ql/r/dtYoA9YUWsbGccDp60VMrjy1/Zkh5lRFXcaBoSj2iLK9pw7FYOjnG Zw8tATj0c7eLXUfpECfynPfnSRZfUTuVXo4fx0xN2uVSJbKbpvRz7ZLbW1LUxXLxB9EF YwwayNjZw8loXzp/uyQj79lmwQ4yr3w7PJlSVeGQEZal6fShxxKt03YmQibKT7T5Pm9p 8nYW2n4Ahzrrf2xKhL1EsWbxZKkORvhG/rJrIS9rAwYdI3qiTa6vKMRyfhQbslq/rDv3 Wyow== X-Forwarded-Encrypted: i=1; AJvYcCVDMdZlkIhLjzfi7tuvlAXGb0dECqWF9lbuIawS+FSia0MLy9p4iKNVrZSogcz4/+9VCBrrEY5p2EwXUgk=@vger.kernel.org X-Gm-Message-State: AOJu0YwO5bm2dKUlMz7cyG3S1c3MtnvqVIJ6E2iBNSZ70jeF+Vub29M+ Dn2XSzA+TNl5UrMx605sXny4w5BjhoVSdWQwFEPGtVwxhke/R+XOFvuk3IEgkIq96ra+egWkkpu Z5TI= X-Gm-Gg: ASbGnctKN/PmpIf64hILcViKrxPrzRQpA4f8A8SRDTeedzoezHsPjl4WeIIYsRvdnSE 7JXigmd7Ebno1yPKiCgZr1K+p40u+1x0d9X7huSI3ILJOS0bL7eTP2oLoV0Ft4Wq/6XDXK/+erv TGwDnOxY/fry9BBacshyNADSQ0MUlfoPCi1ohLFifVeCpow91/0Gc7xQHTfuQfehLgfGGi2XSIq FPOQ9acUC8GRaWBOJ9X7e3vpKMRAZnCetTMfo+6WBE4wD76T2rL/FefjK3LJQfMNlFUGaU7SHvH 80hy7bHBw++EyG3I+MUlSodbf+q2imHAIIQgbyjZ7q/EwFhaJlh8BAJo163DS+CaY2xXFPzbe1C t6sbpLQ8tPFUGxraK/gMz4QT2FEBYokSYW/kRfNAY0n/8xYjiscmlTbqpa1GE8MzufhUc3A0Tfh uaZ3FdnC/ud84KUD0pQ9vUotoLqrjH6a2sn+6vnM8sk/hybNhsvGEarGorCSTlDL/Iyw== X-Google-Smtp-Source: AGHT+IFY8+5yWsF2/+yXKzUgKDznuSxR53YAociIJKjxctfTBbridZE9yYWajB+gH0DDhnuJ0uI+6g== X-Received: by 2002:a05:651c:b2c:b0:36f:77e6:d25a with SMTP id 38308e7fff4ca-37797a8fa40mr51550211fa.43.1761042978949; Tue, 21 Oct 2025 03:36:18 -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-377a950635csm27946251fa.30.2025.10.21.03.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Oct 2025 03:36:18 -0700 (PDT) From: Ricardo Ribalda Date: Tue, 21 Oct 2025 10:36:17 +0000 Subject: [PATCH v2] 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-v2-1-6a74a44f4419@chromium.org> X-B4-Tracking: v=1; b=H4sIACBi92gC/3WNQQ6CMBBFr0JmbU1nDNq48h6ERS0DzAJqptBoC He3snf5XvLf3yCxCie4VxsoZ0kS5wJ0qiCMfh7YSFcYyFKNltCsOZhB/dylRdlPxtYcekvO9Ve Csnop9/I+ik1beJS0RP0cBxl/9n8ro0HjLPKls+5JN3yEUeMk63SOOkC77/sXXAG6MrEAAAA= 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 Reviewed-by: Hans de Goede --- 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] --- Changes in v2: - Fix : invalid reference to the index variable of the iterator. - Link to v1: https://lore.kernel.org/r/20251021-uvc-grandstream-v1-1-801e3= d08b271@chromium.org --- 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 fb6afb8e84f00961f86fd8f840fba48d706d7a9a..ee4f54d6834962414979a046afc= 59c5036455124 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -167,13 +167,26 @@ static struct uvc_entity *uvc_entity_by_reference(str= uct uvc_device *dev, =20 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 =3D 0; =20 list_for_each_entry(stream, &dev->streams, list) { + count +=3D 1; + last_stream =3D stream; 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 last_stream; + } + return NULL; } =20 --- base-commit: ea299a2164262ff787c9d33f46049acccd120672 change-id: 20251021-uvc-grandstream-05ecf0288f62 Best regards, --=20 Ricardo Ribalda