Skip to content

Commit 786c85d

Browse files
Thadeu Lima de Souza Cascardogregkh
authored andcommitted
Revert "media: uvcvideo: Require entities to have a non-zero unique ID"
commit 8004d63 upstream. This reverts commit 3dd075f. Tomasz has reported that his device, Generalplus Technology Inc. 808 Camera, with ID 1b3f:2002, stopped being detected: $ ls -l /dev/video* zsh: no matches found: /dev/video* [ 7.230599] usb 3-2: Found multiple Units with ID 5 This particular device is non-compliant, having both the Output Terminal and Processing Unit with ID 5. uvc_scan_fallback, though, is able to build a chain. However, when media elements are added and uvc_mc_create_links call uvc_entity_by_id, it will get the incorrect entity, media_create_pad_link will WARN, and it will fail to register the entities. In order to reinstate support for such devices in a timely fashion, reverting the fix for these warnings is appropriate. A proper fix that considers the existence of such non-compliant devices will be submitted in a later development cycle. Reported-by: Tomasz Sikora <sikora.tomus@gmail.com> Fixes: 3dd075f ("media: uvcvideo: Require entities to have a non-zero unique ID") Cc: stable@vger.kernel.org Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Ricardo Ribalda <ribalda@chromium.org> Link: https://lore.kernel.org/r/20250114200045.1401644-1-cascardo@igalia.com Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9d237cb commit 786c85d

File tree

1 file changed

+27
-43
lines changed

1 file changed

+27
-43
lines changed

drivers/media/usb/uvc/uvc_driver.c

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -775,27 +775,14 @@ static const u8 uvc_media_transport_input_guid[16] =
775775
UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT;
776776
static const u8 uvc_processing_guid[16] = UVC_GUID_UVC_PROCESSING;
777777

778-
static struct uvc_entity *uvc_alloc_new_entity(struct uvc_device *dev, u16 type,
779-
u16 id, unsigned int num_pads,
780-
unsigned int extra_size)
778+
static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id,
779+
unsigned int num_pads, unsigned int extra_size)
781780
{
782781
struct uvc_entity *entity;
783782
unsigned int num_inputs;
784783
unsigned int size;
785784
unsigned int i;
786785

787-
/* Per UVC 1.1+ spec 3.7.2, the ID should be non-zero. */
788-
if (id == 0) {
789-
dev_err(&dev->udev->dev, "Found Unit with invalid ID 0.\n");
790-
return ERR_PTR(-EINVAL);
791-
}
792-
793-
/* Per UVC 1.1+ spec 3.7.2, the ID is unique. */
794-
if (uvc_entity_by_id(dev, id)) {
795-
dev_err(&dev->udev->dev, "Found multiple Units with ID %u\n", id);
796-
return ERR_PTR(-EINVAL);
797-
}
798-
799786
extra_size = roundup(extra_size, sizeof(*entity->pads));
800787
if (num_pads)
801788
num_inputs = type & UVC_TERM_OUTPUT ? num_pads : num_pads - 1;
@@ -805,7 +792,7 @@ static struct uvc_entity *uvc_alloc_new_entity(struct uvc_device *dev, u16 type,
805792
+ num_inputs;
806793
entity = kzalloc(size, GFP_KERNEL);
807794
if (entity == NULL)
808-
return ERR_PTR(-ENOMEM);
795+
return NULL;
809796

810797
entity->id = id;
811798
entity->type = type;
@@ -917,10 +904,10 @@ static int uvc_parse_vendor_control(struct uvc_device *dev,
917904
break;
918905
}
919906

920-
unit = uvc_alloc_new_entity(dev, UVC_VC_EXTENSION_UNIT,
921-
buffer[3], p + 1, 2 * n);
922-
if (IS_ERR(unit))
923-
return PTR_ERR(unit);
907+
unit = uvc_alloc_entity(UVC_VC_EXTENSION_UNIT, buffer[3],
908+
p + 1, 2*n);
909+
if (unit == NULL)
910+
return -ENOMEM;
924911

925912
memcpy(unit->guid, &buffer[4], 16);
926913
unit->extension.bNumControls = buffer[20];
@@ -1029,10 +1016,10 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
10291016
return -EINVAL;
10301017
}
10311018

1032-
term = uvc_alloc_new_entity(dev, type | UVC_TERM_INPUT,
1033-
buffer[3], 1, n + p);
1034-
if (IS_ERR(term))
1035-
return PTR_ERR(term);
1019+
term = uvc_alloc_entity(type | UVC_TERM_INPUT, buffer[3],
1020+
1, n + p);
1021+
if (term == NULL)
1022+
return -ENOMEM;
10361023

10371024
if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
10381025
term->camera.bControlSize = n;
@@ -1088,10 +1075,10 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
10881075
return 0;
10891076
}
10901077

