From patchwork Tue Feb 13 23:28:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Grzeschik X-Patchwork-Id: 200732 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp868591dyb; Tue, 13 Feb 2024 15:29:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVj61mrXcOagk9fGmj+LaYgDiVdADUsSdOngVFIxJ1zss37VQDlqcQWqFJX+pvFIm5NSRC2K3a/Dq4zdv7iWxrWqchgpA== X-Google-Smtp-Source: AGHT+IHdVlTLIGgxQt6oG4fyV3OufslmxIpWoqR1+XOPkw9IcsD8TLx5GbiFiw+Io/syacumvNBG X-Received: by 2002:a05:6402:69a:b0:560:1c4:cb31 with SMTP id f26-20020a056402069a00b0056001c4cb31mr840273edy.17.1707866963075; Tue, 13 Feb 2024 15:29:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707866963; cv=pass; d=google.com; s=arc-20160816; b=PHjtNzeSa/CxPivNPRJCR4HITTwbN4lBXtqHQvkhy6CZbbBpsHGCjeoXNk/MR8wE1y bN5uqbkEU89Gr8OvrjyPk4cJpWWkXT34i/wHg5tk1rtYza6Fjq60rB3gMdq1eJmLxebL NIn6Pb9wR/D0OgVrP4N+lTyxar8H1vhDYtsCJKepDbfX8NUZCNF7CdZh2yA+Z7gdpgfR jSttvGLDLrbucrIz892UmpQfnume13zdsliETWcYPcbDyHA8Ick+68cL6ifA6krDo4KH 6ntLZ0PIAEnX1JQkFzpmNCpreqqbgepkRWdDO9lq9fF82+s6RLKOFyfApEDpY7bJFC5o SPIg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from; bh=jUfTvjrcWFarSzGDdtecekesHa52GM2EFvExF+n6tjc=; fh=5SQRJE0N328xoOrB8JklKCDTizGHsjNPIn4C7TEzVeY=; b=MfBBTz+HinYrkptQkyzYPv+QG5oswMSVBFTSa/oN3M5Gz/i6J7rXE0izQM2iyPsxwl Ja6kus1XBwhjYGxAryCz/OBO7x9uNOeXSUF2wkIAvuUiV0RrF6gckapZCY5nvZnZm2Ln xFZdL0KSH8SU2vB+mzydRhIaodG43naCB2QjiXeQWmgU+ZK82eA/MwuN6dQ9PORZIeUT lGtO7+x21M6ZWL9WTaRh/JzcwvkjXBvS0zj5XFJifrbj8o4Xj/+g5kqVWzCqtPdLg/dL 4Xo7j8xy2Qqg9Y+rEhU8Rmi7VtCLBFDVwzGsPIZeV+cQwztFa3pZx2hbFrKmYBJeKgVj pLmw==; 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-64540-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64540-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCX3unH/dZzURvEGzN/2ztfRbs+mFk85lLBxm5FHbX+19rtJQy8a42DMhA5I6pG0EFPhuH+dYdxwaWRFKjF9x7yqVQiWTQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id y5-20020a056402440500b00561e8cf5bd2si1427974eda.71.2024.02.13.15.29.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 15:29:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64540-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-64540-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64540-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 am.mirrors.kernel.org (Postfix) with ESMTPS id ADD3F1F2678F for ; Tue, 13 Feb 2024 23:29:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4FC0B64A98; Tue, 13 Feb 2024 23:28:27 +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 E753D63100 for ; Tue, 13 Feb 2024 23:28:21 +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=1707866905; cv=none; b=ZpOY/uVWqIuSSKqFC2/ChmeViZ45n7omfEnozpx+RkI6OWb3zxPWiBaLk1nDUBqKRkg4K50cQy4n2pg6rPy8JyJZ86Cn7Loyxi+frExVeL39rhMBx/FqBjmPhfNCif5iYn0OlS0H96/LQNTL55+7R4Cm2rSVwdYp2h9yWLYEPrY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707866905; c=relaxed/simple; bh=CVvV8hDYr9bL6m/v186v76mN5LV1BfGeIcNkfm5yuxU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bBb16mw4KHbyJwRaSFR6JOb6WuOGU3aKAgcGCF6OAar5naAs2RhuJAp+L71oGxoI08bBs/GBJzsqhauJ2aGK1+vB5izHS4PnftvJ5l/f+jdcnA4PlSJZmjuiSYDUSU1hTBmpg6/2hjeIATPJmrYiyjtJ8IG5zeif2AF4vtmcNfM= 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 1ra2CI-0000eT-Ig; Wed, 14 Feb 2024 00:28:18 +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 1ra2CH-000Zco-UN; Wed, 14 Feb 2024 00:28:17 +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 1ra2CH-002uYW-2s; Wed, 14 Feb 2024 00:28:17 +0100 From: Michael Grzeschik Date: Wed, 14 Feb 2024 00:28:00 +0100 Subject: [PATCH 1/3] usb: gadget: uvc: drop unnecessary check for always set req Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240214-uvc-gadget-cleanup-v1-1-de6d78780459@pengutronix.de> References: <20240214-uvc-gadget-cleanup-v1-0-de6d78780459@pengutronix.de> In-Reply-To: <20240214-uvc-gadget-cleanup-v1-0-de6d78780459@pengutronix.de> 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=1032; i=m.grzeschik@pengutronix.de; h=from:subject:message-id; bh=CVvV8hDYr9bL6m/v186v76mN5LV1BfGeIcNkfm5yuxU=; b=owEBbQKS/ZANAwAKAb9pWET5cfSrAcsmYgBly/sQQgP/ZZy8ylorPv7GT/3A9CuCeeR014oGi 9Gb6LEjUnKJAjMEAAEKAB0WIQQV2+2Fpbqd6fvv0Gi/aVhE+XH0qwUCZcv7EAAKCRC/aVhE+XH0 q4VlD/9MdVUKJntclRLZA9+6LfgBeSjMnA8IU3fGMyrHpVnji8ec9PYNN6B32ZBAwLVrXO2AJMe /uwnF1rwcMZh3SNwuYd8/F4KNHoGczMBLKde7lMbMqe/dw/ZMFmfu+X8vSFtsEiG7tglYclDVF9 b7dPDaWNtDfC8NFeDDSpEBXKt6IXAmvrmnU7O2gjA/C7jEwRiVNlwNHemS5aGag001x+ZMCePUJ ERP9/oKtX/YbayjsgX8ELtbKtTXP7JafYBCluP2wVCi61KH3hsAr2htd64TEj6Rt9g6F0oWYqqj dAgf+AxbexdinTMdIIeUX/pzFKsIQ6vMUctyzGEzRvjrK7YoIIE4SC4ojlEWYqajkKs68KFUvS0 zVld8t8K7bXeOQjBd5b4p5glYwR5pelkZbqansD/CF105Bg5slCKJeAXb1XEQaN11HtATeYsjkj wsSHPL0KuzvE2+BGCSpkRWT+HgiYpDk+k/iAm3i5p8EGPWcFmAlVWzitrbGfxDBQoRiSVbJj12g 8WkmKm194XIg11UAXmxfLaOHF7N285QK816uedbPsDfKpebN8nbGjZxdNQOpXbVvH+CVNgBZtJ8 o5uqotVDYFQLZxDLd30L6W5x68yJsfNr+BhHIYBga1tPOXKeBITfsn7ku/Win2YMAuqmrK8qYJ4 aeAfTYjv/EL7ImQ== 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: 1790828308671553621 X-GMAIL-MSGID: 1790828308671553621 The pump function is running in an while(1) loop. The only case this loop will be escaped is the two breaks. In both cases the req is valid. Therefor the check for an not set req can be dropped and setting the req to NULL does also has never any effect. Signed-off-by: Michael Grzeschik --- drivers/usb/gadget/function/uvc_video.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c index dd3241fc6939d..b17c61c932652 100644 --- a/drivers/usb/gadget/function/uvc_video.c +++ b/drivers/usb/gadget/function/uvc_video.c @@ -623,14 +623,7 @@ static void uvcg_video_pump(struct work_struct *work) uvcg_queue_cancel(queue, 0); break; } - - /* The request is owned by the endpoint / ready list. */ - req = NULL; } - - if (!req) - return; - spin_lock_irqsave(&video->req_lock, flags); if (video->is_enabled) list_add_tail(&req->list, &video->req_free); From patchwork Tue Feb 13 23:28:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Grzeschik X-Patchwork-Id: 200751 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp884199dyb; Tue, 13 Feb 2024 16:04:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU2P9n/0JBMJWfcE9qz9lsj861MOCNUX62DlMjyMQPeVFqRQ7vbhx7O0oLJUcwrwfTJm1VhUUEGTXKOa79X+HU1neOUfQ== X-Google-Smtp-Source: AGHT+IFTBKonUAjatL0U8N8tcaBSq4l8kwDXyaoLL6OqIGbWQUTnwMkvleVxaOcgYJGQhw7GVm96 X-Received: by 2002:a05:6a00:26e0:b0:6e0:384e:c6ce with SMTP id p32-20020a056a0026e000b006e0384ec6cemr455030pfw.7.1707869089709; Tue, 13 Feb 2024 16:04:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707869089; cv=pass; d=google.com; s=arc-20160816; b=K0uNVtXgFhtP9tk+vhMiy1F6PF4/dny7Biy4/QMgXsQ+sUQO98ndmX6BwDCJ1DAp6e yoQBj6cZHJxWw0KSlTEForE06eZi/2xQkRMk0BeoT5sEoqBNYxLmFj6mofMj96ayPc7U gx3ymwswOOFm2GvFbhReuKf2eIlygSm3hlaW1V3vF16g8MOdtl4aSnm7o6DYQL5VIIGl Z/kpj8FYWssMayT0n8Wq+gDTiwUULaCkZoSrgPJ0QxU/50Bci6VqcbofdBzHIUMBoMhg 9/PqA+kv+zgxf3SuvWVFLaBCyefxDpsAVVYECdW7ZWkgfaKdu0Hhq8a0QT/X5xXiO3q+ d+Qw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from; bh=toJipEIkczFD3wqawB6Yxh08HjgMEDvL3BVswzqBOiE=; fh=5AQKaPVt2XqdqcUXXasgjEAoYql4F/aENrwTj4eZWZE=; b=1KX1uTevB35jXdaHYxPsolmn+evVqp8fdQoY2cj4566RoCbh95syovuJyKY+/1X2Ms cUenqwmU5Likr0kJ6j+9klgeANpfyc+fXlzLaSzZi2UPk7u8eM6gHauJxKO5HzByooiW 6JoKCkLL4ORtwJI1QeS0MZA++VPeK7hQyM0mMDmDNSn7d6ZKd6/gdnQK8G0RbI+gZjDr q4A7mtjcKckaEbk6Jw9pS3l9bBppQrDh0b/n9knDX5zhshr6tOWy031rSPsp0caWdCNq mKOYjv09KD9iMsDSV5BUVfKNodY1yjBzKmBif2qg9S3X0srN64HbO8UYAt7HaXu/16WI 1UsQ==; 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-64539-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64539-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCW15q4rDNnMjPbHXuaJYLd4//pKu4IJ/ZpVJeVpjxDy1vWo3wIitcz8KTO7TiXfd9QovdUxbpmyIjQES/r9BPY53mw0nQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id dr7-20020a056a020fc700b005dc504aeaaesi2783408pgb.33.2024.02.13.16.04.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 16:04:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64539-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-64539-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64539-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id A027EB2443E for ; Tue, 13 Feb 2024 23:29:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 40BAD64A93; Tue, 13 Feb 2024 23:28:27 +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 EEFD263106 for ; Tue, 13 Feb 2024 23:28:21 +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=1707866905; cv=none; b=OcpKASm3wg3jIwXRriNeD7OykG2BxEJbUJZuiu2rQk4PnbLY/ABSR/QXMUBTWn73PhgcyBmZ+551j4muzz0HIjKbBs+sNcRDs6NCVOvmwZX2RR+24q+Va0MxiQZCozIO+9BGlpfn+xouRcOEKbL62GeAAyaIkGduElJaHcLhYQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707866905; c=relaxed/simple; bh=30YYmuToXt0Be5FF1D9822Y6K2GuA90aOezsbaqJW0s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MaV2dA8pIMgXJQ1orxBQmuGLQ24G1DB65lZp/Begp8ZcGbQG/Dw+Yk5lPfJVEB6NWujHRZaQnY26zH6hjKj4hPMC9QkPdJ8Mt36a/9bCOSvdSctP/xAl3aSkHRLvwRo9fjSs1q5HO8fOYB2G5aAIVzKqorHw6dKHA4EkmpRVYeY= 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 1ra2CI-0000eR-Ij; Wed, 14 Feb 2024 00:28:18 +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 1ra2CH-000Zcp-Up; Wed, 14 Feb 2024 00:28:17 +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 1ra2CH-002uYW-2t; Wed, 14 Feb 2024 00:28:17 +0100 From: Michael Grzeschik Date: Wed, 14 Feb 2024 00:28:01 +0100 Subject: [PATCH 2/3] usb: gadget: uvc: refactor the check for a valid buffer in the pump worker Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240214-uvc-gadget-cleanup-v1-2-de6d78780459@pengutronix.de> References: <20240214-uvc-gadget-cleanup-v1-0-de6d78780459@pengutronix.de> In-Reply-To: <20240214-uvc-gadget-cleanup-v1-0-de6d78780459@pengutronix.de> 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=1153; i=m.grzeschik@pengutronix.de; h=from:subject:message-id; bh=30YYmuToXt0Be5FF1D9822Y6K2GuA90aOezsbaqJW0s=; b=owEBbQKS/ZANAwAKAb9pWET5cfSrAcsmYgBly/sR6vOuNRf8bz1usN1hrU8dGhJSMxHuyafO/ vgaWNxSX/eJAjMEAAEKAB0WIQQV2+2Fpbqd6fvv0Gi/aVhE+XH0qwUCZcv7EQAKCRC/aVhE+XH0 q3pXEACPUYRmu19z11qUsOha/z9QRa+P7klnxF6Mf3Zgi6d8WSPDG3m1wdvDxkGuPcRJ6ksszw6 qBmF8jzi/kPJFD8aOZwdaPExVhPEP2QN9n7k09m2C+hLlEzstCtqMF4oIUseP4P+4ERtJDac0JW qux4XtvYoU2d4OIMKZ0jHTLKT2TDe+QSuvYhFCFse0EUufu1lJvQrY36oaYFbIMGRN4jIqS3/OL LqmIQPuKzluEaypn5dL2EiUMt/e8SWbtBGowp6byn0x2YK7x14x7VaZqzcWRsF1c3W77PS9GFtA kVdq9F2uUQaI/MOGtx/aYZ0c3Z+C4JTV0JJOjoc+3dgsNXRqn+qOE/Wusr3fMgKd+mbg4B970lE pZETUw5p5wv1CwsbcKeEp6MZZGLU4ujE3ortF9rWAAJx4WJzlXiYRoTnBg7TrfFf+41ssu5kdPU ZcXN0G6VQlz7r42JKbezSEIeGbjhUAEFpMv3RDOqxm1DUw0z+Ao9KfAV724kGW407Y8gE8kWfmT D5Xw9BMLebOHgSiEqJPtKzym3/fkI6uc2pMycN7pZzgqhLLiawSLiYqDKiI+bV6Tucy6/mOV2cZ VYTZr5upT5Xy0zxQKbIr9nb968YB9ybO+KD7A75HetLTqQ5un+Daq+T0KJYhJdAlXf2QtGeYwU5 lizaj9dmtWYG1aw== 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: 1790830538194873548 X-GMAIL-MSGID: 1790830538194873548 By toggling the condition check for a valid buffer, the else path can be completely avoided. Signed-off-by: Michael Grzeschik --- drivers/usb/gadget/function/uvc_video.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c index b17c61c932652..b4f3b3c784218 100644 --- a/drivers/usb/gadget/function/uvc_video.c +++ b/drivers/usb/gadget/function/uvc_video.c @@ -594,10 +594,7 @@ static void uvcg_video_pump(struct work_struct *work) */ spin_lock_irqsave(&queue->irqlock, flags); buf = uvcg_queue_head(queue); - - if (buf != NULL) { - video->encode(req, video, buf); - } else { + if (!buf) { /* * Either the queue has been disconnected or no video buffer * available for bulk transfer. Either way, stop processing @@ -607,6 +604,8 @@ static void uvcg_video_pump(struct work_struct *work) break; } + video->encode(req, video, buf); + spin_unlock_irqrestore(&queue->irqlock, flags); spin_lock_irqsave(&video->req_lock, flags); From patchwork Tue Feb 13 23:28:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Grzeschik X-Patchwork-Id: 200733 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp868650dyb; Tue, 13 Feb 2024 15:29:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVSIAcRCDedI1uu+1wsXgrqyKRjSaZIqgHJJiXKbR4QfaM38XPQX6ujfS2b2ChxfwROhCm9mYAIxTVZTyJ8vkDM7UnWJw== X-Google-Smtp-Source: AGHT+IFIF6o2xvrKNrPv9o6jsEw+VsHYuJF8cbEa3X4EdfjpNid+3pnlC/eVzqRCzkqQVu94d+ui X-Received: by 2002:a2e:be0c:0:b0:2d0:480b:8d76 with SMTP id z12-20020a2ebe0c000000b002d0480b8d76mr742806ljq.47.1707866970957; Tue, 13 Feb 2024 15:29:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707866970; cv=pass; d=google.com; s=arc-20160816; b=qjElj73iHKV1b/mRCShmhDr3FivsMSKri+E37jVT/swswJv/xLHKTvtdy7tKGnqMKL /eC776UuJxyEwvAzUdD5v8a7/tZ1qxbOHxcTxyNL0Lpzvj8K8KKYGfYafU4a1/TxnamX plSpJVYmey7JD7UcwkXUPKIXu7Vs2t2tDhV1dgGat1Ja6MRvB30E5/xy4c7qzYtChafW zbgkyHYiB6BLQ+Fxtu/02lZmPX7xFC8LpQx1EfY5op8lS67gd7NujVNK/SjudZWe2DMp 87UK5KpS59W4BHUMCHZ7O7GKLF2RdEQndz50WSds08Ze6GqAKPsbCbUh9hVb0KN5I5Hg 9hZw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from; bh=8qpZJbyh/L13CObu6tVGEGcD5iA5gWD0BNOb+ahT2P0=; fh=wZpl6U1vLSgmCYoE6mESrpv8oP7BRoFr5EjUE9lQld4=; b=wydHKhPlzkDXQx6GzOd6Ql4S5vuUb1Haqgq5+poanU7KOYTIQIY3FpDUcqlyzhnSqW cdAaB6ORSzrol1ds21h4vp2NVMA5v9zHW0tHFVRSt6gadka4jFbY1pCNDjE7liGlyHth 3vtYaFzyV5RPF++H8xwitP1LHKgvI5X+5plJJwMH0jCjYJhOLjs0SF9dVB9UGmJzb/Dz 4x5t9oOaw1y30gStctSYQUfBHUsDv+aOl5nc+MqgjmA7bvbSfe/GW62jvYy35TkBRPZ+ 4mUitpMWB+oretukKgRYInKbEvcay00jvWNRRAnX8s/1Eae2xRcXuqjZ05e90/D0smFV pvYA==; 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-64541-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64541-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCWxIpn9sp0pr5X2AqYYb+qJISIo88tn4Gxoi+dxP+F6Ax+BcZBTzlvqpb430VXNKo2e4DVtFq5e9pCRtg3KNUljK/zOxQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id j5-20020aa7c405000000b00560c92f8706si4081486edq.576.2024.02.13.15.29.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 15:29:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64541-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-64541-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64541-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 635DB1F26C63 for ; Tue, 13 Feb 2024 23:29:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E4E0D64CC9; Tue, 13 Feb 2024 23:28:27 +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 E758363101 for ; Tue, 13 Feb 2024 23:28:21 +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=1707866905; cv=none; b=IIOllSbt7gwsDJT3rDiz50HxNV2R7tkMMc6MCfG8v/4FxpWGib4Hw4rLKiHMgDUpcUssClq7HHheKkKoS3bvm6UBPYbL+H6x2QXxGiXJpaNUZensQbYRNFqokPIEpd2v6Qp8tG+dLDHII1drsbCnAMa8lelSRpDxgcL7Ylzm/pY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707866905; c=relaxed/simple; bh=IQ3Y/e/zPuJO66WvMrusL0LrQcoWvCq272yYuoXcg8I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SnUq4at8De0kbww9/Ghi9c30r3D48iVo5DfeROrDuYdioSVEgDm2+Q0Ic7B59pqBn5mjFcZGZg+8N94nlbpTHED0NbGZ9j6Bi1Jo5leM6MxCGyZ63+jDgUADajV92Ve6SpVNyYpKaT1+je8eGUD2Ekt8LgTcGD4zn0TJu3qxkR8= 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 1ra2CI-0000eU-Ih; Wed, 14 Feb 2024 00:28:18 +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 1ra2CH-000Zcq-V8; Wed, 14 Feb 2024 00:28:17 +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 1ra2CH-002uYW-2u; Wed, 14 Feb 2024 00:28:17 +0100 From: Michael Grzeschik Date: Wed, 14 Feb 2024 00:28:02 +0100 Subject: [PATCH 3/3] usb: gadget: uvc: rework complete handler Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240214-uvc-gadget-cleanup-v1-3-de6d78780459@pengutronix.de> References: <20240214-uvc-gadget-cleanup-v1-0-de6d78780459@pengutronix.de> In-Reply-To: <20240214-uvc-gadget-cleanup-v1-0-de6d78780459@pengutronix.de> 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=5140; i=m.grzeschik@pengutronix.de; h=from:subject:message-id; bh=IQ3Y/e/zPuJO66WvMrusL0LrQcoWvCq272yYuoXcg8I=; b=owEBbQKS/ZANAwAKAb9pWET5cfSrAcsmYgBly/sRqPjQgnXhsPN6K1krJXPbN4oO0gMIjSHDh ODyESfaFlCJAjMEAAEKAB0WIQQV2+2Fpbqd6fvv0Gi/aVhE+XH0qwUCZcv7EQAKCRC/aVhE+XH0 q/CaEACMk8xx1roCJwuAZ81Qtu6o3wB2rl5GyAJ4TGAKUYLFtMwIMvqir785IWJBD5ddVQqosrW 9AmHSNjTDXGpvYDLg5QjBwffQ/49LmMYf+Mrlsk/In1oRHlnFCIdN9geB4tFvClyzHf0H315nQa SjCyO62cqg/XRccWR+iJTyiD76bvAxHhWQDYr/UAWy4uei2gM48q2qYK4V3fVtMsfGqpihMBkjM VL+aOLY7UEPz3AG2l2CtdKF3/BrVROox+N3BMnuREWleGZua1UXL0YAuHoxwW66GVZbBYWSlbJr JsjkX4cnVOFb5bIdQZP1ljgCss2dFsYoI/QAv+gbWDLCRIfKKRNGE+uYIJ7D7eDMt/nmCr1nS6h DjjkpfqWil5Hxr6N9L21BBWmPSV6lTG7OAE7tF4+zyvAL802Bj1tbJQFr0lJ48D5dlklKS93+X2 HGA44nijWDtmAiL43lHs4CDVMMA3juRa4rQazbVo9KsWP3m2PORNs1aktfGlMjZbFbGlhqS77NZ imRt0DdYrCsK+dISSMAR+Di2DXMiVsrlsxmAq7UWZw74yo49LkFclNVjGTMaU5zGe6sDAL/QkfA kEAgkORQJe3uR9ZdEgblKvQQprgjcFvIhTCOwlP8z8VpbhZ4MAanquiH1+ZCGyXuElIo2xzYhE9 0y7ceOz4sHl6/gA== 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: 1790828316781482257 X-GMAIL-MSGID: 1790828316781482257 We refactor the complete handler since the return path with the locking are really difficult to follow. Just simplify the function by switching the logic return it on an disabled endpoint early. This way the second level of indentation can be removed. Signed-off-by: Michael Grzeschik --- drivers/usb/gadget/function/uvc_video.c | 95 +++++++++++++++++---------------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c index b4f3b3c784218..ff7c1fa5c48f3 100644 --- a/drivers/usb/gadget/function/uvc_video.c +++ b/drivers/usb/gadget/function/uvc_video.c @@ -370,6 +370,7 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req) struct uvc_video *video = ureq->video; struct uvc_video_queue *queue = &video->queue; struct uvc_buffer *last_buf; + struct usb_request *to_queue = req; unsigned long flags; bool is_bulk = video->max_payload_size; int ret = 0; @@ -425,59 +426,59 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req) * we're still streaming before queueing the usb_request * back to req_free */ - if (video->is_enabled) { + if (!video->is_enabled) { + uvc_video_free_request(ureq, ep); + spin_unlock_irqrestore(&video->req_lock, flags); + uvcg_queue_cancel(queue, 0); + + return; + } + + /* + * Here we check whether any request is available in the ready + * list. If it is, queue it to the ep and add the current + * usb_request to the req_free list - for video_pump to fill in. + * Otherwise, just use the current usb_request to queue a 0 + * length request to the ep. Since we always add to the req_free + * list if we dequeue from the ready list, there will never + * be a situation where the req_free list is completely out of + * requests and cannot recover. + */ + to_queue->length = 0; + if (!list_empty(&video->req_ready)) { + to_queue = list_first_entry(&video->req_ready, + struct usb_request, list); + list_del(&to_queue->list); + list_add_tail(&req->list, &video->req_free); /* - * Here we check whether any request is available in the ready - * list. If it is, queue it to the ep and add the current - * usb_request to the req_free list - for video_pump to fill in. - * Otherwise, just use the current usb_request to queue a 0 - * length request to the ep. Since we always add to the req_free - * list if we dequeue from the ready list, there will never - * be a situation where the req_free list is completely out of - * requests and cannot recover. + * Queue work to the wq as well since it is possible that a + * buffer may not have been completely encoded with the set of + * in-flight usb requests for whih the complete callbacks are + * firing. + * In that case, if we do not queue work to the worker thread, + * the buffer will never be marked as complete - and therefore + * not be returned to userpsace. As a result, + * dequeue -> queue -> dequeue flow of uvc buffers will not + * happen. */ - struct usb_request *to_queue = req; - - to_queue->length = 0; - if (!list_empty(&video->req_ready)) { - to_queue = list_first_entry(&video->req_ready, - struct usb_request, list); - list_del(&to_queue->list); - list_add_tail(&req->list, &video->req_free); - /* - * Queue work to the wq as well since it is possible that a - * buffer may not have been completely encoded with the set of - * in-flight usb requests for whih the complete callbacks are - * firing. - * In that case, if we do not queue work to the worker thread, - * the buffer will never be marked as complete - and therefore - * not be returned to userpsace. As a result, - * dequeue -> queue -> dequeue flow of uvc buffers will not - * happen. - */ - queue_work(video->async_wq, &video->pump); - } + queue_work(video->async_wq, &video->pump); + } + /* + * Queue to the endpoint. The actual queueing to ep will + * only happen on one thread - the async_wq for bulk endpoints + * and this thread for isoc endpoints. + */ + ret = uvcg_video_usb_req_queue(video, to_queue, !is_bulk); + if (ret < 0) { /* - * Queue to the endpoint. The actual queueing to ep will - * only happen on one thread - the async_wq for bulk endpoints - * and this thread for isoc endpoints. + * Endpoint error, but the stream is still enabled. + * Put request back in req_free for it to be cleaned + * up later. */ - ret = uvcg_video_usb_req_queue(video, to_queue, !is_bulk); - if (ret < 0) { - /* - * Endpoint error, but the stream is still enabled. - * Put request back in req_free for it to be cleaned - * up later. - */ - list_add_tail(&to_queue->list, &video->req_free); - } - } else { - uvc_video_free_request(ureq, ep); - ret = 0; + list_add_tail(&to_queue->list, &video->req_free); } + spin_unlock_irqrestore(&video->req_lock, flags); - if (ret < 0) - uvcg_queue_cancel(queue, 0); } static int