From patchwork Fri Jan 19 14:14:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Cercueil X-Patchwork-Id: 189572 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp1036492dyb; Fri, 19 Jan 2024 06:16:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IEiMmuK6z9iG9+VB5GE1p64+nNzP68ROXaXIDvD0kK8RngQoRZH/42mGISwrZQdnIH3QAzf X-Received: by 2002:a05:620a:28cc:b0:783:53e2:f472 with SMTP id l12-20020a05620a28cc00b0078353e2f472mr1648617qkp.11.1705673788589; Fri, 19 Jan 2024 06:16:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705673788; cv=pass; d=google.com; s=arc-20160816; b=PoQjjfeXeAy3uTpp2uwDbWFhM4OWXUOyRqqdaHEwmFsA9BLmwuSXKXz60o4fsQP1Ar a0hP5CBiLvfDTPGND27c5JKxsfFztKeZtW6xyyh4Y6aeVb7Go1pum4Wrmhv/g+Dr7FK1 34xc/pVxhgQEPBwPb2UFZwok8kgG+ffkDBLAqVFBgw5h9I0fh6bhzeo12+MHyjVU3/b2 4omOFxaUoSEklIECIO85Qun+TD4mDqCSsxPoIpXKxMMCXO9g+TOWcHvm2DdwwoF1JE6g xr3nYokM9FV0zWT9gX/EqWvuprEmBNHu9rsSZfxsoTEsYPGHoKYXArSu0GwLpR8sTabc o9RQ== ARC-Message-Signature: i=2; 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=3Xwiw3h4BuSZxa4g5nlxoJvEg1Pn4zGp9h0k4mfsabo=; b=a+vbUUq1kVoFXrYgjyhjflgxKSk4cEldSLp5umToTngVBXYdmpa2yPtnJdfvY1Zxrw wVYs8tnAgKszd3e06ISWO82Tf8B4SbSmJyJbVzqo6dkvyAONVJGPcHofp8h3NfxtHMvM 9KoHk45vCH2De2EizCglQHXfGo31jmyBp68orM0v9u0c+UyO1T7rzmlET6wm60obbOfO tnQ6yMZT/VW53/9cI8NqeXpQF592lbLd2ZIgasn205sTgkiHJ5V0fCLzfzSBKV3e9d9p fVLjgKihHVlJuuQh/g4bo+BmBfi2auQI+0bGdKqlji+T3lBB7/BzhIPamSE1ccV+Fzj2 C8ug== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=Gt2xMOok; arc=pass (i=1 spf=pass spfdomain=crapouillou.net dkim=pass dkdomain=crapouillou.net dmarc=pass fromdomain=crapouillou.net); spf=pass (google.com: domain of linux-kernel+bounces-31251-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31251-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x19-20020a05620a099300b007835a915c1esi10714778qkx.309.2024.01.19.06.16.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 06:16:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31251-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=Gt2xMOok; arc=pass (i=1 spf=pass spfdomain=crapouillou.net dkim=pass dkdomain=crapouillou.net dmarc=pass fromdomain=crapouillou.net); spf=pass (google.com: domain of linux-kernel+bounces-31251-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31251-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 5D5841C20C2E for ; Fri, 19 Jan 2024 14:16:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 75A6F54FAB; Fri, 19 Jan 2024 14:14:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=crapouillou.net header.i=@crapouillou.net header.b="Gt2xMOok" 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 8027053E2F; Fri, 19 Jan 2024 14:14:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=89.234.176.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705673686; cv=none; b=B83061s2Z1lL93iMb02zGzujE0tVOmX4uqlaxUpGXD/yGZk+goS0wOf3GYZTCwA9uweGAMlFhEtpHjaBRa38x4jrk6GGaPlYKsGPHrUWqhrjrZch//2M8/STG8nym0aQx75wALEeBT7J3w9KFMCZ9ubt2ZcGm0nVdzuRMfonzpA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705673686; c=relaxed/simple; bh=ulEjlAZ2D8bQ3nhph/YUQbd+dlZj+pir5iq1If3tF7Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zts1r2xNlGjNnPaFm60209cbQstRdYQ/w2qf1FKTy/uIBGnExonr6DIcuaeUVSes8UYIgoNW2Ne5hGiDxOIksXRPCST8wJhIjXknvOICd1YLgfrkVmDJ7OBMquvwrRj+1QZWguJ+HUb6QYJ6tMcUR8sq8FtOTyWiwPDJTovdEh4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=crapouillou.net; spf=pass smtp.mailfrom=crapouillou.net; dkim=pass (1024-bit key) header.d=crapouillou.net header.i=@crapouillou.net header.b=Gt2xMOok; arc=none smtp.client-ip=89.234.176.197 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=1705673653; 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=Gt2xMOokNy++NJFR1tq2AUBcDdKRgJGiiz5FSZvayuQanfDZYEBEehUt+TLwRdtKYYMQX0 N+tcnAwYsDx961blLSEEEMkDtaedDVVXIhQ3h6d+0+HHoJaBgCZxoP1TkzfBHso6z1qKo7 EDDtwRL25WF5+PCGPOhNibxKGarkIyE= From: Paul Cercueil To: Greg Kroah-Hartman , Jonathan Corbet , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= Cc: Jonathan Cameron , =?utf-8?q?Nuno_S=C3=A1?= , Michael Hennerich , 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 v5 4/6] usb: gadget: functionfs: Factorize wait-for-endpoint code Date: Fri, 19 Jan 2024 15:14:00 +0100 Message-ID: <20240119141402.44262-5-paul@crapouillou.net> In-Reply-To: <20240119141402.44262-1-paul@crapouillou.net> References: <20240119141402.44262-1-paul@crapouillou.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam: Yes X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788528598706555046 X-GMAIL-MSGID: 1788528598706555046 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);