Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1519088pxb; Wed, 4 Nov 2020 11:05:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJxlR/mlGhr9SWyPh6ewxYB0Bnf8UHl8jtLQyWWLl1bzjR9D+kcp7adfI2C+3IOMdbi0iz+H X-Received: by 2002:a17:906:1253:: with SMTP id u19mr20326723eja.288.1604516758951; Wed, 04 Nov 2020 11:05:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604516758; cv=none; d=google.com; s=arc-20160816; b=K/OLbjM+yyoBlnO0dlZJiK//vl1MqTzTjiui7YsZq5r+fb4w6YuYNIJySTBVCsnkup ItqpZXKuvvK1CL6WX91bzb56IgWkzYNw49C0I+4X09EdD/24IdU1L8HfMCDUdMI1cGY0 TLsjAAU5urylDQ0W6FXQxCoW0Ske4j4Ot8f1mR9gYQoio4LdS5b1+aVHtIFuLKteuGQx o2OilA89LOdtYIZ5dpBSgR3kt6yoKgc0hM62N+PB1k/ZQg3ZDE7oGfYXqvzCCI/CZ+0t Y3yElwAbdlnFBQolOBIyX8ijartf3Nw3UP4veRFow0CT+UIVyk8Awu2Df1xEbZTnKjDz wYvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VfhCDV/n9idjZ/d3QJ4jFPIhhk5FgusiEPH5kI39Shw=; b=uiRn9rEVJmyE+vx0mdThQNPOflE7ftQxOBnGAILLlkXQa/J4Fju8G7V5dd1drKClWX 4HMsY5ZYUagHfToWwRdU0Y2j9yorJ2Sjbbcr1Cd+zoRU4cyzNkPdCOb/LxcN2NJiwmTu GVXkQA+Eq0YNC96tl41j/X5uAgRjdG9ydJcAoDr0K3Cyypkln2UnprV6Sj37HItLFT2i SZA1blY2mV03JA1Sdc+Qr+MrNhF+LYSOY4gvWESTvCccdUGR/Mu5GIUz+dfueg1EoNdt cD/5evgFaNvonHBEoL6zzANzNadoFLw6G8leTWcGw3ow97UdKUk7/jkHGOIK23BJCrf1 icrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CsTUsHFo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id sd17si2139275ejb.395.2020.11.04.11.05.35; Wed, 04 Nov 2020 11:05:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CsTUsHFo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732225AbgKDSHx (ORCPT + 99 others); Wed, 4 Nov 2020 13:07:53 -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-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