1091-
term = uvc_alloc_new_entity(dev, type | UVC_TERM_OUTPUT,
1092-
buffer[3], 1, 0);
1093-
if (IS_ERR(term))
1094-
return PTR_ERR(term);
1078+
term = uvc_alloc_entity(type | UVC_TERM_OUTPUT, buffer[3],
1079+
1, 0);
1080+
if (term == NULL)
1081+
return -ENOMEM;
10951082

10961083
memcpy(term->baSourceID, &buffer[7], 1);
10971084

@@ -1110,10 +1097,9 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
11101097
return -EINVAL;
11111098
}
11121099

1113-
unit = uvc_alloc_new_entity(dev, buffer[2], buffer[3],
1114-
p + 1, 0);
1115-
if (IS_ERR(unit))
1116-
return PTR_ERR(unit);
1100+
unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, 0);
1101+
if (unit == NULL)
1102+
return -ENOMEM;
11171103

11181104
memcpy(unit->baSourceID, &buffer[5], p);
11191105

@@ -1133,9 +1119,9 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
11331119
return -EINVAL;
11341120
}
11351121

1136-
unit = uvc_alloc_new_entity(dev, buffer[2], buffer[3], 2, n);
1137-
if (IS_ERR(unit))
1138-
return PTR_ERR(unit);
1122+
unit = uvc_alloc_entity(buffer[2], buffer[3], 2, n);
1123+
if (unit == NULL)
1124+
return -ENOMEM;
11391125

11401126
memcpy(unit->baSourceID, &buffer[4], 1);
11411127
unit->processing.wMaxMultiplier =
@@ -1162,10 +1148,9 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
11621148
return -EINVAL;
11631149
}
11641150

1165-
unit = uvc_alloc_new_entity(dev, buffer[2], buffer[3],
1166-
p + 1, n);
1167-
if (IS_ERR(unit))
1168-
return PTR_ERR(unit);
1151+
unit = uvc_alloc_entity(buffer[2], buffer[3], p + 1, n);
1152+
if (unit == NULL)
1153+
return -ENOMEM;
11691154

11701155
memcpy(unit->guid, &buffer[4], 16);
11711156
unit->extension.bNumControls = buffer[20];
@@ -1305,10 +1290,9 @@ static int uvc_gpio_parse(struct uvc_device *dev)
13051290
return dev_err_probe(&dev->udev->dev, irq,
13061291
"No IRQ for privacy GPIO\n");
13071292

1308-
unit = uvc_alloc_new_entity(dev, UVC_EXT_GPIO_UNIT,
1309-
UVC_EXT_GPIO_UNIT_ID, 0, 1);
1310-
if (IS_ERR(unit))
1311-
return PTR_ERR(unit);
1293+
unit = uvc_alloc_entity(UVC_EXT_GPIO_UNIT, UVC_EXT_GPIO_UNIT_ID, 0, 1);
1294+
if (!unit)
1295+
return -ENOMEM;
13121296

13131297
unit->gpio.gpio_privacy = gpio_privacy;
13141298
unit->gpio.irq = irq;

0 commit comments

Comments
 (0)