Skip to content

Commit 43766aa

Browse files
pcercueinunojsa
authored andcommitted
usb: gadget: functionfs: Factorize wait-for-endpoint code
This exact same code was duplicated in two different places. Signed-off-by: Paul Cercueil <paul@crapouillou.net> Link: https://lore.kernel.org/r/20240130122340.54813-3-paul@crapouillou.net Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1a3fc3e commit 43766aa

File tree

1 file changed

+27
-21
lines changed
  • drivers/usb/gadget/function

1 file changed

+27
-21
lines changed

drivers/usb/gadget/function/f_fs.c

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -934,31 +934,44 @@ static ssize_t __ffs_epfile_read_data(struct ffs_epfile *epfile,
934934
return ret;
935935
}
936936

937-
static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
937+
static struct ffs_ep *ffs_epfile_wait_ep(struct file *file)
938938
{
939939
struct ffs_epfile *epfile = file->private_data;
940-
struct usb_request *req;
941940
struct ffs_ep *ep;
942-
char *data = NULL;
943-
ssize_t ret, data_len = -EINVAL;
944-
int halt;
945-
946-
/* Are we still active? */
947-
if (WARN_ON(epfile->ffs->state != FFS_ACTIVE))
948-
return -ENODEV;
941+
int ret;
949942

950943
/* Wait for endpoint to be enabled */
951944
ep = epfile->ep;
952945
if (!ep) {
953946
if (file->f_flags & O_NONBLOCK)
954-
return -EAGAIN;
947+
return ERR_PTR(-EAGAIN);
955948

956949
ret = wait_event_interruptible(
957950
epfile->ffs->wait, (ep = epfile->ep));
958951
if (ret)
959-
return -EINTR;
952+
return ERR_PTR(-EINTR);
960953
}
961954

955+
return ep;
956+
}
957+
958+
static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
959+
{
960+
struct ffs_epfile *epfile = file->private_data;
961+
struct usb_request *req;
962+
struct ffs_ep *ep;
963+
char *data = NULL;
964+
ssize_t ret, data_len = -EINVAL;
965+
int halt;
966+
967+
/* Are we still active? */
968+
if (WARN_ON(epfile->ffs->state != FFS_ACTIVE))
969+
return -ENODEV;
970+
971+
ep = ffs_epfile_wait_ep(file);
972+
if (IS_ERR(ep))
973+
return PTR_ERR(ep);
974+
962975
/* Do we halt? */
963976
halt = (!io_data->read == !epfile->in);
964977
if (halt && epfile->isoc)
@@ -1280,16 +1293,9 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code,
12801293
return -ENODEV;
12811294

12821295
/* Wait for endpoint to be enabled */
1283-
ep = epfile->ep;
1284-
if (!ep) {
1285-
if (file->f_flags & O_NONBLOCK)
1286-
return -EAGAIN;
1287-
1288-
ret = wait_event_interruptible(
1289-
epfile->ffs->wait, (ep = epfile->ep));
1290-
if (ret)
1291-
return -EINTR;
1292-
}
1296+
ep = ffs_epfile_wait_ep(file);
1297+
if (IS_ERR(ep))
1298+
return PTR_ERR(ep);
12931299

12941300
spin_lock_irq(&epfile->ffs->eps_lock);
12951301

0 commit comments

Comments
 (0)