From patchwork Tue Jan 30 12:23:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Cercueil X-Patchwork-Id: 194069 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1181378dyb; Tue, 30 Jan 2024 04:24:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IElwekgIAaFBP4OVJr0zwi1XDH5aAj7OX+szwOcxO6QIrBzzr8FIIRauT16HRJt03xxEK6U X-Received: by 2002:a05:620a:14ad:b0:783:b1f6:bcbf with SMTP id x13-20020a05620a14ad00b00783b1f6bcbfmr7531452qkj.5.1706617497016; Tue, 30 Jan 2024 04:24:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706617497; cv=pass; d=google.com; s=arc-20160816; b=L2VKI9GEuuvD3Ci3twNzOgFquZEzC+aSTqlhxT/Anm0BfEVWFqVuswQ9wHJ55WoQDo v1jwWc2E9u3VAC5EDjVSM0l7yZD70JLnglphKcXe2RRbA7GP3kipmeknEERA0vhN8AN2 DrAQRIGGG6rM0Mbp8huIzCV77rALtN/HvxxsU+45aK362L7BkzZq1FtVbdb8PA+nx9ye rngtCGRDlCpJ52kRLGXYi+7NJ1KzvJg1vEVD7jDH7dfp2SIjy1USwaMHB/CzSSjWMPmh SBrZqp6De662YUeHQlEdrJ97XuthnsJoo6SCvi4d/WOvV3sGVeA6nyAvFJiUVShzzD/E 6owQ== 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=XWEviP/cSSSXmmQM4aKkBeUs1pfsU9NbxBdr/i8jS+4=; fh=rOwklx3n4HddILOil3p/QTffAKooJ/gOk0lSkLfkcvQ=; b=LvctYTUTDeUnAhmfdMqVHn1cz07JRF3bjGbTc52gSuhIZ96aA+kPtoebjLweHBpEdz mFJA5qOZvnWQBcqklPUG19jTLSDu3JLJZ0bzysUPpBOnHIFZzcN34SxKKM4XgIWKgxml MeHHodTK8D4sr9YXX40XNYPl7WAtzbZSDKFgjIrjt+hAg4kSCBQsZixfkOA9LCHFOjzp s8NNvKvOKao2MZr8Sr4PDh5aRfwpl2DBWXBANT/p245+ygkXdSLk/DQvpjN3+E8H8x1q rQzz3lmppjYLwA0bzAalV0FsLidD0utItVjMQpgKqx8waKvrfrKbD+8LSzrL+E9LDDEn OcTQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=jYqDNCvz; 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-44597-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44597-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f18-20020a05620a409200b00783344715eesi6936581qko.177.2024.01.30.04.24.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:24:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44597-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=jYqDNCvz; 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-44597-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44597-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 CB25F1C24060 for ; Tue, 30 Jan 2024 12:24:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 625336BB2D; Tue, 30 Jan 2024 12:24:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=crapouillou.net header.i=@crapouillou.net header.b="jYqDNCvz" 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 29E5A67E8D; Tue, 30 Jan 2024 12:24:06 +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=1706617448; cv=none; b=m0WH5dVq402u2AWg4P4EsV+Bg/NF+sPIHeSU7wRuy4h5qbQ/YhL4Jbj4e7n6hYgYHkRHyQKe9KBZo/acsPi8bvr72ywhZ0i+1ulvtptHIKY6RkerBC034erkyqB3++Btf+/99DPL+9IJ3s7XW8YLUE+CqNk4PRStDl+LRAcBiYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706617448; c=relaxed/simple; bh=BE8sRZ3slJO1R4SWqbcjAAfUIst/OdB5yuqfyw8rI18=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HhUs4zfORPgPDUOMardDNLK0nj9A7jCwSvNUs75sx35GBuzpt5vXWNEeyLjEL7wGLIELz1xmi562McCJXO49f8guPYBxcRcyTKqfb1hbpnNdV/L9gOAdWtCqumBkrn99WK2DX/pU+Yo2+7NTOc8cOYy1XSPYvS6DdlUO0Rf3k4M= 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=jYqDNCvz; 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=1706617429; 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=XWEviP/cSSSXmmQM4aKkBeUs1pfsU9NbxBdr/i8jS+4=; b=jYqDNCvz4OHuusyFV4JsYbmyK6jJ6zUaqU0yJW99Gh2/atzYrLcryXNMQW3pLADkJT1K0B Iq4V3FohKB4OYC1mtJy7RvBYG6+AFRSVH+RXw5ktmum/5Ip2Gnwcgx8khtE/OVPIDGHXAo +niRNnw9UPEzeGuf0yIiByri5iDzOd0= From: Paul Cercueil To: Greg Kroah-Hartman , Jonathan Corbet , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= Cc: =?utf-8?q?Nuno_S=C3=A1?= , Jonathan Cameron , 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 v6 2/4] usb: gadget: functionfs: Factorize wait-for-endpoint code Date: Tue, 30 Jan 2024 13:23:38 +0100 Message-ID: <20240130122340.54813-3-paul@crapouillou.net> In-Reply-To: <20240130122340.54813-1-paul@crapouillou.net> References: <20240130122340.54813-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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789518148344359287 X-GMAIL-MSGID: 1789518148344359287 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 be3851cffb73..491a1e0f4fa3 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);