From nobody Mon Feb 9 23:00:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35BCBC6FD1F for ; Wed, 22 Mar 2023 09:37:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230515AbjCVJg7 (ORCPT ); Wed, 22 Mar 2023 05:36:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230491AbjCVJg5 (ORCPT ); Wed, 22 Mar 2023 05:36:57 -0400 Received: from aposti.net (aposti.net [89.234.176.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80F7F5FA69; Wed, 22 Mar 2023 02:36:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1679476888; 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=CN+sVrd+5zFw4phF+tfY1VTRoiHERXU6QZdwnYlGtLk=; b=290ybhb/nQSzlWwiqepHlmfRl6bBQAeQpsu2kCX6juwdFufQnTL2q9cWMSt3BFfqDHY8C/ YBuHTnA/oFffaBiMc0xDnycFtNmmDF5gB1zoXuIyV3EXGi4mHcg5sJ335CVRlVNFYq5f7t ko18FMhNgLfOeOQTzPqtKDHEyqvOl1o= From: Paul Cercueil To: Greg Kroah-Hartman , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= Cc: michael.hennerich@analog.com, nuno.sa@analog.com, linux-usb@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 v2 2/3] usb: gadget: functionfs: Factorize wait-for-endpoint code Date: Wed, 22 Mar 2023 10:21:17 +0100 Message-Id: <20230322092118.9213-3-paul@crapouillou.net> In-Reply-To: <20230322092118.9213-1-paul@crapouillou.net> References: <20230322092118.9213-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/functi= on/f_fs.c index ddfc537c7526..8da64f0fdef0 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -947,31 +947,44 @@ static ssize_t __ffs_epfile_read_data(struct ffs_epfi= le *epfile, return ret; } =20 -static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_dat= a) +static struct ffs_ep *ffs_epfile_wait_ep(struct file *file) { struct ffs_epfile *epfile =3D file->private_data; - struct usb_request *req; struct ffs_ep *ep; - char *data =3D NULL; - ssize_t ret, data_len =3D -EINVAL; - int halt; - - /* Are we still active? */ - if (WARN_ON(epfile->ffs->state !=3D FFS_ACTIVE)) - return -ENODEV; + int ret; =20 /* Wait for endpoint to be enabled */ ep =3D epfile->ep; if (!ep) { if (file->f_flags & O_NONBLOCK) - return -EAGAIN; + return ERR_PTR(-EAGAIN); =20 ret =3D wait_event_interruptible( epfile->ffs->wait, (ep =3D epfile->ep)); if (ret) - return -EINTR; + return ERR_PTR(-EINTR); } =20 + return ep; +} + +static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_dat= a) +{ + struct ffs_epfile *epfile =3D file->private_data; + struct usb_request *req; + struct ffs_ep *ep; + char *data =3D NULL; + ssize_t ret, data_len =3D -EINVAL; + int halt; + + /* Are we still active? */ + if (WARN_ON(epfile->ffs->state !=3D FFS_ACTIVE)) + return -ENODEV; + + ep =3D ffs_epfile_wait_ep(file); + if (IS_ERR(ep)) + return PTR_ERR(ep); + /* Do we halt? */ halt =3D (!io_data->read =3D=3D !epfile->in); if (halt && epfile->isoc) @@ -1305,16 +1318,9 @@ static long ffs_epfile_ioctl(struct file *file, unsi= gned code, return -ENODEV; =20 /* Wait for endpoint to be enabled */ - ep =3D epfile->ep; - if (!ep) { - if (file->f_flags & O_NONBLOCK) - return -EAGAIN; - - ret =3D wait_event_interruptible( - epfile->ffs->wait, (ep =3D epfile->ep)); - if (ret) - return -EINTR; - } + ep =3D ffs_epfile_wait_ep(file); + if (IS_ERR(ep)) + return PTR_ERR(ep); =20 spin_lock_irq(&epfile->ffs->eps_lock); =20 --=20 2.39.2