Skip to content

Commit cc52ed1

Browse files
ribaldagregkh
authored andcommitted
media: uvcvideo: Allow entities with no pads
[ Upstream commit 7532dad ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 4b73f01 commit cc52ed1

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
@@ -1028,7 +1028,10 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id,
10281028
unsigned int i;
10291029

10301030
extra_size = roundup(extra_size, sizeof(*entity->pads));
1031-
num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1;
1031+
if (num_pads)
1032+
num_inputs = type & UVC_TERM_OUTPUT ? num_pads : num_pads - 1;
1033+
else
1034+
num_inputs = 0;
10321035
size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads
10331036
+ num_inputs;
10341037
entity = kzalloc(size, GFP_KERNEL);
@@ -1044,7 +1047,7 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id,
10441047

10451048
for (i = 0; i < num_inputs; ++i)
10461049
entity->pads[i].flags = MEDIA_PAD_FL_SINK;
1047-
if (!UVC_ENTITY_IS_OTERM(entity))
1050+
if (!UVC_ENTITY_IS_OTERM(entity) && num_pads)
10481051
entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE;
10491052

10501053
entity->bNrInPins = num_inputs;

0 commit comments

Comments
 (0)