Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp445012pxb; Wed, 24 Feb 2021 06:28:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjXsOqJW7UhQ6ZLAJyXKC9Fqn1cdH2uSN48P8Sq1zOaEvxYLUdHRV2sXjGgKCN1CWj0fcg X-Received: by 2002:a17:906:d19b:: with SMTP id c27mr5549686ejz.304.1614176888663; Wed, 24 Feb 2021 06:28:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614176888; cv=none; d=google.com; s=arc-20160816; b=dCt5ZhsvhfdC/+c1XYedd/s+GG6/pm+vKGAbJrKijS8UkoMX6diH2Nnqpn6syOtg7F 6B7oU4adD3p469kAXfT00qPpd/LU9pgF8eaphlYqfcn1aDvV6tJm0NtfmcMvzZpPdfdj 0pew18hIcooKw1Qtb7Mr6v6RSrtIOF1HP03/tCDFQ53nzAUYkH+CqlRGfI4JuNWEtt7P 9vUtUD0icn1TdruV0YPTapj7jqYrLXUzsOGZyUkmZ/BvGFqGwWn4DAmjcpwyLSbCQOFM Ut6Cpq6GHx7uHyMyYyjwgSBXxumNOi4It3MLQPAJ6XFJg08XEb0zbSm5O9wi6tmNxZLm wX0A== 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=GQStIQ06rKL9LmOcZm+gygmh15LKP2tgdA/nhOKIsio=; b=JiD4YUOoOCCx6a+J99JJiHOJASZD79yMQFrljgBPh5huLRmjtXaEPn1sJwJglZ5w2f 5d3krdjX9M9YDR3tCsRNIznaidwpi5/SZRfh96dNZ61H7dkBpKkEedMtqFzYbKZkLPbi l+RyI934faMs5ZrHTk7u9SLwNhmw63vI8Bi93+GXHleNVLe2it7fw7UkX7CyXwUfaTw6 nfF3i3fL0eJE2wpQtEtt608TnMN8nyku2vbtu2Phm4hPiDhpxX0q/6It9daHimQKtRvy 7ZcR3CmG8LyCil/dIhQZOAVuU2ns/UwRIlo84tsXVf4HxUmJXpBZ225YHg/iJeZMjy3b RGtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GpudaQLh; 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 b9si1292943ede.108.2021.02.24.06.27.26; Wed, 24 Feb 2021 06:28:08 -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=GpudaQLh; 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 S236323AbhBXOQM (ORCPT + 99 others); Wed, 24 Feb 2021 09:16:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:59884 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235320AbhBXNLS (ORCPT ); Wed, 24 Feb 2021 08:11:18 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5A69164E6F; Wed, 24 Feb 2021 12:55:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614171329; bh=JLdY6mO9wFBXvwUwH0t05F3l6gYMmG/wKxRG6/umEsQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GpudaQLhneGaNDMWs0AT6p7fpuOC8CSxq7gAcqtFLCZLs8msTLm57Y7ajKdw1Crl2 /j8F1NitF2reKoUj1Y1DyWiOxfh9cbJk/hG9xoW+9pnpw/eVC5FCOlo+nnbdY5OYLF 1Bs41CsaXTrbi5OSlLFVK/48CvvjFX51zdC3Ym0JqIHbdBlhaPLgtCZMNqgdcZvKpi f6BH/7JV3Bb+ej3mMFVFMHPAsMvyEQnFy1ElNT4LevUGrIhS6GeOGrrVtmsxKlUinq lh1+W8/pmt2nApZUI9BZ0vsKRX/+ZoomA8dCj+jPB2O4YL35eqGo9vVWdQM83vHB4L 1oYnYV8AaFPwQ== 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.14 11/16] media: uvcvideo: Allow entities with no pads Date: Wed, 24 Feb 2021 07:55:08 -0500 Message-Id: <20210224125514.483935-11-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210224125514.483935-1-sashal@kernel.org> References: <20210224125514.483935-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 5899593dabaf6..aaaee039fb30c 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -904,7 +904,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); @@ -920,7 +923,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