Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp433865pxb; Wed, 24 Feb 2021 06:13:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjEfIFoBdNx/3MivQgroNAelviOEyxiglYK2CFaQ0HuPinkb6FTC4kLLeomUpV7lA32pnQ X-Received: by 2002:a05:6402:890:: with SMTP id e16mr15959435edy.335.1614175994890; Wed, 24 Feb 2021 06:13:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614175994; cv=none; d=google.com; s=arc-20160816; b=Mwcif6crWcXkeEfjPqT6v0VPGcJvpahlaStLg2pFi45WTOXHkWo4b5wPCPnN4o+uUV JnME7DDUlfho3GaGSF4rgdCTlPWRYf1YDua7fOo+tAXGvlLEMbdAS1FbMGNIUlCa8TRn OpmUp643uoDZTIW/5NO4juy0FoE1uThOuIsX7As+bTwwvGxweAX1ImvKRY0ipT3NSUDL +8tM4FIQmjTp1yMj+l4uQyE5rAXoq6nSTwHwSVQ7Nx2yhen44x36lfgPTgV7aPfnQcFW ke3mVmpk2UfpVu1gco/DYS5ISgKRulXEspNricvoPUXbw6bJNxVg7mrQmULObH9JkFSq o0Dg== 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=3aJ/N/0ITWPGagLRUCY3HCn4EeV2hsiiOGPtCYrywag=; b=BKqOOQAYuRkkOjsP52msMBtixd8gjfOg69Edu7E+95BmGANHXOpuRImRhq+aLzy9hB 2xS9BC4MUXwgKwcaJKsNiXZ5/pEAEZixTYik8ak6uSs+SgY0/mVWOolRMOxoF5RulXtq YNOez9xz9jOi1jfby++fgar5dU0I9Pwgvex1JLuppjN0bHaloz4YRvXxLsFf8PcEkhzF uGOB+4kPnp8ZLu7xhU1c2153QeNkijzF5CR5fuFn+1SxaV5FKpheZAGOmlSm/EcCwIsl dvqDqbq5DnBycqiX0yIv9ZdIpRb7Qqy6YeHVdl0FAYcbbjIWJfHKuglJGOn6PR8TpiGT mRXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="hzUSrl8/"; 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 gz13si1331661ejc.411.2021.02.24.06.12.29; Wed, 24 Feb 2021 06:13:14 -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="hzUSrl8/"; 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 S234521AbhBXOKD (ORCPT + 99 others); Wed, 24 Feb 2021 09:10:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:58434 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233691AbhBXNIh (ORCPT ); Wed, 24 Feb 2021 08:08:37 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9FEC164F9F; Wed, 24 Feb 2021 12:54:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614171296; bh=Pj4aQF+Oyoerw+DUAbyzJWz+rBVxid4lt78TdfufLsk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hzUSrl8/nmWLYbqWeKct5R2I2tDW79McYYlry4T2+RKMP2fUh3Ns5PrzvuX9LdPtF Lhg8A4um7Bl7zWfrW3MbBAFpe/eqTLZ9XHdH5iFkPLhlOGEBL7a2Bpim0HWRidWzWQ cgM7eRhXkNePrX610fNZ7QGdVw7JzHeNDYkFhJJwaOvAz2/avr3WrCj/mVECmkl+be fzpZbMd2zuLkU2lUrf6tg3a9q3N5fruRsK12SOvOLnhvKK1aBxLeU40blHInVRP/eJ Ws+iU/s0kzkPqayGlh9UpVqPDDxqdd+ho1OnuTAZFDqkzY+jemIRjSzp39Acb8H56T J5vQAtp/FC02Q== 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 4.19 16/26] media: uvcvideo: Allow entities with no pads Date: Wed, 24 Feb 2021 07:54:24 -0500 Message-Id: <20210224125435.483539-16-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210224125435.483539-1-sashal@kernel.org> References: <20210224125435.483539-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 38c73cdbef70e..998ce712978ae 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.27.0