Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp5787904pxu; Wed, 23 Dec 2020 05:38:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJw1cJXgLedE8t5BBQA+YDQJP8JhezPMjpvsPAWmRKdlTUseM/DLT5yuyL+dBx7otvmgPhlP X-Received: by 2002:a17:906:8058:: with SMTP id x24mr23194646ejw.262.1608730702874; Wed, 23 Dec 2020 05:38:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608730702; cv=none; d=google.com; s=arc-20160816; b=PkXzTz078FiNq4G/F+Y1vlB8l9Gd+u8EmetjhWJ+U5tRYhVhvyy2oMbTUuLRtQ/Ew2 yjYOt1pAzw5JeTS/C6/e4GWiJ+4pCJBrDIMpsD8xljFTLlKPIKnHQSncrns4KHElhaUU 92upiJPoHVPZOoxlGPFvE1piRTaMjc3o5hSFEEqhPZ/nkrZMdZFZX0k8YRD/x5R7uM2f vta1yN7nMqrk934HD1qq+iWFZf/MPmiGyDaH6mdmFgMZU7comii4BlkrmTOCwB64yz9u yZtdnQiXpqB2ZDprTO+THYezHQXo/E1/hwKvjH+2DuhBlT8vM1xmFUaiuFzCE/XQE+pA gU4g== 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=UvpyONwNGFK1cqijvX/a2/5UzH+LaYn5TNyYwWHAtHU=; b=JDvarSnTZSyORztPyUUsiLER6bfKrRQO4nN/Ckhx3Fi0nC5qfwQ1c49a6slDvXlaAF I4oUPNnzAf9NuMSRo7clnF4wHm0PbJ0gM9xlC970GzvosqXFRncljjT53YPOoLfKe6MY lEvZaPUbUIAqACXbf4dxVGkBpbV1m4TyoYwfISqqWaHhiV7bUqaDIDIEEOUx3fYVfSHg FHfyfJ/mqbK/5x9qMMs+jdPyAGGjn8+/ZjS270iaIPINPw+9JBE6Wz8wV8PFDiA55BWS OlH8nJz6GfM7UXHrhr1rBIH1qyGJPSYV3/F71dg/kqMqlSCq+pAxKRb8q060AuBl7UdC BCvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=STIbJo6y; 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 h14si12517418eje.288.2020.12.23.05.38.00; Wed, 23 Dec 2020 05:38:22 -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=STIbJo6y; 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 S1728716AbgLWNgy (ORCPT + 99 others); Wed, 23 Dec 2020 08:36:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728576AbgLWNgw (ORCPT ); Wed, 23 Dec 2020 08:36:52 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A058EC061282 for ; Wed, 23 Dec 2020 05:35:34 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id n16so1403069wmc.0 for ; Wed, 23 Dec 2020 05:35:34 -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=UvpyONwNGFK1cqijvX/a2/5UzH+LaYn5TNyYwWHAtHU=; b=STIbJo6yghNXeVFMNqXERsWmAolzLrgTDD1kYmexWRLS9wSef5T9p79CoJELIVYm7W 0gUiMl5Uzu87MPElOS8AOal7nnlyUjHu2M3kjcTZ7aR/INuoZOc4+XrEz5hp7iZzzbsa GfWvgvfn9Xgj7WnA+uPvNW1e8wrj4lTRtt9RQ= 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=UvpyONwNGFK1cqijvX/a2/5UzH+LaYn5TNyYwWHAtHU=; b=W/gVZ2T7tMcDWQTFJEYunsVvE6e+oy/H1S73XYI64BCTbZLiJ0TJJNhxAEbdunuUzy vWrTL2es9rLKU5wFsnp9izMOD4zM6l3umbqB8MOW39fvIgv+0ApOBxCu9sJbgF6dtItG qAVeFQzZsvnByLBOhno8ypSJvF6q3kfwGapM6wI6TEu6a1tXpqL5QnNfq4syq+y6ZqtS yDnMjYmFh+p2cCVA9wtOIHRjpGfirbfVfDYmfD0fgFYAPxdFY3lqmzyE84grf6PllO25 yUhvZhS0Vc8yOr+x2n4s10doNpL0AMTaSJ4fIw4t29gEW3uERwtDemstriTfw81on4VR /u/A== X-Gm-Message-State: AOAM5313E9M+N4mtDxqh33g7nnCSMwZDBjPcQD0U7tcDvo5hxrN8w28I hptsH83Q+rmBNQX+EnUyE3CUaw== X-Received: by 2002:a1c:3d86:: with SMTP id k128mr26228187wma.66.1608730533456; Wed, 23 Dec 2020 05:35:33 -0800 (PST) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id q143sm31572247wme.28.2020.12.23.05.35.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Dec 2020 05:35:32 -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 v7 03/12] media: uvcvideo: Allow entities with no pads Date: Wed, 23 Dec 2020 14:35:19 +0100 Message-Id: <20201223133528.55014-4-ribalda@chromium.org> X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog In-Reply-To: <20201223133528.55014-1-ribalda@chromium.org> References: <20201223133528.55014-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. Reviewed-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_driver.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 82cdd1bb28dc..c0c5f75ade40 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1033,7 +1033,10 @@ 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); @@ -1065,7 +1068,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.2.729.g45daf8777d-goog