From patchwork Wed Feb 21 22:08:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Grzeschik X-Patchwork-Id: 204471 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1324634dyc; Wed, 21 Feb 2024 14:08:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWzNCeF4PAuhZ80XpZ7Q8vyVYSWX1KYVF1Ez0xozlAMlTGGD2KLQNsq44ogiJZpLpwdMwGwuHm2ckqnquhhw88BfNj3dA== X-Google-Smtp-Source: AGHT+IEVaOmttGSnbxmQiL1NPAm49nsaLhSjP/Jvxp+2PMW3q7eVA+VRlD/ZvII6Ef9PKaThbQlN X-Received: by 2002:a05:6a20:6f07:b0:19e:5fe5:ff98 with SMTP id gt7-20020a056a206f0700b0019e5fe5ff98mr20639166pzb.52.1708553332392; Wed, 21 Feb 2024 14:08:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708553332; cv=pass; d=google.com; s=arc-20160816; b=y1jr3JbLwbPFvM/LmpS16tTyP+v0jovjzM3qGDZicJBhM3D9lVjGh0D7U0+vUp8yDz BRjUIhhYBzrUiibxgKX51jPaJpGLhezFfBkZN5nDJpmaQ9dYVN2XPdLdgaEQ3aZ4pJ51 ZvUbZpSfygd2MnhMuUhXP4129HXAhhUwnq7IjJCnos88Wx9sbA0I4F8lorhEnwuJ6k6S 2pK36wNDgu9XTxytponwlKJxrccXYRFPkr5T5JgiVR8P2cyEhDidxxk5WolRGvG4DBEb k+DKm7Tl4oYoCMGTjSMKRRyC+YYNyTbE6X7pMGlsTF705CXTrWNxs3tnQ8I0ePUYSzyA CfDg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from; bh=T9+I6JisPsPZwz/qwsN6DvJCt9wEgcyXD1rgyrQC3Dk=; fh=rKrs5iq1RvK7IdAtTGH/dIdPlPgX7+tXIrQymu3i5H4=; b=dDvnRsAYsDgNiRcUFpnZGOJpUQbA0GiiJb1EpWx08zWnOqyy7ZyjkbxBUc20Xpp7BK B8zng5f4EIt8/XeFNu1HFiWl1VZAhwOvpdY5uJTgBc1ybyB197e+AAJyXLZlwk+8Hh/a +KjVAaQW8ri7Opxg3bG1ZTSyn9Kz5iWYdcdbOoObcnq3402uFpclqomyDIEttSs/0JIt +PBWsP8mP8udk1Tw4O43tqwwVyxXtjhaTUV/sW9DmCCCNaGnpstWfCSigvtR1FmqmL+n tAP8h+WeRLHxhfp1//OoftrqhDzJ5QMT+A9zU2MzkVQaqiCZsZPfXEDIjukFpIYH+iNU GgPQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-75589-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75589-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id n19-20020a638f13000000b005dc83423faasi8670224pgd.833.2024.02.21.14.08.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 14:08:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75589-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-75589-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75589-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3AA792845F1 for ; Wed, 21 Feb 2024 22:08:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4936A128830; Wed, 21 Feb 2024 22:08:39 +0000 (UTC) Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 01E57127B6F for ; Wed, 21 Feb 2024 22:08:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708553317; cv=none; b=nOGWWxu1iS/CexTlYTpTK21ntVXdQMNvHkz9oh5o46uGeftePmDVy2SkBdF8QWRuNjnwXj4rdd0NSyLqoLC/mLC796wPGXuu3mUyrNPbfr6Lsakg6IQ6lI+yIwFH/1akwMvBN7mcGwIxSXpxTp1/d3mDc1uXqN61w7KfqoOgwhU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708553317; c=relaxed/simple; bh=osIvO3Rr4RNhy8KfumCNnV1e4Hfi2ZGD6cGUJ7ZBljY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=DB7ioh3cpzti3SZ/sx6adFonEIUjnb1ll3RnALNMDpBExUMEdba4Tv5Y622bt1pCJaxR67bXcHcG3d8sjG0k7PzRaS6G2E79ZQQSWT+K3Q+S5urCOTS3+dMMED/75SM/MvKnJtUViIrwHg8jPCGmqD2q5u0i9UU97r+yo+io4+Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rculU-00087C-FK; Wed, 21 Feb 2024 23:08:32 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rculT-00275u-Tj; Wed, 21 Feb 2024 23:08:31 +0100 Received: from localhost ([::1] helo=dude04.red.stw.pengutronix.de) by dude04.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1rculT-009xti-2n; Wed, 21 Feb 2024 23:08:31 +0100 From: Michael Grzeschik Date: Wed, 21 Feb 2024 23:08:31 +0100 Subject: [PATCH] usb: gadget: uvc: fix try format returns on uncompressed formats Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240221-uvc-gadget-uncompressed-v1-1-f55e97287cae@pengutronix.de> X-B4-Tracking: v=1; b=H4sIAF501mUC/x2N0QqDMAxFf0XyvICWOXC/MvbQNlkNuDiaVQTx3 xf2eA73cA8wrsIG9+6AypuYrOowXDrIc9TCKOQMoQ/XPoQB25axRCr8xaZ5fX8qmzFhTCNlnqY b0whep2iMqUbNs/falsWlj1+y/+8ez/P8AUUeFCV+AAAA To: Laurent Pinchart , Daniel Scally , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Grzeschik X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2107; i=m.grzeschik@pengutronix.de; h=from:subject:message-id; bh=osIvO3Rr4RNhy8KfumCNnV1e4Hfi2ZGD6cGUJ7ZBljY=; b=owEBbQKS/ZANAwAKAb9pWET5cfSrAcsmYgBl1nRfVFFupHo9D4ssRIPwvD9iwMrUWrf9w4/4M T20WCfCPSiJAjMEAAEKAB0WIQQV2+2Fpbqd6fvv0Gi/aVhE+XH0qwUCZdZ0XwAKCRC/aVhE+XH0 q3zwD/sGkFvwYCARNgOqt3OjyxmAqc4U3iU4t+LabEPz/x7whMQ7MKv5t7TranPdMmXwyQx+e1Y zgLlH+CvEZAhHP7Eo4Jyb/k06nGFKbWwvkQCVNf7e2MvOZ+3uKuGe+xvRz6nzBfvkI5turlaSdg FzkWIBXV1YBprzEpMd5Hjanb4OlX8r89ppRMrhzV2jnqSS5yqZuxs2a5qXzXfM6epk96t5wLS2y kYdY8A+zGnlq3sp7zVh9AuYavVDclwTNi9Hrwyo75UTg/N0qIuNuap+wIkymxmiBcydYJSM96Pq fOR99O1+HwoH3RLzpeaQaS9ZWm7HkNnZu2j/gHGRfCcoUZwnDxyW3Lolw/BUFHRAs4Pbc5i/MBj Jv0FWWUfN/jU6H3DlvVAHfr6C/9oL0nRsuOGn9Lxv1PfvbAPyQQqs+I27o5joXXSKFIWXkM4eYq 5fMqvLxRvctnbKb2UmEP4njTtRv32nlKrId+0CYsJ1wmZ4ClqWSWoWuOd1qps2RzHtYb40Vh64X rln7dU0gFbPgx/oLAAPHbKxlYqh0t+zlVm9sFAlqVuxedFY57DNf3VuscDQdAQgl3TWvBmUN2Hg IhYpB2d62ifVVdyj29P/rgbC/o5SSF3YTDrxjqN2WOCoE2dXGU4qacP0bjA6HH7jISmRMYLYzqm 12m7IhvpC1VFwew== X-Developer-Key: i=m.grzeschik@pengutronix.de; a=openpgp; fpr=957BC452CE953D7EA60CF4FC0BE9E3157A1E2C64 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: m.grzeschik@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791548019298356823 X-GMAIL-MSGID: 1791548019298356823 When setting uncompressed formats, the values of bytesperline and sizeimage can already be determined by using the v4l2_fill_pixfmt helper function. We change the try_fmt function to use the helper instead. Signed-off-by: Michael Grzeschik --- drivers/usb/gadget/function/uvc_v4l2.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) --- base-commit: 3bf0514dc6f36f81ee11b1becd977cb87b4c90c6 change-id: 20240221-uvc-gadget-uncompressed-ab5dce996ed5 Best regards, diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c index c7e5fa4f29e03..a024aecb76dc3 100644 --- a/drivers/usb/gadget/function/uvc_v4l2.c +++ b/drivers/usb/gadget/function/uvc_v4l2.c @@ -260,12 +260,26 @@ uvc_v4l2_try_format(struct file *file, void *fh, struct v4l2_format *fmt) if (!uframe) return -EINVAL; - fmt->fmt.pix.width = uframe->frame.w_width; - fmt->fmt.pix.height = uframe->frame.w_height; + if (uformat->type == UVCG_UNCOMPRESSED) { + struct uvcg_uncompressed *u = + to_uvcg_uncompressed(&uformat->group.cg_item); + if (!u) + return 0; + + v4l2_fill_pixfmt(&fmt->fmt.pix, fmt->fmt.pix.pixelformat, + uframe->frame.w_width, uframe->frame.w_height); + + if (fmt->fmt.pix.sizeimage != (uvc_v4l2_get_bytesperline(uformat, uframe) * + uframe->frame.w_height)) + return -EINVAL; + } else { + fmt->fmt.pix.width = uframe->frame.w_width; + fmt->fmt.pix.height = uframe->frame.w_height; + fmt->fmt.pix.bytesperline = uvc_v4l2_get_bytesperline(uformat, uframe); + fmt->fmt.pix.sizeimage = uvc_get_frame_size(uformat, uframe); + fmt->fmt.pix.pixelformat = to_uvc_format(uformat)->fcc; + } fmt->fmt.pix.field = V4L2_FIELD_NONE; - fmt->fmt.pix.bytesperline = uvc_v4l2_get_bytesperline(uformat, uframe); - fmt->fmt.pix.sizeimage = uvc_get_frame_size(uformat, uframe); - fmt->fmt.pix.pixelformat = to_uvc_format(uformat)->fcc; fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB; fmt->fmt.pix.priv = 0;