Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1979917pxb; Fri, 5 Mar 2021 04:40:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJx87eQy8yAgKINywazucYDm4HbISRBaXTUQ6z0iXFqAqmJVrW0KrZfbdP9ebTJnUqbbZ/Kj X-Received: by 2002:a17:906:be9:: with SMTP id z9mr1999501ejg.35.1614948036592; Fri, 05 Mar 2021 04:40:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614948036; cv=none; d=google.com; s=arc-20160816; b=IA5XZaZjwz0FkDyqp5f/p9e8UjKxc/VgHYyF65G3TLJlOvHanuoVYQpl3FfZton7CC RC5fiEz8vSo1tl4UMlrjqOpCXd85pdOLJsQ1mnhi1FjzttgqTNha4zDF7UcM3uzZcLrG aYUnvI1iT91n1PWrYUpHyNRk9ojgOpT2mWCuTId7DE8MVxK512TzoYu6xQcT2+hOMUDC zU6nKb7nVoTLjBdRpyIalmyi2AatuMRIBnvV0m1MIFk24GzKJ8YHIGwCjwhdRtP0B4KQ +JdnUxma2BvVB/FDKv0gxWtO2/l1zHZa1K8+1zJQtecgzZw7zhJLOh7WNNu48LU06Cat OyaA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tGbpAe2dYt6QJJNawIujNinzVNjMfdCuuze4/EwgxEo=; b=rDA8HezmB6YtTTSguhchoAxgyOpNhd4rCFugQhJjPVeYr08V/LfPw+hVn6A64RzU/0 Jj38vc+2vdzf9fzxHmm83kqtL3uCYZEsW9PWQKjkXgnkXvyBKOvwsOPOcikv8KH6yZkO MDL6jEboOzw4wMrDIIoOHABXtxBnBE59QY7Q586BmwgR3cKTD+TXrjEUH4B5IvQfY1j4 aewJDb0Iu8ddu1WpilDEQj+jpqareFPyOFcIIrcarXJwt9/9qUI6zJmllbhfxst6rPim orMtbzsMp/oMpFY4vkR5L7Kb+TdxkSt1xlgdF8B5IlkBdTri793O5Rxg0Pv0qgnkQkcg vipA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HS9rSJTm; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o9si1176279eja.264.2021.03.05.04.40.13; Fri, 05 Mar 2021 04:40:36 -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=@linuxfoundation.org header.s=korg header.b=HS9rSJTm; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231259AbhCEMjO (ORCPT + 99 others); Fri, 5 Mar 2021 07:39:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:52156 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233072AbhCEMig (ORCPT ); Fri, 5 Mar 2021 07:38:36 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id CA17564FF0; Fri, 5 Mar 2021 12:38:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614947916; bh=HyXNKzlEerydnVeJ0HfUOD7a5QP60KoqNzEpC574pPo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HS9rSJTmnX7cKKJ/UkAQWSuTkPaBPFtA3a4Ls8rhCRwgMTO906PHbP7pE9dGT8+0c X57ifMEoR10OMDDEEjBDdhYJelbQPC/33vlyywGxElEzvPHa+FpxEVRVsJX6KyFKHN WXmTcSUCRj7z8gbGygUOLjRjsDTW45ivswX7ylFw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ricardo Ribalda , Laurent Pinchart , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.19 34/52] media: uvcvideo: Allow entities with no pads Date: Fri, 5 Mar 2021 13:22:05 +0100 Message-Id: <20210305120855.341940501@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210305120853.659441428@linuxfoundation.org> References: <20210305120853.659441428@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ricardo Ribalda [ Upstream commit 7532dad6634031d083df7af606fac655b8d08b5c ] Avoid an underflow while calculating the number of inputs for entities with zero pads. Signed-off-by: Ricardo Ribalda Signed-off-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- 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 38c73cdbef70..998ce712978a 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -940,7 +940,10 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u8 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); @@ -956,7 +959,7 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u8 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.30.1