Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp786429pxb; Thu, 19 Nov 2020 13:52:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJxFz7mhYiqCk0ZQX9KndoQmu/2mcempCrnzesnj1xEUOcVSBftatxHGVjNFmpn7VQk67kxQ X-Received: by 2002:a17:906:7cc6:: with SMTP id h6mr28921383ejp.161.1605822740111; Thu, 19 Nov 2020 13:52:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605822740; cv=none; d=google.com; s=arc-20160816; b=kDTrn51zY7GEAmNuAlf68PTMt5yRgd33LdSZ3II255kcxntNRD/hbilG0b6wZE/uK2 TeBO3uVXbrrUOKbA+2/fvhhI0q5+oPBgR/7nAC+8FB6jvgNlhAPhS5ekSUNSelxYyLWT 631UugJEz0Rdiix3Xdm1xIb2UkeP/JIKI0aTFHZ9Ep4kFm1l7N4O1ALiQtAwHakZ4KUx vhqNvhwi4411xBEyREINXSDR447kn8yDURpewnB5OLM8VNZZHwMtwPNk9xFkajtQoJB4 no5MUqWY2gZhE3XMoXSgJmtqMARF34ZyXSbSfkKwc9v5svJl9+BEasO0t59ZPUG2CTa1 XPaA== 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=zOlDw3xAtBO2wRxDpudGLYAgtj4GYNudNiFuGERnAjQ=; b=bcB8M9rQkrqbOJr3IOxt50UR+7Ky52Mk1gNIE39wIMc+jDxAhthxhcWVzZqsEyD57Y FgWHdO/f3nLWLhXGldT+gIJCwdqwZ2OCg+lx62Ey+AWzkMd3sbw2Tgf0JY2pP2ZitfdP O8nn76hjTcJyBwKGgHBC5ysZUGjbiVwgZbxtH78LEsc/BTuxsxGA98TMhrbtPZdDVgVb xcIMzbK5L18hANetz/Uww3rhKHchPX7W9qc6xvM7syaWTUx/wyUtl5Qt24A9tOn2kZtu 0Ex/fq/PbIfcTO7bP9+TyOR7N/tkOGGNORCTQiNFxzBda+EGFR2j4UzLyDG8F+7LewVo xqPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OcG+6ZXd; 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 u18si583253ejt.95.2020.11.19.13.51.55; Thu, 19 Nov 2020 13:52:20 -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=OcG+6ZXd; 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 S1726466AbgKSVub (ORCPT + 99 others); Thu, 19 Nov 2020 16:50:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726549AbgKSVua (ORCPT ); Thu, 19 Nov 2020 16:50:30 -0500 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5B57C0613D4 for ; Thu, 19 Nov 2020 13:50:29 -0800 (PST) Received: by mail-wm1-x342.google.com with SMTP id a3so8049396wmb.5 for ; Thu, 19 Nov 2020 13:50:29 -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=zOlDw3xAtBO2wRxDpudGLYAgtj4GYNudNiFuGERnAjQ=; b=OcG+6ZXdy+PQO9GK7Nw/wczVsoutxZ1M3eanuJ7kt69pL4SHrH/xal6OVYAbPJ3GEX bwP/pVEqa0IvEttvhnJGpczgh1hVXhex6bywvdrS/pn3E5PJWKdHei7jpq8uvLsfIhC3 YabrY2RVvcJdnGquxSn0V/Y09N17mS8cZOOHg= 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=zOlDw3xAtBO2wRxDpudGLYAgtj4GYNudNiFuGERnAjQ=; b=ZIVfCam8k4j6OYLEC0QZAmZe/98hd8YDK+iW7uHpQ7aLzwaZ5wkrnlUsC0WZVXYpjg i1qjhhx7ryEW0NkXPQ7CMFUlH55Dp9ppQ9JDM3ob4bKmRaRgiyZg5d1Yp7nACOEa9uBo Nr1dpf/2GIZMpwcPZzx73DIN2rkYcfXm+mPF2Tkyphw0jllVdWuu/91PEHMVlqdwC4iQ efYkmQcBRmBBmgGGApllfIxCUOrGlHa+cwoF+MaWlBX/JF9c9xkTLqI0LeFPNYnltxrz zHr3BdG7dfITMsHrQ0iPDs34H7N7TvrsPLSFWdbygPC1pQ/p06VKisZRKU2qIro9+IrD p9SQ== X-Gm-Message-State: AOAM531nH29clAvaSBTaYhcPTkoXrrRQKnv2lqZgou4SopDe7PnbFWl1 AbpXl9WP/8qbIW4jC7Dxnz4xtQ== X-Received: by 2002:a7b:ce84:: with SMTP id q4mr6438582wmj.26.1605822628600; Thu, 19 Nov 2020 13:50:28 -0800 (PST) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id t136sm1818859wmt.18.2020.11.19.13.50.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 13:50:28 -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 v3 3/8] media: uvcvideo: Allow entities with no pads Date: Thu, 19 Nov 2020 22:50:15 +0100 Message-Id: <20201119215020.508487-4-ribalda@chromium.org> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog In-Reply-To: <20201119215020.508487-1-ribalda@chromium.org> References: <20201119215020.508487-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 9f4451a2e0a6..534629ecd60d 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); @@ -1066,7 +1070,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.299.gdc1121823c-goog