Skip to content

Commit 7532dad

Browse files
ribaldamchehab
authored andcommitted
media: uvcvideo: Allow entities with no pads
Avoid an underflow while calculating the number of inputs for entities with zero pads. Signed-off-by: Ricardo Ribalda <ribalda@chromium.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent cae79e5 commit 7532dad

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎drivers/media/usb/uvc/uvc_driver.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,10 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id,
10331033
unsigned int i;
10341034

10351035
extra_size = roundup(extra_size, sizeof(*entity->pads));
1036-
num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1;
1036+
if (num_pads)
1037+
num_inputs = type & UVC_TERM_OUTPUT ? num_pads : num_pads - 1;
1038+
else
1039+
num_inputs = 0;
10371040
size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads
10381041
+ num_inputs;
10391042
entity = kzalloc(size, GFP_KERNEL);
@@ -1065,7 +1068,7 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id,
10651068

10661069
for (i = 0; i < num_inputs; ++i)
10671070
entity->pads[i].flags = MEDIA_PAD_FL_SINK;
1068-
if (!UVC_ENTITY_IS_OTERM(entity))
1071+
if (!UVC_ENTITY_IS_OTERM(entity) && num_pads)
10691072
entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE;
10701073

10711074
entity->bNrInPins = num_inputs;

0 commit comments

Comments
 (0)