Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1977161pxb; Fri, 5 Mar 2021 04:36:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZpLwAQ+HDIJMqkDchICqciLkfUdywZzvhkim/L9MehBjIndZRYaf5DgWKW3V8O42drxlN X-Received: by 2002:a17:906:828e:: with SMTP id h14mr2052640ejx.529.1614947790803; Fri, 05 Mar 2021 04:36:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614947790; cv=none; d=google.com; s=arc-20160816; b=QEH0FRHJM+j2Qoqg4R8/az3iV14ZFvF2jUdwaI7bz4Z4dDC9lzdMphxSB3wP5JLn27 Q7OZeuQE6kTmFltEXa5uvO4Yyu6TcA465XjdXyxRY78qjI42K/kLoeotsx5gLE6Kt6ft diB0SfC3lbpR3HdDIAi5WXV3nkh9BciOkK2lxqp7eA3kotEKcoTpUOpGBSKjZAu4wNr1 Oh7nog5ZeJKK+2iDxxuCZso6GS+ZgskGUgjwQaQIBrTSxpVcGhTHiDVBE+BwBCzL6Byv 2l8KHgzgjkGRgT+FrJgsSE6eQS5zJL03kw8DQ35s6rzcMKlop9miV5QUSCrwT9+yLJ8W fkNA== 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=y41w6PVwY+BYLvEB89LASWjSzvzwR3mOWQdfT002+oM=; b=Da9mVI5i1M7Wb4aW18M2fn1s9+wZhwjKplm9YiwqKqfZ7U/XC0Io0bLuUKeF+Et1U/ NkQ/oenPKBF9FZ+0oI1tc9qMYtbNC64Ciow1Z1q2Ipj1vQpnXEm/+7nLH6xk2kWlaFbN k5abjvpmwhnO4FHH/4fabA1395Vaz4JkR9f9y6NTNjOnBB9oYHPzSqerZVsv5b2eslBM pn/WncflrBVZfgBBjLYlMZxwdlffF41VOGxbwbcvgo2NSsHHL4o2cJcwz4PXoRl0OiAk BbbTDpnwvO70ZqnIaG9ELi2bd+AIMbaiZOdRuGU+HhuoOMmXCqziZuUhjJXUFYyOE9K7 uuWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DqAkIjTs; 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 i8si1216773ejj.286.2021.03.05.04.36.07; Fri, 05 Mar 2021 04:36:30 -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=DqAkIjTs; 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 S232731AbhCEMfQ (ORCPT + 99 others); Fri, 5 Mar 2021 07:35:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:46404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232041AbhCEMeo (ORCPT ); Fri, 5 Mar 2021 07:34:44 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1206565012; Fri, 5 Mar 2021 12:34:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614947683; bh=OwMQz5KXEvz6gkTdf5tY25ZgpaYcBxyyXegH2uE6mxg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DqAkIjTsGriKBX/VJIqFHoa/ua4yuiHJuM5I6lSAIof6YybJiMAv5JYkbvikfG7sY qvDW6abnHYgV8rrUc8XABJWZpKAWeXeaSQETwxcb7WB7nERultK8guq6x/mHlBMIma ryJGI2vQEH/E7HnlVedwJ7A+jtn+Hov8XTITFoCk= 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 5.4 46/72] media: uvcvideo: Allow entities with no pads Date: Fri, 5 Mar 2021 13:21:48 +0100 Message-Id: <20210305120859.594718349@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210305120857.341630346@linuxfoundation.org> References: <20210305120857.341630346@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 99883550375e..40ca1d4e0348 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.30.1