Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1577395rdb; Mon, 8 Jan 2024 04:02:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IFFm8xwFbJ1A0KmrfzXzpbkUCSBsTA8f5ZjNy1H+J2NSpwiEdAuGq8iApYqAL1DSTXzxVh/ X-Received: by 2002:aa7:da4f:0:b0:552:3044:1df9 with SMTP id w15-20020aa7da4f000000b0055230441df9mr2045396eds.67.1704715323094; Mon, 08 Jan 2024 04:02:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704715323; cv=none; d=google.com; s=arc-20160816; b=NO5iEys5gSAnScI2+lre/bC6D9RLpuuSjY7A72yPR4bs8EM3kPsWCGZt3rsQUL0N1j lJI/mRvq6q8iqpuJvXKALg7jT6+kCiW0owIju9i6FfOmWFLhtiVaDY3zhvvXHlm7Ex+j VvUmglWrYqEkENsciFhw1+633smUVIv8bqK71gdVGnOiZXt8atav7fycBxoVIQ6tNW8o V2PTdVm47YPhHAEXs+ND7BSQjOju8WXAVeDzyr5v5qiv9abu3dWQucyO9oFWxVOONGzl x/2IfJwS9zm27xzaNHbj1xrqKH9PTGlMcWyZbbQahKp0ebpbGs1YM5YxU8Ms/o00MOAj GfTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=PFENih9XWAd70944xbCOau+9oHw/D103WR9u3LQvnx8=; fh=uCl+pDf5A/h9/EhC2a7e6oA3XsaNDDsC5zMoVf40Kzc=; b=baoeQe+9fUas23k4fTcSTyeUUbv42EIALED4RiVvD++cZoe4vGvsU2SOQplY7Z3VKB hUN1gx00byU4hSSGCK3eMo7sN4HX/EJm5JFRr5Qjkm6XdcZRF+8CUEEMEnso+5+7bgyW DXbsVvt+aAiprlJQnLvzZd4ZZ6qDiGjkxScfkuEtCbWdt8q85q8BBDDi/veEIfGlFs0E paoed1tX9+t8gUVx/G7dfWvdpLPaPT3cu7SveJsn0XlNoBQ9CfVWLV965KO5c3F/7KiG G3yJp2rAMAcH1iThH/wEmS1ZvKWjZhIiJxJnjYCBTrlOnzeGoDMQ2Ai+q2jMQ5hnTJwg vc0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=QEsdJscw; spf=pass (google.com: domain of linux-kernel+bounces-19462-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19462-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id x22-20020a05640226d600b005574ba7e91bsi2403919edd.683.2024.01.08.04.02.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 04:02:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19462-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=QEsdJscw; spf=pass (google.com: domain of linux-kernel+bounces-19462-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19462-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net 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 D05751F2298E for ; Mon, 8 Jan 2024 12:02:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CDB6D29D03; Mon, 8 Jan 2024 12:01:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=crapouillou.net header.i=@crapouillou.net header.b="QEsdJscw" X-Original-To: linux-kernel@vger.kernel.org Received: from aposti.net (aposti.net [89.234.176.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 894982C688; Mon, 8 Jan 2024 12:01:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=crapouillou.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=crapouillou.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1704715264; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PFENih9XWAd70944xbCOau+9oHw/D103WR9u3LQvnx8=; b=QEsdJscwiJEspTAoEHRDNK7VnoGgpp0UGaBRfdN8yjy64rkHYjOZYbhcPEnI8nVS88oAIb lUCdoJ6bnksYqtGmP1DgMA+2SYnNjnqO8RVCclnVrpFxfZU3wLhxd+Ijyl27rmZApxI4Jl n0GqzBZqFruQrC9jLKU5sAfjRLjmBxo= From: Paul Cercueil To: Greg Kroah-Hartman , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , Jonathan Corbet Cc: Jonathan Cameron , =?UTF-8?q?Nuno=20S=C3=A1?= , Michael Hennerich , Andrzej Pietrasiewicz , linux-usb@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Paul Cercueil Subject: [PATCH v3 2/4] usb: gadget: functionfs: Factorize wait-for-endpoint code Date: Mon, 8 Jan 2024 13:00:54 +0100 Message-ID: <20240108120056.22165-3-paul@crapouillou.net> In-Reply-To: <20240108120056.22165-1-paul@crapouillou.net> References: <20240108120056.22165-1-paul@crapouillou.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam: Yes This exact same code was duplicated in two different places. Signed-off-by: Paul Cercueil --- drivers/usb/gadget/function/f_fs.c | 48 +++++++++++++++++------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index 6bff6cb93789..ed2a6d5fcef7 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -934,31 +934,44 @@ static ssize_t __ffs_epfile_read_data(struct ffs_epfile *epfile, return ret; } -static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data) +static struct ffs_ep *ffs_epfile_wait_ep(struct file *file) { struct ffs_epfile *epfile = file->private_data; - struct usb_request *req; struct ffs_ep *ep; - char *data = NULL; - ssize_t ret, data_len = -EINVAL; - int halt; - - /* Are we still active? */ - if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) - return -ENODEV; + int ret; /* Wait for endpoint to be enabled */ ep = epfile->ep; if (!ep) { if (file->f_flags & O_NONBLOCK) - return -EAGAIN; + return ERR_PTR(-EAGAIN); ret = wait_event_interruptible( epfile->ffs->wait, (ep = epfile->ep)); if (ret) - return -EINTR; + return ERR_PTR(-EINTR); } + return ep; +} + +static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data) +{ + struct ffs_epfile *epfile = file->private_data; + struct usb_request *req; + struct ffs_ep *ep; + char *data = NULL; + ssize_t ret, data_len = -EINVAL; + int halt; + + /* Are we still active? */ + if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) + return -ENODEV; + + ep = ffs_epfile_wait_ep(file); + if (IS_ERR(ep)) + return PTR_ERR(ep); + /* Do we halt? */ halt = (!io_data->read == !epfile->in); if (halt && epfile->isoc) @@ -1280,16 +1293,9 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code, return -ENODEV; /* Wait for endpoint to be enabled */ - ep = epfile->ep; - if (!ep) { - if (file->f_flags & O_NONBLOCK) - return -EAGAIN; - - ret = wait_event_interruptible( - epfile->ffs->wait, (ep = epfile->ep)); - if (ret) - return -EINTR; - } + ep = ffs_epfile_wait_ep(file); + if (IS_ERR(ep)) + return PTR_ERR(ep); spin_lock_irq(&epfile->ffs->eps_lock); -- 2.43.0