From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBB87C6379F for ; Thu, 19 Nov 2020 21:50:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8ECA52222A for ; Thu, 19 Nov 2020 21:50:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="OcG+6ZXd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726614AbgKSVub (ORCPT ); Thu, 19 Nov 2020 16:50:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726549AbgKSVua (ORCPT ); Thu, 19 Nov 2020 16:50:30 -0500 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5B57C0613D4 for ; Thu, 19 Nov 2020 13:50:29 -0800 (PST) Received: by mail-wm1-x342.google.com with SMTP id a3so8049396wmb.5 for ; Thu, 19 Nov 2020 13:50:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zOlDw3xAtBO2wRxDpudGLYAgtj4GYNudNiFuGERnAjQ=; b=OcG+6ZXdy+PQO9GK7Nw/wczVsoutxZ1M3eanuJ7kt69pL4SHrH/xal6OVYAbPJ3GEX bwP/pVEqa0IvEttvhnJGpczgh1hVXhex6bywvdrS/pn3E5PJWKdHei7jpq8uvLsfIhC3 YabrY2RVvcJdnGquxSn0V/Y09N17mS8cZOOHg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zOlDw3xAtBO2wRxDpudGLYAgtj4GYNudNiFuGERnAjQ=; b=ZIVfCam8k4j6OYLEC0QZAmZe/98hd8YDK+iW7uHpQ7aLzwaZ5wkrnlUsC0WZVXYpjg i1qjhhx7ryEW0NkXPQ7CMFUlH55Dp9ppQ9JDM3ob4bKmRaRgiyZg5d1Yp7nACOEa9uBo Nr1dpf/2GIZMpwcPZzx73DIN2rkYcfXm+mPF2Tkyphw0jllVdWuu/91PEHMVlqdwC4iQ efYkmQcBRmBBmgGGApllfIxCUOrGlHa+cwoF+MaWlBX/JF9c9xkTLqI0LeFPNYnltxrz zHr3BdG7dfITMsHrQ0iPDs34H7N7TvrsPLSFWdbygPC1pQ/p06VKisZRKU2qIro9+IrD p9SQ== X-Gm-Message-State: AOAM531nH29clAvaSBTaYhcPTkoXrrRQKnv2lqZgou4SopDe7PnbFWl1 AbpXl9WP/8qbIW4jC7Dxnz4xtQ== X-Google-Smtp-Source: ABdhPJwThvKiCdR+FOWM2aS+lAsiSpMLYOX5XIBtHyibvCm1PLYmlw0vayTKCFMrhzQ0wQCRGVNwPw== X-Received: by 2002:a7b:ce84:: with SMTP id q4mr6438582wmj.26.1605822628600; Thu, 19 Nov 2020 13:50:28 -0800 (PST) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id t136sm1818859wmt.18.2020.11.19.13.50.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 13:50:28 -0800 (PST) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Subject: [PATCH v3 3/8] media: uvcvideo: Allow entities with no pads Date: Thu, 19 Nov 2020 22:50:15 +0100 Message-Id: <20201119215020.508487-4-ribalda@chromium.org> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog In-Reply-To: <20201119215020.508487-1-ribalda@chromium.org> References: <20201119215020.508487-1-ribalda@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Avoid an underflow while calculating the number of inputs for entities with zero pads. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_driver.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 9f4451a2e0a6..534629ecd60d 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1033,7 +1033,11 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u16 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); @@ -1066,7 +1070,7 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u16 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.29.2.299.gdc1121823c-goog