Received: by 2002:ac8:156:0:b0:3e0:cd10:60c8 with SMTP id f22csp1806586qtg; Wed, 22 Mar 2023 02:40:03 -0700 (PDT) X-Google-Smtp-Source: AK7set/SW55LbnZOiswsFyURYKLEtEMFRcrfHj/hRCH1HSyJs0fL33zvHnvjooAdoEUu/owhXN5G X-Received: by 2002:a17:906:e08c:b0:92f:17d:4438 with SMTP id gh12-20020a170906e08c00b0092f017d4438mr7236143ejb.47.1679478003616; Wed, 22 Mar 2023 02:40:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679478003; cv=none; d=google.com; s=arc-20160816; b=MVGR8l7IDMGyFd61AvHBLp/bZ/tA7WxmZcDUGzLr4xmY5FOOg3v9KXD5QF8fl3HlsP 2vQ/RLt4f+bJqOfREQYTaISkof5IPbUPCuA8uCH7VaefgELuyBykuutI9Bvka1cag7oU VoR7eYLzZizRrfZDA1aLPgfJ9qf9WTT3tMhT6AkULMUjqfbpNcqjEoZM3XjYvNYtt9gg j+emvZ8FZwgJdSBUgfFwJEeZfEgx6Pritl3Vnqlfdw2VWz4+qEXQwjC5++OVDa5atzz0 Knllsemb8ScBlVuZXvdP8bp4m3THIUU0rjSbHtSWrALWM9gHRLAGeXCnXzN9vtZhIV4Z sUPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CN+sVrd+5zFw4phF+tfY1VTRoiHERXU6QZdwnYlGtLk=; b=sRPAtlDfdhSrNRRqnT6RWOFCS8LzmuKh1wbegwwKbZpxKMp//gMW6jZfUDOB+LQiVI tBJPbTGfNZN2ocJtZgv4CIzkOAALTfXRCzKJtMY06FO6Qp9zTNu1m7+0Xp8HgVENLKyh YJjVeRY+Jh/q6GNhp8HxK/q6BAIWVyCa+8ght+dc6OipRbp30kfqYmjI9ghctc7tzQHe +f/0KmyBDC35hBzlpp1z/3bcfUI0QAC2hcza84X6MYJwE0+3h+cf4QGzTtX6YX1uDsuy cBQBVDHJvmLj64QD6rCFxJQ0CKaAPaTMUi9hMTshdq5dGOwOriF5PS9UdzR0FWCTDnz9 DEJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b="290ybhb/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id vx5-20020a170907a78500b00932bed49028si13139170ejc.809.2023.03.22.02.39.39; Wed, 22 Mar 2023 02:40:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b="290ybhb/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230461AbjCVJg6 (ORCPT + 99 others); Wed, 22 Mar 2023 05:36:58 -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: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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_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) @@ -1305,16 +1318,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.39.2