From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24E75C56201 for ; Wed, 4 Nov 2020 18:08:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D08DB206CB for ; Wed, 4 Nov 2020 18:08:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="CsTUsHFo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732254AbgKDSHy (ORCPT ); Wed, 4 Nov 2020 13:07:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732224AbgKDSHv (ORCPT ); Wed, 4 Nov 2020 13:07:51 -0500 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84EAAC040201 for ; Wed, 4 Nov 2020 10:07:50 -0800 (PST) Received: by mail-wr1-x441.google.com with SMTP id w14so23035494wrs.9 for ; Wed, 04 Nov 2020 10:07:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VfhCDV/n9idjZ/d3QJ4jFPIhhk5FgusiEPH5kI39Shw=; b=CsTUsHFoi2cq5mlqNEg6Q8YdypKf+v8flbBmVvC2TFeHrP3SPfIp00pkrgMBBt4FL0 a9Ulz06vG3ReIa2RC9wMhRau8jI1CF6/TBPVfn51WDviXxUh9+5mAUZoPRC2/2ENB082 bXrjXU1J7l4yKtg6v2T6u8LZcWbh5J6f3b998= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VfhCDV/n9idjZ/d3QJ4jFPIhhk5FgusiEPH5kI39Shw=; b=YEyAsIPj1kEjUThFzCecmMvPHbk3+DnBhH+sf6yBWXt/wKprlSPisRC88UEBU0T/fr /C5otJxesfaydA2lyhKRd3fE/cI4nlqYf+88VJWxHwJX5eGx6p2NSHIQBFQqEbsDstxg AXfRL8W4zkNxB97+7edJW5GhYvdACmERN9CVscXnId7HQMGcsbGBTX6OXWiZwsxd+DXS Mav3R3rtu/JKq2NRWZXbWiW2TuFFEq+J+uA4vnlFY9+3lLr86eOZnMPXh39aRUbBZc5q 0nUr7pOBbGnuppsEKUfAThEiIrPBS+qDpDhaTKfun04KPm/eJr2YLPGefmt9WzYOKAtK MBiA== X-Gm-Message-State: AOAM533Mf95iUtR3vTwes6ou972jNTP7CMBMgZmA/6bh+MzDdJfnZL4J p2b1rfXkRMjyoo2EKkIOFdv4zw== X-Google-Smtp-Source: ABdhPJzzX85rrIcPc4D40s3Cht5BnMBvX0o1FGEgI1vk1Pl239321KjQC0eOL7x62pZeYBZOv4XeLg== X-Received: by 2002:a5d:6cc9:: with SMTP id c9mr36246646wrc.276.1604513269347; Wed, 04 Nov 2020 10:07:49 -0800 (PST) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id y10sm3801841wru.94.2020.11.04.10.07.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 10:07:49 -0800 (PST) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Subject: [PATCH v2 4/7] media: uvcvideo: Allow entities with no pads Date: Wed, 4 Nov 2020 19:07:31 +0100 Message-Id: <20201104180734.286789-5-ribalda@chromium.org> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog In-Reply-To: <20201104180734.286789-1-ribalda@chromium.org> References: <20201104180734.286789-1-ribalda@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Avoid an underflow while calculating the number of inputs for entities with zero pads. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_driver.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 7a1b2decccc8..27acc221f0d6 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1033,7 +1033,11 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id, unsigned int i; extra_size = roundup(extra_size, sizeof(*entity->pads)); - num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1; + if (num_pads) + num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : + num_pads - 1; + else + num_inputs = 0; size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads + num_inputs; entity = kzalloc(size, GFP_KERNEL); @@ -1061,7 +1065,7 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id, for (i = 0; i < num_inputs; ++i) entity->pads[i].flags = MEDIA_PAD_FL_SINK; - if (!UVC_ENTITY_IS_OTERM(entity)) + if (!UVC_ENTITY_IS_OTERM(entity) && num_pads) entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE; entity->bNrInPins = num_inputs; -- 2.29.1.341.ge80a0c044ae-goog