Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp420406pxb; Wed, 24 Feb 2021 05:56:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJy8hlCcKX2UH1WSNI9RkmOG8JeKrr7wfoWxZ7CwcUcs6MJSkQJMdl4yKEqPPS1Jkw8XHp0v X-Received: by 2002:a05:6402:304f:: with SMTP id bu15mr34382605edb.259.1614175016062; Wed, 24 Feb 2021 05:56:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614175016; cv=none; d=google.com; s=arc-20160816; b=xJYUevPuuzYp12g57euZANiuNlsgqRKWIi1ywIjoJDgPWZs1dakAi/JbRSo02XcAiw KN5e82J8IqhQX/VODU9IAt4umQvROZL0qagW6JD67o7PffDJSJIYL9o9cKEWJ9Omuqcs awUSYRuraTJnzh5Ku+204v9ewoB5s5AEmJYxrx9+o9HPCQlrAYkMc1Jd3VW9wXFL7nug 5cu/pVk9qlPJN7sk0d3GaQKrCNTUVPx3NGTybsBxKKR5tKNUXnMMKw2BHgLs8k238gFH UEwNl1e0K9ZhVwSBRUv1Np+pQNcC4PBkTOfdbR4l+NAWbnWRBerEzDse6Bwm6RVFV7Dw 6qYg== 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=usd3RBnjB42U5hY8ddPQ5/bWXFCelur/4vBEfOYBKmM=; b=BskOU37bWktM5+QuUnKdX43meIjjNuwbUtoiKQbbVTI+yilLpRr0WJX5gQMMbzSqQE a607M5H0lZU8KDrpZX/faE0W1AzqEKiKCrG6KYA6tMwP6ruE3dkvFYoC8txijpyQmP31 hk/1NEJRlpsKN4uCGWo2/fdVCtPDULUwqC6mZ0SA96P49F616J2b/v1jr9TFK+5V7/0f r3p83ksQjTYgeXz8UVkZszSatJo6uEnfh7gIMtxVhnA52qVBAFccFuaKD36q9AqviZcK UF06L8skiF7oBcLzLNfQtK0h3aAfbUCAbug0RBQrsy7cSKE547KiQpe0b9OFgJxWwPwL IgXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nGlRYevk; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i28si1128487edy.261.2021.02.24.05.56.30; Wed, 24 Feb 2021 05:56:56 -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=@kernel.org header.s=k20201202 header.b=nGlRYevk; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235623AbhBXNvy (ORCPT + 99 others); Wed, 24 Feb 2021 08:51:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:58102 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235736AbhBXNGH (ORCPT ); Wed, 24 Feb 2021 08:06:07 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id B47B264F81; Wed, 24 Feb 2021 12:54:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614171250; bh=UcP5weq7WeVFcFD7tRgXmjgjPhb2Bw4oSntSVMieRsA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nGlRYevkPwI+vtR1cJD0N4E8dnJtHY2AYtNhP0itoy2K8QmfAuxF17OK/z+rxRkh7 Zh0Gd28SHaU2Pl0aycqmmqXRynJtD/8vQuQ2ZrO7hF2UdY5wndmQ0aXYCXE+VQg3Lq 8xJe8/ZsuWhCnLrT6tOVB1K4fxsG1aaTELljpHTjkDuuBQ0JL04Xy8WdSswmPGw0dV z+lpJoDgpZWkab60SKPnvNKS2k0DJRHpEUAxbz6pyxc8eVUAWyJsDWbuLc0UnSSl20 a0pz5C6Nb/NkPfiW+dOlRwstxoyDM9hMgoGQkIjyTBi5AHRgtkegFz2NY9h8LKxk40 XrPTO7M+E3q4g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ricardo Ribalda , Laurent Pinchart , Mauro Carvalho Chehab , Sasha Levin , linux-media@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 22/40] media: uvcvideo: Allow entities with no pads Date: Wed, 24 Feb 2021 07:53:22 -0500 Message-Id: <20210224125340.483162-22-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210224125340.483162-1-sashal@kernel.org> References: <20210224125340.483162-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 99883550375e9..40ca1d4e03483 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -967,7 +967,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); @@ -983,7 +986,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.27.0