Lines Matching +full:num +full:- +full:strings

1 // SPDX-License-Identifier: GPL-2.0+
3 * f_fs.c -- user mode file system API for USB composite function controllers
9 * Copyright (C) 2003-2004 David Brownell
57 /* Called with ffs->mutex held; take over ownership of data. */
91 cmpxchg(&ffs->setup_state, FFS_SETUP_CANCELLED, FFS_NO_SETUP); in ffs_setup_state_clear_cancelled()
111 static int ffs_func_revmap_ep(struct ffs_function *func, u8 num);
118 struct usb_ep *ep; /* P: ffs->eps_lock */
119 struct usb_request *req; /* P: epfile->mutex */
124 u8 num; member
128 /* Protects ep->ep and ep->req. */
132 struct ffs_ep *ep; /* P: ffs->eps_lock */
147 * can never run concurrently (they are synchronised by epfile->mutex)
157 * pointer is not-NULL (namely READ_BUFFER_DROP) it will instead free
192 #define READ_BUFFER_DROP ((struct ffs_buffer *)ERR_PTR(-ESHUTDOWN))
196 unsigned char in; /* P: ffs->eps_lock */
197 unsigned char isoc; /* P: ffs->eps_lock */
271 struct ffs_data *ffs = req->context; in ffs_ep0_complete()
273 complete(&ffs->ep0req_completion); in ffs_ep0_complete()
277 __releases(&ffs->ev.waitq.lock) in __ffs_ep0_queue_wait()
279 struct usb_request *req = ffs->ep0req; in __ffs_ep0_queue_wait()
283 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_queue_wait()
284 return -EINVAL; in __ffs_ep0_queue_wait()
287 req->zero = len < le16_to_cpu(ffs->ev.setup.wLength); in __ffs_ep0_queue_wait()
289 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_queue_wait()
291 req->buf = data; in __ffs_ep0_queue_wait()
292 req->length = len; in __ffs_ep0_queue_wait()
299 if (req->buf == NULL) in __ffs_ep0_queue_wait()
300 req->buf = (void *)0xDEADBABE; in __ffs_ep0_queue_wait()
302 reinit_completion(&ffs->ep0req_completion); in __ffs_ep0_queue_wait()
304 ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC); in __ffs_ep0_queue_wait()
308 ret = wait_for_completion_interruptible(&ffs->ep0req_completion); in __ffs_ep0_queue_wait()
310 usb_ep_dequeue(ffs->gadget->ep0, req); in __ffs_ep0_queue_wait()
311 return -EINTR; in __ffs_ep0_queue_wait()
314 ffs->setup_state = FFS_NO_SETUP; in __ffs_ep0_queue_wait()
315 return req->status ? req->status : req->actual; in __ffs_ep0_queue_wait()
320 if (ffs->ev.can_stall) { in __ffs_ep0_stall()
322 usb_ep_set_halt(ffs->gadget->ep0); in __ffs_ep0_stall()
323 ffs->setup_state = FFS_NO_SETUP; in __ffs_ep0_stall()
324 return -EL2HLT; in __ffs_ep0_stall()
327 return -ESRCH; in __ffs_ep0_stall()
334 struct ffs_data *ffs = file->private_data; in ffs_ep0_write()
340 return -EIDRM; in ffs_ep0_write()
343 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_write()
348 switch (ffs->state) { in ffs_ep0_write()
353 ret = -EINVAL; in ffs_ep0_write()
364 if (ffs->state == FFS_READ_DESCRIPTORS) { in ffs_ep0_write()
370 ffs->state = FFS_READ_STRINGS; in ffs_ep0_write()
373 pr_info("read strings\n"); in ffs_ep0_write()
380 ffs->state = FFS_CLOSING; in ffs_ep0_write()
384 ffs->state = FFS_ACTIVE; in ffs_ep0_write()
385 mutex_unlock(&ffs->mutex); in ffs_ep0_write()
389 ffs->state = FFS_CLOSING; in ffs_ep0_write()
403 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
406 ret = -EIDRM; in ffs_ep0_write()
410 ret = -ESRCH; in ffs_ep0_write()
418 if (!(ffs->ev.setup.bRequestType & USB_DIR_IN)) { in ffs_ep0_write()
419 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
425 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); in ffs_ep0_write()
427 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
435 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
445 * the only place FFS_SETUP_PENDING -> FFS_NO_SETUP in ffs_ep0_write()
451 ret = -EIDRM; in ffs_ep0_write()
453 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
462 ret = -EBADFD; in ffs_ep0_write()
466 mutex_unlock(&ffs->mutex); in ffs_ep0_write()
470 /* Called with ffs->ev.waitq.lock and ffs->mutex held, both released on exit. */
473 __releases(&ffs->ev.waitq.lock) in __ffs_ep0_read_events()
476 * n cannot be bigger than ffs->ev.count, which cannot be bigger than in __ffs_ep0_read_events()
477 * size of ffs->ev.types array (which is four) so that's how much space in __ffs_ep0_read_events()
480 struct usb_functionfs_event events[ARRAY_SIZE(ffs->ev.types)]; in __ffs_ep0_read_events()
487 events[i].type = ffs->ev.types[i]; in __ffs_ep0_read_events()
489 events[i].u.setup = ffs->ev.setup; in __ffs_ep0_read_events()
490 ffs->setup_state = FFS_SETUP_PENDING; in __ffs_ep0_read_events()
494 ffs->ev.count -= n; in __ffs_ep0_read_events()
495 if (ffs->ev.count) in __ffs_ep0_read_events()
496 memmove(ffs->ev.types, ffs->ev.types + n, in __ffs_ep0_read_events()
497 ffs->ev.count * sizeof *ffs->ev.types); in __ffs_ep0_read_events()
499 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_read_events()
500 mutex_unlock(&ffs->mutex); in __ffs_ep0_read_events()
502 return copy_to_user(buf, events, size) ? -EFAULT : size; in __ffs_ep0_read_events()
508 struct ffs_data *ffs = file->private_data; in ffs_ep0_read()
515 return -EIDRM; in ffs_ep0_read()
518 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_read()
523 if (ffs->state != FFS_ACTIVE) { in ffs_ep0_read()
524 ret = -EBADFD; in ffs_ep0_read()
532 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
536 ret = -EIDRM; in ffs_ep0_read()
542 ret = -EINVAL; in ffs_ep0_read()
546 if ((file->f_flags & O_NONBLOCK) && !ffs->ev.count) { in ffs_ep0_read()
547 ret = -EAGAIN; in ffs_ep0_read()
551 if (wait_event_interruptible_exclusive_locked_irq(ffs->ev.waitq, in ffs_ep0_read()
552 ffs->ev.count)) { in ffs_ep0_read()
553 ret = -EINTR; in ffs_ep0_read()
559 min(n, (size_t)ffs->ev.count)); in ffs_ep0_read()
562 if (ffs->ev.setup.bRequestType & USB_DIR_IN) { in ffs_ep0_read()
563 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
568 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); in ffs_ep0_read()
570 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
575 ret = -ENOMEM; in ffs_ep0_read()
580 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
585 ret = -EIDRM; in ffs_ep0_read()
592 ret = -EFAULT; in ffs_ep0_read()
596 ret = -EBADFD; in ffs_ep0_read()
600 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
602 mutex_unlock(&ffs->mutex); in ffs_ep0_read()
609 struct ffs_data *ffs = inode->i_private; in ffs_ep0_open()
611 if (ffs->state == FFS_CLOSING) in ffs_ep0_open()
612 return -EBUSY; in ffs_ep0_open()
614 file->private_data = ffs; in ffs_ep0_open()
622 struct ffs_data *ffs = file->private_data; in ffs_ep0_release()
631 struct ffs_data *ffs = file->private_data; in ffs_ep0_ioctl()
632 struct usb_gadget *gadget = ffs->gadget; in ffs_ep0_ioctl()
636 struct ffs_function *func = ffs->func; in ffs_ep0_ioctl()
637 ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV; in ffs_ep0_ioctl()
638 } else if (gadget && gadget->ops->ioctl) { in ffs_ep0_ioctl()
639 ret = gadget->ops->ioctl(gadget, code, value); in ffs_ep0_ioctl()
641 ret = -ENOTTY; in ffs_ep0_ioctl()
649 struct ffs_data *ffs = file->private_data; in ffs_ep0_poll()
653 poll_wait(file, &ffs->ev.waitq, wait); in ffs_ep0_poll()
655 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_poll()
659 switch (ffs->state) { in ffs_ep0_poll()
666 switch (ffs->setup_state) { in ffs_ep0_poll()
668 if (ffs->ev.count) in ffs_ep0_poll()
685 mutex_unlock(&ffs->mutex); in ffs_ep0_poll()
706 struct ffs_io_data *io_data = req->context; in ffs_epfile_io_complete()
708 if (req->status) in ffs_epfile_io_complete()
709 io_data->status = req->status; in ffs_epfile_io_complete()
711 io_data->status = req->actual; in ffs_epfile_io_complete()
713 complete(&io_data->done); in ffs_epfile_io_complete()
723 return -EFAULT; in ffs_copy_to_iter()
761 * @sg_table - pointer to a place to be filled with sg_table contents
762 * @size - required buffer size
799 if (io_data->use_sg) in ffs_alloc_buffer()
800 return ffs_build_sg_list(&io_data->sgt, data_len); in ffs_alloc_buffer()
807 if (!io_data->buf) in ffs_free_buffer()
810 if (io_data->use_sg) { in ffs_free_buffer()
811 sg_free_table(&io_data->sgt); in ffs_free_buffer()
812 vfree(io_data->buf); in ffs_free_buffer()
814 kfree(io_data->buf); in ffs_free_buffer()
822 int ret = io_data->status; in ffs_user_copy_worker()
823 bool kiocb_has_eventfd = io_data->kiocb->ki_flags & IOCB_EVENTFD; in ffs_user_copy_worker()
825 if (io_data->read && ret > 0) { in ffs_user_copy_worker()
826 kthread_use_mm(io_data->mm); in ffs_user_copy_worker()
827 ret = ffs_copy_to_iter(io_data->buf, ret, &io_data->data); in ffs_user_copy_worker()
828 kthread_unuse_mm(io_data->mm); in ffs_user_copy_worker()
831 io_data->kiocb->ki_complete(io_data->kiocb, ret); in ffs_user_copy_worker()
833 if (io_data->ffs->ffs_eventfd && !kiocb_has_eventfd) in ffs_user_copy_worker()
834 eventfd_signal(io_data->ffs->ffs_eventfd); in ffs_user_copy_worker()
836 if (io_data->read) in ffs_user_copy_worker()
837 kfree(io_data->to_free); in ffs_user_copy_worker()
845 struct ffs_io_data *io_data = req->context; in ffs_epfile_async_io_complete()
846 struct ffs_data *ffs = io_data->ffs; in ffs_epfile_async_io_complete()
848 io_data->status = req->status ? req->status : req->actual; in ffs_epfile_async_io_complete()
851 INIT_WORK(&io_data->work, ffs_user_copy_worker); in ffs_epfile_async_io_complete()
852 queue_work(ffs->io_completion_wq, &io_data->work); in ffs_epfile_async_io_complete()
861 struct ffs_buffer *buf = xchg(&epfile->read_buffer, READ_BUFFER_DROP); in __ffs_epfile_read_buffer_free()
866 /* Assumes epfile->mutex is held. */
871 * Null out epfile->read_buffer so ffs_func_eps_disable does not free in __ffs_epfile_read_buffered()
875 struct ffs_buffer *buf = xchg(&epfile->read_buffer, NULL); in __ffs_epfile_read_buffered()
880 ret = copy_to_iter(buf->data, buf->length, iter); in __ffs_epfile_read_buffered()
881 if (buf->length == ret) { in __ffs_epfile_read_buffered()
887 ret = -EFAULT; in __ffs_epfile_read_buffered()
889 buf->length -= ret; in __ffs_epfile_read_buffered()
890 buf->data += ret; in __ffs_epfile_read_buffered()
893 if (cmpxchg(&epfile->read_buffer, NULL, buf)) in __ffs_epfile_read_buffered()
899 /* Assumes epfile->mutex is held. */
911 return -EFAULT; in __ffs_epfile_read_data()
917 data_len -= ret; in __ffs_epfile_read_data()
920 return -ENOMEM; in __ffs_epfile_read_data()
921 buf->length = data_len; in __ffs_epfile_read_data()
922 buf->data = buf->storage; in __ffs_epfile_read_data()
923 memcpy(buf->storage, data + ret, flex_array_size(buf, storage, data_len)); in __ffs_epfile_read_data()
931 if (cmpxchg(&epfile->read_buffer, NULL, buf)) in __ffs_epfile_read_data()
939 struct ffs_epfile *epfile = file->private_data; in ffs_epfile_io()
943 ssize_t ret, data_len = -EINVAL; in ffs_epfile_io()
947 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_io()
948 return -ENODEV; in ffs_epfile_io()
951 ep = epfile->ep; in ffs_epfile_io()
953 if (file->f_flags & O_NONBLOCK) in ffs_epfile_io()
954 return -EAGAIN; in ffs_epfile_io()
957 epfile->ffs->wait, (ep = epfile->ep)); in ffs_epfile_io()
959 return -EINTR; in ffs_epfile_io()
963 halt = (!io_data->read == !epfile->in); in ffs_epfile_io()
964 if (halt && epfile->isoc) in ffs_epfile_io()
965 return -EINVAL; in ffs_epfile_io()
968 ret = ffs_mutex_lock(&epfile->mutex, file->f_flags & O_NONBLOCK); in ffs_epfile_io()
983 if (!io_data->aio && io_data->read) { in ffs_epfile_io()
984 ret = __ffs_epfile_read_buffered(epfile, &io_data->data); in ffs_epfile_io()
990 * if we _do_ wait above, the epfile->ffs->gadget might be NULL in ffs_epfile_io()
994 gadget = epfile->ffs->gadget; in ffs_epfile_io()
996 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
998 if (epfile->ep != ep) { in ffs_epfile_io()
999 ret = -ESHUTDOWN; in ffs_epfile_io()
1002 data_len = iov_iter_count(&io_data->data); in ffs_epfile_io()
1007 if (io_data->read) in ffs_epfile_io()
1008 data_len = usb_ep_align_maybe(gadget, ep->ep, data_len); in ffs_epfile_io()
1010 io_data->use_sg = gadget->sg_supported && data_len > PAGE_SIZE; in ffs_epfile_io()
1011 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1015 ret = -ENOMEM; in ffs_epfile_io()
1018 if (!io_data->read && in ffs_epfile_io()
1019 !copy_from_iter_full(data, data_len, &io_data->data)) { in ffs_epfile_io()
1020 ret = -EFAULT; in ffs_epfile_io()
1025 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1027 if (epfile->ep != ep) { in ffs_epfile_io()
1029 ret = -ESHUTDOWN; in ffs_epfile_io()
1031 ret = usb_ep_set_halt(ep->ep); in ffs_epfile_io()
1033 ret = -EBADMSG; in ffs_epfile_io()
1034 } else if (data_len == -EINVAL) { in ffs_epfile_io()
1040 * being initialized to -EINVAL during its declaration, which in ffs_epfile_io()
1046 WARN(1, "%s: data_len == -EINVAL\n", __func__); in ffs_epfile_io()
1047 ret = -EINVAL; in ffs_epfile_io()
1048 } else if (!io_data->aio) { in ffs_epfile_io()
1051 req = ep->req; in ffs_epfile_io()
1052 if (io_data->use_sg) { in ffs_epfile_io()
1053 req->buf = NULL; in ffs_epfile_io()
1054 req->sg = io_data->sgt.sgl; in ffs_epfile_io()
1055 req->num_sgs = io_data->sgt.nents; in ffs_epfile_io()
1057 req->buf = data; in ffs_epfile_io()
1058 req->num_sgs = 0; in ffs_epfile_io()
1060 req->length = data_len; in ffs_epfile_io()
1062 io_data->buf = data; in ffs_epfile_io()
1064 init_completion(&io_data->done); in ffs_epfile_io()
1065 req->context = io_data; in ffs_epfile_io()
1066 req->complete = ffs_epfile_io_complete; in ffs_epfile_io()
1068 ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC); in ffs_epfile_io()
1072 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1074 if (wait_for_completion_interruptible(&io_data->done)) { in ffs_epfile_io()
1075 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1076 if (epfile->ep != ep) { in ffs_epfile_io()
1077 ret = -ESHUTDOWN; in ffs_epfile_io()
1084 * condition with req->complete callback. in ffs_epfile_io()
1086 usb_ep_dequeue(ep->ep, req); in ffs_epfile_io()
1087 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1088 wait_for_completion(&io_data->done); in ffs_epfile_io()
1089 interrupted = io_data->status < 0; in ffs_epfile_io()
1093 ret = -EINTR; in ffs_epfile_io()
1094 else if (io_data->read && io_data->status > 0) in ffs_epfile_io()
1095 ret = __ffs_epfile_read_data(epfile, data, io_data->status, in ffs_epfile_io()
1096 &io_data->data); in ffs_epfile_io()
1098 ret = io_data->status; in ffs_epfile_io()
1100 } else if (!(req = usb_ep_alloc_request(ep->ep, GFP_ATOMIC))) { in ffs_epfile_io()
1101 ret = -ENOMEM; in ffs_epfile_io()
1103 if (io_data->use_sg) { in ffs_epfile_io()
1104 req->buf = NULL; in ffs_epfile_io()
1105 req->sg = io_data->sgt.sgl; in ffs_epfile_io()
1106 req->num_sgs = io_data->sgt.nents; in ffs_epfile_io()
1108 req->buf = data; in ffs_epfile_io()
1109 req->num_sgs = 0; in ffs_epfile_io()
1111 req->length = data_len; in ffs_epfile_io()
1113 io_data->buf = data; in ffs_epfile_io()
1114 io_data->ep = ep->ep; in ffs_epfile_io()
1115 io_data->req = req; in ffs_epfile_io()
1116 io_data->ffs = epfile->ffs; in ffs_epfile_io()
1118 req->context = io_data; in ffs_epfile_io()
1119 req->complete = ffs_epfile_async_io_complete; in ffs_epfile_io()
1121 ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC); in ffs_epfile_io()
1123 io_data->req = NULL; in ffs_epfile_io()
1124 usb_ep_free_request(ep->ep, req); in ffs_epfile_io()
1128 ret = -EIOCBQUEUED; in ffs_epfile_io()
1137 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1139 mutex_unlock(&epfile->mutex); in ffs_epfile_io()
1141 if (ret != -EIOCBQUEUED) /* don't free if there is iocb queued */ in ffs_epfile_io()
1149 struct ffs_epfile *epfile = inode->i_private; in ffs_epfile_open()
1151 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_open()
1152 return -ENODEV; in ffs_epfile_open()
1154 file->private_data = epfile; in ffs_epfile_open()
1155 ffs_data_opened(epfile->ffs); in ffs_epfile_open()
1162 struct ffs_io_data *io_data = kiocb->private; in ffs_aio_cancel()
1163 struct ffs_epfile *epfile = kiocb->ki_filp->private_data; in ffs_aio_cancel()
1167 spin_lock_irqsave(&epfile->ffs->eps_lock, flags); in ffs_aio_cancel()
1169 if (io_data && io_data->ep && io_data->req) in ffs_aio_cancel()
1170 value = usb_ep_dequeue(io_data->ep, io_data->req); in ffs_aio_cancel()
1172 value = -EINVAL; in ffs_aio_cancel()
1174 spin_unlock_irqrestore(&epfile->ffs->eps_lock, flags); in ffs_aio_cancel()
1187 return -ENOMEM; in ffs_epfile_write_iter()
1188 p->aio = true; in ffs_epfile_write_iter()
1191 p->aio = false; in ffs_epfile_write_iter()
1194 p->read = false; in ffs_epfile_write_iter()
1195 p->kiocb = kiocb; in ffs_epfile_write_iter()
1196 p->data = *from; in ffs_epfile_write_iter()
1197 p->mm = current->mm; in ffs_epfile_write_iter()
1199 kiocb->private = p; in ffs_epfile_write_iter()
1201 if (p->aio) in ffs_epfile_write_iter()
1204 res = ffs_epfile_io(kiocb->ki_filp, p); in ffs_epfile_write_iter()
1205 if (res == -EIOCBQUEUED) in ffs_epfile_write_iter()
1207 if (p->aio) in ffs_epfile_write_iter()
1210 *from = p->data; in ffs_epfile_write_iter()
1222 return -ENOMEM; in ffs_epfile_read_iter()
1223 p->aio = true; in ffs_epfile_read_iter()
1226 p->aio = false; in ffs_epfile_read_iter()
1229 p->read = true; in ffs_epfile_read_iter()
1230 p->kiocb = kiocb; in ffs_epfile_read_iter()
1231 if (p->aio) { in ffs_epfile_read_iter()
1232 p->to_free = dup_iter(&p->data, to, GFP_KERNEL); in ffs_epfile_read_iter()
1233 if (!iter_is_ubuf(&p->data) && !p->to_free) { in ffs_epfile_read_iter()
1235 return -ENOMEM; in ffs_epfile_read_iter()
1238 p->data = *to; in ffs_epfile_read_iter()
1239 p->to_free = NULL; in ffs_epfile_read_iter()
1241 p->mm = current->mm; in ffs_epfile_read_iter()
1243 kiocb->private = p; in ffs_epfile_read_iter()
1245 if (p->aio) in ffs_epfile_read_iter()
1248 res = ffs_epfile_io(kiocb->ki_filp, p); in ffs_epfile_read_iter()
1249 if (res == -EIOCBQUEUED) in ffs_epfile_read_iter()
1252 if (p->aio) { in ffs_epfile_read_iter()
1253 kfree(p->to_free); in ffs_epfile_read_iter()
1256 *to = p->data; in ffs_epfile_read_iter()
1264 struct ffs_epfile *epfile = inode->i_private; in ffs_epfile_release()
1267 ffs_data_closed(epfile->ffs); in ffs_epfile_release()
1275 struct ffs_epfile *epfile = file->private_data; in ffs_epfile_ioctl()
1279 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_ioctl()
1280 return -ENODEV; in ffs_epfile_ioctl()
1283 ep = epfile->ep; in ffs_epfile_ioctl()
1285 if (file->f_flags & O_NONBLOCK) in ffs_epfile_ioctl()
1286 return -EAGAIN; in ffs_epfile_ioctl()
1289 epfile->ffs->wait, (ep = epfile->ep)); in ffs_epfile_ioctl()
1291 return -EINTR; in ffs_epfile_ioctl()
1294 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1297 if (epfile->ep != ep) { in ffs_epfile_ioctl()
1298 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1299 return -ESHUTDOWN; in ffs_epfile_ioctl()
1304 ret = usb_ep_fifo_status(epfile->ep->ep); in ffs_epfile_ioctl()
1307 usb_ep_fifo_flush(epfile->ep->ep); in ffs_epfile_ioctl()
1311 ret = usb_ep_clear_halt(epfile->ep->ep); in ffs_epfile_ioctl()
1314 ret = epfile->ep->num; in ffs_epfile_ioctl()
1321 switch (epfile->ffs->gadget->speed) { in ffs_epfile_ioctl()
1333 desc = epfile->ep->descs[desc_idx]; in ffs_epfile_ioctl()
1334 memcpy(&desc1, desc, desc->bLength); in ffs_epfile_ioctl()
1336 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1339 ret = -EFAULT; in ffs_epfile_ioctl()
1343 ret = -ENOTTY; in ffs_epfile_ioctl()
1345 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1382 inode->i_ino = get_next_ino(); in ffs_sb_make_inode()
1383 inode->i_mode = perms->mode; in ffs_sb_make_inode()
1384 inode->i_uid = perms->uid; in ffs_sb_make_inode()
1385 inode->i_gid = perms->gid; in ffs_sb_make_inode()
1388 inode->i_private = data; in ffs_sb_make_inode()
1390 inode->i_fop = fops; in ffs_sb_make_inode()
1392 inode->i_op = iops; in ffs_sb_make_inode()
1403 struct ffs_data *ffs = sb->s_fs_info; in ffs_sb_create_file()
1407 dentry = d_alloc_name(sb->s_root, name); in ffs_sb_create_file()
1411 inode = ffs_sb_make_inode(sb, data, fops, NULL, &ffs->file_perms); in ffs_sb_create_file()
1437 struct ffs_sb_fill_data *data = fc->fs_private; in ffs_sb_fill()
1439 struct ffs_data *ffs = data->ffs_data; in ffs_sb_fill()
1441 ffs->sb = sb; in ffs_sb_fill()
1442 data->ffs_data = NULL; in ffs_sb_fill()
1443 sb->s_fs_info = ffs; in ffs_sb_fill()
1444 sb->s_blocksize = PAGE_SIZE; in ffs_sb_fill()
1445 sb->s_blocksize_bits = PAGE_SHIFT; in ffs_sb_fill()
1446 sb->s_magic = FUNCTIONFS_MAGIC; in ffs_sb_fill()
1447 sb->s_op = &ffs_sb_operations; in ffs_sb_fill()
1448 sb->s_time_gran = 1; in ffs_sb_fill()
1451 data->perms.mode = data->root_mode; in ffs_sb_fill()
1455 &data->perms); in ffs_sb_fill()
1456 sb->s_root = d_make_root(inode); in ffs_sb_fill()
1457 if (!sb->s_root) in ffs_sb_fill()
1458 return -ENOMEM; in ffs_sb_fill()
1462 return -ENOMEM; in ffs_sb_fill()
1488 struct ffs_sb_fill_data *data = fc->fs_private; in ffs_fs_parse_param()
1498 data->no_disconnect = result.boolean; in ffs_fs_parse_param()
1501 data->root_mode = (result.uint_32 & 0555) | S_IFDIR; in ffs_fs_parse_param()
1504 data->perms.mode = (result.uint_32 & 0666) | S_IFREG; in ffs_fs_parse_param()
1507 data->root_mode = (result.uint_32 & 0555) | S_IFDIR; in ffs_fs_parse_param()
1508 data->perms.mode = (result.uint_32 & 0666) | S_IFREG; in ffs_fs_parse_param()
1512 data->perms.uid = make_kuid(current_user_ns(), result.uint_32); in ffs_fs_parse_param()
1513 if (!uid_valid(data->perms.uid)) in ffs_fs_parse_param()
1517 data->perms.gid = make_kgid(current_user_ns(), result.uint_32); in ffs_fs_parse_param()
1518 if (!gid_valid(data->perms.gid)) in ffs_fs_parse_param()
1523 return -ENOPARAM; in ffs_fs_parse_param()
1529 return invalf(fc, "%s: unmapped value: %u", param->key, result.uint_32); in ffs_fs_parse_param()
1537 struct ffs_sb_fill_data *ctx = fc->fs_private; in ffs_fs_get_tree()
1541 if (!fc->source) in ffs_fs_get_tree()
1544 ffs = ffs_data_new(fc->source); in ffs_fs_get_tree()
1546 return -ENOMEM; in ffs_fs_get_tree()
1547 ffs->file_perms = ctx->perms; in ffs_fs_get_tree()
1548 ffs->no_disconnect = ctx->no_disconnect; in ffs_fs_get_tree()
1550 ffs->dev_name = kstrdup(fc->source, GFP_KERNEL); in ffs_fs_get_tree()
1551 if (!ffs->dev_name) { in ffs_fs_get_tree()
1553 return -ENOMEM; in ffs_fs_get_tree()
1556 ret = ffs_acquire_dev(ffs->dev_name, ffs); in ffs_fs_get_tree()
1562 ctx->ffs_data = ffs; in ffs_fs_get_tree()
1568 struct ffs_sb_fill_data *ctx = fc->fs_private; in ffs_fs_free_fc()
1571 if (ctx->ffs_data) { in ffs_fs_free_fc()
1572 ffs_data_put(ctx->ffs_data); in ffs_fs_free_fc()
1591 return -ENOMEM; in ffs_fs_init_fs_context()
1593 ctx->perms.mode = S_IFREG | 0600; in ffs_fs_init_fs_context()
1594 ctx->perms.uid = GLOBAL_ROOT_UID; in ffs_fs_init_fs_context()
1595 ctx->perms.gid = GLOBAL_ROOT_GID; in ffs_fs_init_fs_context()
1596 ctx->root_mode = S_IFDIR | 0500; in ffs_fs_init_fs_context()
1597 ctx->no_disconnect = false; in ffs_fs_init_fs_context()
1599 fc->fs_private = ctx; in ffs_fs_init_fs_context()
1600 fc->ops = &ffs_fs_context_ops; in ffs_fs_init_fs_context()
1608 if (sb->s_fs_info) in ffs_fs_kill_sb()
1609 ffs_data_closed(sb->s_fs_info); in ffs_fs_kill_sb()
1651 refcount_inc(&ffs->ref); in ffs_data_get()
1656 refcount_inc(&ffs->ref); in ffs_data_opened()
1657 if (atomic_add_return(1, &ffs->opened) == 1 && in ffs_data_opened()
1658 ffs->state == FFS_DEACTIVATED) { in ffs_data_opened()
1659 ffs->state = FFS_CLOSING; in ffs_data_opened()
1666 if (refcount_dec_and_test(&ffs->ref)) { in ffs_data_put()
1669 ffs_release_dev(ffs->private_data); in ffs_data_put()
1670 BUG_ON(waitqueue_active(&ffs->ev.waitq) || in ffs_data_put()
1671 swait_active(&ffs->ep0req_completion.wait) || in ffs_data_put()
1672 waitqueue_active(&ffs->wait)); in ffs_data_put()
1673 destroy_workqueue(ffs->io_completion_wq); in ffs_data_put()
1674 kfree(ffs->dev_name); in ffs_data_put()
1684 if (atomic_dec_and_test(&ffs->opened)) { in ffs_data_closed()
1685 if (ffs->no_disconnect) { in ffs_data_closed()
1686 ffs->state = FFS_DEACTIVATED; in ffs_data_closed()
1687 spin_lock_irqsave(&ffs->eps_lock, flags); in ffs_data_closed()
1688 epfiles = ffs->epfiles; in ffs_data_closed()
1689 ffs->epfiles = NULL; in ffs_data_closed()
1690 spin_unlock_irqrestore(&ffs->eps_lock, in ffs_data_closed()
1695 ffs->eps_count); in ffs_data_closed()
1697 if (ffs->setup_state == FFS_SETUP_PENDING) in ffs_data_closed()
1700 ffs->state = FFS_CLOSING; in ffs_data_closed()
1704 if (atomic_read(&ffs->opened) < 0) { in ffs_data_closed()
1705 ffs->state = FFS_CLOSING; in ffs_data_closed()
1718 ffs->io_completion_wq = alloc_ordered_workqueue("%s", 0, dev_name); in ffs_data_new()
1719 if (!ffs->io_completion_wq) { in ffs_data_new()
1724 refcount_set(&ffs->ref, 1); in ffs_data_new()
1725 atomic_set(&ffs->opened, 0); in ffs_data_new()
1726 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_new()
1727 mutex_init(&ffs->mutex); in ffs_data_new()
1728 spin_lock_init(&ffs->eps_lock); in ffs_data_new()
1729 init_waitqueue_head(&ffs->ev.waitq); in ffs_data_new()
1730 init_waitqueue_head(&ffs->wait); in ffs_data_new()
1731 init_completion(&ffs->ep0req_completion); in ffs_data_new()
1734 ffs->ev.can_stall = 1; in ffs_data_new()
1746 BUG_ON(ffs->gadget); in ffs_data_clear()
1748 spin_lock_irqsave(&ffs->eps_lock, flags); in ffs_data_clear()
1749 epfiles = ffs->epfiles; in ffs_data_clear()
1750 ffs->epfiles = NULL; in ffs_data_clear()
1751 spin_unlock_irqrestore(&ffs->eps_lock, flags); in ffs_data_clear()
1756 * copy of epfile will save us from use-after-free. in ffs_data_clear()
1759 ffs_epfiles_destroy(epfiles, ffs->eps_count); in ffs_data_clear()
1760 ffs->epfiles = NULL; in ffs_data_clear()
1763 if (ffs->ffs_eventfd) { in ffs_data_clear()
1764 eventfd_ctx_put(ffs->ffs_eventfd); in ffs_data_clear()
1765 ffs->ffs_eventfd = NULL; in ffs_data_clear()
1768 kfree(ffs->raw_descs_data); in ffs_data_clear()
1769 kfree(ffs->raw_strings); in ffs_data_clear()
1770 kfree(ffs->stringtabs); in ffs_data_clear()
1777 ffs->raw_descs_data = NULL; in ffs_data_reset()
1778 ffs->raw_descs = NULL; in ffs_data_reset()
1779 ffs->raw_strings = NULL; in ffs_data_reset()
1780 ffs->stringtabs = NULL; in ffs_data_reset()
1782 ffs->raw_descs_length = 0; in ffs_data_reset()
1783 ffs->fs_descs_count = 0; in ffs_data_reset()
1784 ffs->hs_descs_count = 0; in ffs_data_reset()
1785 ffs->ss_descs_count = 0; in ffs_data_reset()
1787 ffs->strings_count = 0; in ffs_data_reset()
1788 ffs->interfaces_count = 0; in ffs_data_reset()
1789 ffs->eps_count = 0; in ffs_data_reset()
1791 ffs->ev.count = 0; in ffs_data_reset()
1793 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_reset()
1794 ffs->setup_state = FFS_NO_SETUP; in ffs_data_reset()
1795 ffs->flags = 0; in ffs_data_reset()
1797 ffs->ms_os_descs_ext_prop_count = 0; in ffs_data_reset()
1798 ffs->ms_os_descs_ext_prop_name_len = 0; in ffs_data_reset()
1799 ffs->ms_os_descs_ext_prop_data_len = 0; in ffs_data_reset()
1808 if (WARN_ON(ffs->state != FFS_ACTIVE in functionfs_bind()
1809 || test_and_set_bit(FFS_FL_BOUND, &ffs->flags))) in functionfs_bind()
1810 return -EBADFD; in functionfs_bind()
1812 first_id = usb_string_ids_n(cdev, ffs->strings_count); in functionfs_bind()
1816 ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL); in functionfs_bind()
1817 if (!ffs->ep0req) in functionfs_bind()
1818 return -ENOMEM; in functionfs_bind()
1819 ffs->ep0req->complete = ffs_ep0_complete; in functionfs_bind()
1820 ffs->ep0req->context = ffs; in functionfs_bind()
1822 lang = ffs->stringtabs; in functionfs_bind()
1825 struct usb_string *str = (*lang)->strings; in functionfs_bind()
1827 for (; str->s; ++id, ++str) in functionfs_bind()
1828 str->id = id; in functionfs_bind()
1832 ffs->gadget = cdev->gadget; in functionfs_bind()
1839 if (!WARN_ON(!ffs->gadget)) { in functionfs_unbind()
1841 usb_ep_dequeue(ffs->gadget->ep0, ffs->ep0req); in functionfs_unbind()
1842 mutex_lock(&ffs->mutex); in functionfs_unbind()
1843 usb_ep_free_request(ffs->gadget->ep0, ffs->ep0req); in functionfs_unbind()
1844 ffs->ep0req = NULL; in functionfs_unbind()
1845 ffs->gadget = NULL; in functionfs_unbind()
1846 clear_bit(FFS_FL_BOUND, &ffs->flags); in functionfs_unbind()
1847 mutex_unlock(&ffs->mutex); in functionfs_unbind()
1857 count = ffs->eps_count; in ffs_epfiles_create()
1860 return -ENOMEM; in ffs_epfiles_create()
1864 epfile->ffs = ffs; in ffs_epfiles_create()
1865 mutex_init(&epfile->mutex); in ffs_epfiles_create()
1866 if (ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_epfiles_create()
1867 sprintf(epfile->name, "ep%02x", ffs->eps_addrmap[i]); in ffs_epfiles_create()
1869 sprintf(epfile->name, "ep%u", i); in ffs_epfiles_create()
1870 epfile->dentry = ffs_sb_create_file(ffs->sb, epfile->name, in ffs_epfiles_create()
1873 if (!epfile->dentry) { in ffs_epfiles_create()
1874 ffs_epfiles_destroy(epfiles, i - 1); in ffs_epfiles_create()
1875 return -ENOMEM; in ffs_epfiles_create()
1879 ffs->epfiles = epfiles; in ffs_epfiles_create()
1887 for (; count; --count, ++epfile) { in ffs_epfiles_destroy()
1888 BUG_ON(mutex_is_locked(&epfile->mutex)); in ffs_epfiles_destroy()
1889 if (epfile->dentry) { in ffs_epfiles_destroy()
1890 d_delete(epfile->dentry); in ffs_epfiles_destroy()
1891 dput(epfile->dentry); in ffs_epfiles_destroy()
1892 epfile->dentry = NULL; in ffs_epfiles_destroy()
1906 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
1907 count = func->ffs->eps_count; in ffs_func_eps_disable()
1908 epfile = func->ffs->epfiles; in ffs_func_eps_disable()
1909 ep = func->eps; in ffs_func_eps_disable()
1910 while (count--) { in ffs_func_eps_disable()
1912 if (ep->ep) in ffs_func_eps_disable()
1913 usb_ep_disable(ep->ep); in ffs_func_eps_disable()
1917 epfile->ep = NULL; in ffs_func_eps_disable()
1922 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
1934 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
1935 ffs = func->ffs; in ffs_func_eps_enable()
1936 ep = func->eps; in ffs_func_eps_enable()
1937 epfile = ffs->epfiles; in ffs_func_eps_enable()
1938 count = ffs->eps_count; in ffs_func_eps_enable()
1939 while(count--) { in ffs_func_eps_enable()
1940 ep->ep->driver_data = ep; in ffs_func_eps_enable()
1942 ret = config_ep_by_speed(func->gadget, &func->function, ep->ep); in ffs_func_eps_enable()
1945 __func__, ep->ep->name, ret); in ffs_func_eps_enable()
1949 ret = usb_ep_enable(ep->ep); in ffs_func_eps_enable()
1951 epfile->ep = ep; in ffs_func_eps_enable()
1952 epfile->in = usb_endpoint_dir_in(ep->ep->desc); in ffs_func_eps_enable()
1953 epfile->isoc = usb_endpoint_xfer_isoc(ep->ep->desc); in ffs_func_eps_enable()
1962 wake_up_interruptible(&ffs->wait); in ffs_func_eps_enable()
1963 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
1969 /* Parsing and building descriptors and strings *****************************/
1973 * well as record how many interfaces, endpoints and strings are
2006 return -EINVAL; in ffs_do_single_desc()
2010 length = _ds->bLength; in ffs_do_single_desc()
2013 return -EINVAL; in ffs_do_single_desc()
2023 return -EINVAL; \ in ffs_do_single_desc()
2034 switch (_ds->bDescriptorType) { in ffs_do_single_desc()
2041 _ds->bDescriptorType); in ffs_do_single_desc()
2042 return -EINVAL; in ffs_do_single_desc()
2050 __entity(INTERFACE, ds->bInterfaceNumber); in ffs_do_single_desc()
2051 if (ds->iInterface) in ffs_do_single_desc()
2052 __entity(STRING, ds->iInterface); in ffs_do_single_desc()
2053 *current_class = ds->bInterfaceClass; in ffs_do_single_desc()
2063 __entity(ENDPOINT, ds->bEndpointAddress); in ffs_do_single_desc()
2080 _ds->bDescriptorType, *current_class); in ffs_do_single_desc()
2081 return -EINVAL; in ffs_do_single_desc()
2094 if (ds->iFunction) in ffs_do_single_desc()
2095 __entity(STRING, ds->iFunction); in ffs_do_single_desc()
2111 pr_vdebug("unimplemented descriptor: %d\n", _ds->bDescriptorType); in ffs_do_single_desc()
2112 return -EINVAL; in ffs_do_single_desc()
2116 pr_vdebug("unknown descriptor: %d\n", _ds->bDescriptorType); in ffs_do_single_desc()
2117 return -EINVAL; in ffs_do_single_desc()
2121 _ds->bLength, _ds->bDescriptorType); in ffs_do_single_desc()
2122 return -EINVAL; in ffs_do_single_desc()
2138 unsigned long num = 0; in ffs_do_descs() local
2139 int current_class = -1; in ffs_do_descs()
2144 if (num == count) in ffs_do_descs()
2148 ret = entity(FFS_DESCRIPTOR, (u8 *)num, (void *)data, priv); in ffs_do_descs()
2151 num, ret); in ffs_do_descs()
2156 return _len - len; in ffs_do_descs()
2165 len -= ret; in ffs_do_descs()
2167 ++num; in ffs_do_descs()
2188 if (*valuep >= helper->interfaces_count) in __ffs_data_do_entity()
2189 helper->interfaces_count = *valuep + 1; in __ffs_data_do_entity()
2194 * Strings are indexed from 1 (0 is reserved in __ffs_data_do_entity()
2197 if (*valuep > helper->ffs->strings_count) in __ffs_data_do_entity()
2198 helper->ffs->strings_count = *valuep; in __ffs_data_do_entity()
2203 helper->eps_count++; in __ffs_data_do_entity()
2204 if (helper->eps_count >= FFS_MAX_EPS_COUNT) in __ffs_data_do_entity()
2205 return -EINVAL; in __ffs_data_do_entity()
2207 if (!helper->ffs->eps_count && !helper->ffs->interfaces_count) in __ffs_data_do_entity()
2208 helper->ffs->eps_addrmap[helper->eps_count] = in __ffs_data_do_entity()
2209 d->bEndpointAddress; in __ffs_data_do_entity()
2210 else if (helper->ffs->eps_addrmap[helper->eps_count] != in __ffs_data_do_entity()
2211 d->bEndpointAddress) in __ffs_data_do_entity()
2212 return -EINVAL; in __ffs_data_do_entity()
2222 u16 bcd_version = le16_to_cpu(desc->bcdVersion); in __ffs_do_os_desc_header()
2223 u16 w_index = le16_to_cpu(desc->wIndex); in __ffs_do_os_desc_header()
2231 return -EINVAL; in __ffs_do_os_desc_header()
2242 return -EINVAL; in __ffs_do_os_desc_header()
2263 while (feature_count--) { in ffs_do_single_os_desc()
2270 len -= ret; in ffs_do_single_os_desc()
2272 return _len - len; in ffs_do_single_os_desc()
2281 unsigned long num = 0; in ffs_do_os_descs() local
2283 for (num = 0; num < count; ++num) { in ffs_do_os_descs()
2290 return -EINVAL; in ffs_do_os_descs()
2299 if (le32_to_cpu(desc->dwLength) > len) in ffs_do_os_descs()
2300 return -EINVAL; in ffs_do_os_descs()
2305 num, ret); in ffs_do_os_descs()
2309 * 16-bit hex "?? 00" Little Endian looks like 8-bit hex "??" in ffs_do_os_descs()
2311 feature_count = le16_to_cpu(desc->wCount); in ffs_do_os_descs()
2313 (feature_count > 255 || desc->Reserved)) in ffs_do_os_descs()
2314 return -EINVAL; in ffs_do_os_descs()
2315 len -= ret; in ffs_do_os_descs()
2329 len -= ret; in ffs_do_os_descs()
2332 return _len - len; in ffs_do_os_descs()
2351 d->bFirstInterfaceNumber >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2352 return -EINVAL; in __ffs_data_do_os_desc()
2353 if (d->Reserved1 != 1) { in __ffs_data_do_os_desc()
2356 * but older kernels incorrectly rejected non-zero in __ffs_data_do_os_desc()
2361 d->Reserved1 = 1; in __ffs_data_do_os_desc()
2363 for (i = 0; i < ARRAY_SIZE(d->Reserved2); ++i) in __ffs_data_do_os_desc()
2364 if (d->Reserved2[i]) in __ffs_data_do_os_desc()
2365 return -EINVAL; in __ffs_data_do_os_desc()
2375 if (len < sizeof(*d) || h->interface >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2376 return -EINVAL; in __ffs_data_do_os_desc()
2377 length = le32_to_cpu(d->dwSize); in __ffs_data_do_os_desc()
2379 return -EINVAL; in __ffs_data_do_os_desc()
2380 type = le32_to_cpu(d->dwPropertyDataType); in __ffs_data_do_os_desc()
2385 return -EINVAL; in __ffs_data_do_os_desc()
2387 pnl = le16_to_cpu(d->wPropertyNameLength); in __ffs_data_do_os_desc()
2391 return -EINVAL; in __ffs_data_do_os_desc()
2397 return -EINVAL; in __ffs_data_do_os_desc()
2399 ++ffs->ms_os_descs_ext_prop_count; in __ffs_data_do_os_desc()
2401 ffs->ms_os_descs_ext_prop_name_len += pnl * 2; in __ffs_data_do_os_desc()
2402 ffs->ms_os_descs_ext_prop_data_len += pdl; in __ffs_data_do_os_desc()
2407 return -EINVAL; in __ffs_data_do_os_desc()
2417 int ret = -EINVAL, i; in __ffs_data_got_descs()
2427 len -= 8; in __ffs_data_got_descs()
2431 ffs->user_flags = flags; in __ffs_data_got_descs()
2440 ret = -ENOSYS; in __ffs_data_got_descs()
2444 len -= 12; in __ffs_data_got_descs()
2453 ffs->ffs_eventfd = in __ffs_data_got_descs()
2455 if (IS_ERR(ffs->ffs_eventfd)) { in __ffs_data_got_descs()
2456 ret = PTR_ERR(ffs->ffs_eventfd); in __ffs_data_got_descs()
2457 ffs->ffs_eventfd = NULL; in __ffs_data_got_descs()
2461 len -= 4; in __ffs_data_got_descs()
2473 len -= 4; in __ffs_data_got_descs()
2482 len -= 4; in __ffs_data_got_descs()
2497 if (!ffs->eps_count && !ffs->interfaces_count) { in __ffs_data_got_descs()
2498 ffs->eps_count = helper.eps_count; in __ffs_data_got_descs()
2499 ffs->interfaces_count = helper.interfaces_count; in __ffs_data_got_descs()
2501 if (ffs->eps_count != helper.eps_count) { in __ffs_data_got_descs()
2502 ret = -EINVAL; in __ffs_data_got_descs()
2505 if (ffs->interfaces_count != helper.interfaces_count) { in __ffs_data_got_descs()
2506 ret = -EINVAL; in __ffs_data_got_descs()
2511 len -= ret; in __ffs_data_got_descs()
2519 len -= ret; in __ffs_data_got_descs()
2523 ret = -EINVAL; in __ffs_data_got_descs()
2527 ffs->raw_descs_data = _data; in __ffs_data_got_descs()
2528 ffs->raw_descs = raw_descs; in __ffs_data_got_descs()
2529 ffs->raw_descs_length = data - raw_descs; in __ffs_data_got_descs()
2530 ffs->fs_descs_count = counts[0]; in __ffs_data_got_descs()
2531 ffs->hs_descs_count = counts[1]; in __ffs_data_got_descs()
2532 ffs->ss_descs_count = counts[2]; in __ffs_data_got_descs()
2533 ffs->ms_os_descs_count = os_descs_count; in __ffs_data_got_descs()
2561 /* Do we have at least as many strings as descriptors need? */ in __ffs_data_got_strings()
2562 needed_count = ffs->strings_count; in __ffs_data_got_strings()
2567 * If we don't need any strings just return and free all in __ffs_data_got_strings()
2582 vla_item(d, struct usb_string, strings, in __ffs_data_got_strings()
2589 return -ENOMEM; in __ffs_data_got_strings()
2598 } while (--i); in __ffs_data_got_strings()
2604 s = vla_ptr(vlabuf, d, strings); in __ffs_data_got_strings()
2609 len -= 16; in __ffs_data_got_strings()
2611 do { /* lang_count > 0 so we can use do-while */ in __ffs_data_got_strings()
2617 t->language = get_unaligned_le16(data); in __ffs_data_got_strings()
2618 t->strings = s; in __ffs_data_got_strings()
2622 len -= 2; in __ffs_data_got_strings()
2625 do { /* str_count > 0 so we can use do-while */ in __ffs_data_got_strings()
2632 * User may provide more strings then we need, in __ffs_data_got_strings()
2638 * s->id will be set while adding in __ffs_data_got_strings()
2642 s->s = data; in __ffs_data_got_strings()
2643 --needed; in __ffs_data_got_strings()
2648 len -= length + 1; in __ffs_data_got_strings()
2649 } while (--str_per_lang); in __ffs_data_got_strings()
2651 s->id = 0; /* terminator */ in __ffs_data_got_strings()
2652 s->s = NULL; in __ffs_data_got_strings()
2655 } while (--lang_count); in __ffs_data_got_strings()
2662 ffs->stringtabs = stringtabs; in __ffs_data_got_strings()
2663 ffs->raw_strings = _data; in __ffs_data_got_strings()
2671 return -EINVAL; in __ffs_data_got_strings()
2687 * of ffs->setup_state without holding the lock because when in __ffs_event_add()
2691 if (ffs->setup_state == FFS_SETUP_PENDING) in __ffs_event_add()
2692 ffs->setup_state = FFS_SETUP_CANCELLED; in __ffs_event_add()
2696 * evens on ffs->ev.types queue. This is important because the queue in __ffs_event_add()
2727 u8 *ev = ffs->ev.types, *out = ev; in __ffs_event_add()
2728 unsigned n = ffs->ev.count; in __ffs_event_add()
2729 for (; n; --n, ++ev) in __ffs_event_add()
2734 ffs->ev.count = out - ffs->ev.types; in __ffs_event_add()
2738 ffs->ev.types[ffs->ev.count++] = type; in __ffs_event_add()
2739 wake_up_locked(&ffs->ev.waitq); in __ffs_event_add()
2740 if (ffs->ffs_eventfd) in __ffs_event_add()
2741 eventfd_signal(ffs->ffs_eventfd); in __ffs_event_add()
2748 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_event_add()
2750 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_event_add()
2759 for (i = 1; i < ARRAY_SIZE(ffs->eps_addrmap); ++i) in ffs_ep_addr2idx()
2760 if (ffs->eps_addrmap[i] == endpoint_address) in ffs_ep_addr2idx()
2762 return -ENOENT; in ffs_ep_addr2idx()
2785 if (func->function.ss_descriptors) { in __ffs_func_bind_do_descs()
2787 func->function.ss_descriptors[(long)valuep] = desc; in __ffs_func_bind_do_descs()
2788 } else if (func->function.hs_descriptors) { in __ffs_func_bind_do_descs()
2790 func->function.hs_descriptors[(long)valuep] = desc; in __ffs_func_bind_do_descs()
2793 func->function.fs_descriptors[(long)valuep] = desc; in __ffs_func_bind_do_descs()
2796 if (!desc || desc->bDescriptorType != USB_DT_ENDPOINT) in __ffs_func_bind_do_descs()
2799 idx = ffs_ep_addr2idx(func->ffs, ds->bEndpointAddress) - 1; in __ffs_func_bind_do_descs()
2803 ffs_ep = func->eps + idx; in __ffs_func_bind_do_descs()
2805 if (ffs_ep->descs[ep_desc_id]) { in __ffs_func_bind_do_descs()
2808 ds->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); in __ffs_func_bind_do_descs()
2809 return -EINVAL; in __ffs_func_bind_do_descs()
2811 ffs_ep->descs[ep_desc_id] = ds; in __ffs_func_bind_do_descs()
2813 ffs_dump_mem(": Original ep desc", ds, ds->bLength); in __ffs_func_bind_do_descs()
2814 if (ffs_ep->ep) { in __ffs_func_bind_do_descs()
2815 ds->bEndpointAddress = ffs_ep->descs[0]->bEndpointAddress; in __ffs_func_bind_do_descs()
2816 if (!ds->wMaxPacketSize) in __ffs_func_bind_do_descs()
2817 ds->wMaxPacketSize = ffs_ep->descs[0]->wMaxPacketSize; in __ffs_func_bind_do_descs()
2828 bEndpointAddress = ds->bEndpointAddress; in __ffs_func_bind_do_descs()
2833 wMaxPacketSize = ds->wMaxPacketSize; in __ffs_func_bind_do_descs()
2835 ep = usb_ep_autoconfig(func->gadget, ds); in __ffs_func_bind_do_descs()
2837 return -ENOTSUPP; in __ffs_func_bind_do_descs()
2838 ep->driver_data = func->eps + idx; in __ffs_func_bind_do_descs()
2842 return -ENOMEM; in __ffs_func_bind_do_descs()
2844 ffs_ep->ep = ep; in __ffs_func_bind_do_descs()
2845 ffs_ep->req = req; in __ffs_func_bind_do_descs()
2846 func->eps_revmap[ds->bEndpointAddress & in __ffs_func_bind_do_descs()
2852 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in __ffs_func_bind_do_descs()
2853 ds->bEndpointAddress = bEndpointAddress; in __ffs_func_bind_do_descs()
2858 ds->wMaxPacketSize = wMaxPacketSize; in __ffs_func_bind_do_descs()
2860 ffs_dump_mem(": Rewritten ep desc", ds, ds->bLength); in __ffs_func_bind_do_descs()
2881 if (func->interfaces_nums[idx] < 0) { in __ffs_func_bind_do_nums()
2882 int id = usb_interface_id(func->conf, &func->function); in __ffs_func_bind_do_nums()
2885 func->interfaces_nums[idx] = id; in __ffs_func_bind_do_nums()
2887 newValue = func->interfaces_nums[idx]; in __ffs_func_bind_do_nums()
2892 newValue = func->ffs->stringtabs[0]->strings[*valuep - 1].id; in __ffs_func_bind_do_nums()
2900 if (desc->bDescriptorType == USB_DT_ENDPOINT) in __ffs_func_bind_do_nums()
2903 idx = (*valuep & USB_ENDPOINT_NUMBER_MASK) - 1; in __ffs_func_bind_do_nums()
2904 if (!func->eps[idx].ep) in __ffs_func_bind_do_nums()
2905 return -EINVAL; in __ffs_func_bind_do_nums()
2909 descs = func->eps[idx].descs; in __ffs_func_bind_do_nums()
2910 newValue = descs[descs[0] ? 0 : 1]->bEndpointAddress; in __ffs_func_bind_do_nums()
2915 pr_vdebug("%02x -> %02x\n", *valuep, newValue); in __ffs_func_bind_do_nums()
2932 t = &func->function.os_desc_table[desc->bFirstInterfaceNumber]; in __ffs_func_bind_do_os_desc()
2933 t->if_id = func->interfaces_nums[desc->bFirstInterfaceNumber]; in __ffs_func_bind_do_os_desc()
2934 memcpy(t->os_desc->ext_compat_id, &desc->IDs, in __ffs_func_bind_do_os_desc()
2946 t = &func->function.os_desc_table[h->interface]; in __ffs_func_bind_do_os_desc()
2947 t->if_id = func->interfaces_nums[h->interface]; in __ffs_func_bind_do_os_desc()
2949 ext_prop = func->ffs->ms_os_descs_ext_prop_avail; in __ffs_func_bind_do_os_desc()
2950 func->ffs->ms_os_descs_ext_prop_avail += sizeof(*ext_prop); in __ffs_func_bind_do_os_desc()
2952 ext_prop->type = le32_to_cpu(desc->dwPropertyDataType); in __ffs_func_bind_do_os_desc()
2953 ext_prop->name_len = le16_to_cpu(desc->wPropertyNameLength); in __ffs_func_bind_do_os_desc()
2954 ext_prop->data_len = le32_to_cpu(*(__le32 *) in __ffs_func_bind_do_os_desc()
2955 usb_ext_prop_data_len_ptr(data, ext_prop->name_len)); in __ffs_func_bind_do_os_desc()
2956 length = ext_prop->name_len + ext_prop->data_len + 14; in __ffs_func_bind_do_os_desc()
2958 ext_prop_name = func->ffs->ms_os_descs_ext_prop_name_avail; in __ffs_func_bind_do_os_desc()
2959 func->ffs->ms_os_descs_ext_prop_name_avail += in __ffs_func_bind_do_os_desc()
2960 ext_prop->name_len; in __ffs_func_bind_do_os_desc()
2962 ext_prop_data = func->ffs->ms_os_descs_ext_prop_data_avail; in __ffs_func_bind_do_os_desc()
2963 func->ffs->ms_os_descs_ext_prop_data_avail += in __ffs_func_bind_do_os_desc()
2964 ext_prop->data_len; in __ffs_func_bind_do_os_desc()
2966 usb_ext_prop_data_ptr(data, ext_prop->name_len), in __ffs_func_bind_do_os_desc()
2967 ext_prop->data_len); in __ffs_func_bind_do_os_desc()
2969 switch (ext_prop->type) { in __ffs_func_bind_do_os_desc()
2974 ext_prop->data_len *= 2; in __ffs_func_bind_do_os_desc()
2977 ext_prop->data = ext_prop_data; in __ffs_func_bind_do_os_desc()
2980 ext_prop->name_len); in __ffs_func_bind_do_os_desc()
2982 ext_prop->name_len *= 2; in __ffs_func_bind_do_os_desc()
2983 ext_prop->name = ext_prop_name; in __ffs_func_bind_do_os_desc()
2985 t->os_desc->ext_prop_len += in __ffs_func_bind_do_os_desc()
2986 ext_prop->name_len + ext_prop->data_len + 14; in __ffs_func_bind_do_os_desc()
2987 ++t->os_desc->ext_prop_count; in __ffs_func_bind_do_os_desc()
2988 list_add_tail(&ext_prop->entry, &t->os_desc->ext_prop); in __ffs_func_bind_do_os_desc()
3003 container_of(f->fi, struct f_fs_opts, func_inst); in ffs_do_functionfs_bind()
3012 * Configfs-enabled gadgets however do need ffs_dev_lock. in ffs_do_functionfs_bind()
3014 if (!ffs_opts->no_configfs) in ffs_do_functionfs_bind()
3016 ret = ffs_opts->dev->desc_ready ? 0 : -ENODEV; in ffs_do_functionfs_bind()
3017 ffs_data = ffs_opts->dev->ffs_data; in ffs_do_functionfs_bind()
3018 if (!ffs_opts->no_configfs) in ffs_do_functionfs_bind()
3023 func->ffs = ffs_data; in ffs_do_functionfs_bind()
3024 func->conf = c; in ffs_do_functionfs_bind()
3025 func->gadget = c->cdev->gadget; in ffs_do_functionfs_bind()
3032 * with regard to ffs_opts->bound access in ffs_do_functionfs_bind()
3034 if (!ffs_opts->refcnt) { in ffs_do_functionfs_bind()
3035 ret = functionfs_bind(func->ffs, c->cdev); in ffs_do_functionfs_bind()
3039 ffs_opts->refcnt++; in ffs_do_functionfs_bind()
3040 func->function.strings = func->ffs->stringtabs; in ffs_do_functionfs_bind()
3049 struct ffs_data *ffs = func->ffs; in _ffs_func_bind()
3051 const int full = !!func->ffs->fs_descs_count; in _ffs_func_bind()
3052 const int high = !!func->ffs->hs_descs_count; in _ffs_func_bind()
3053 const int super = !!func->ffs->ss_descs_count; in _ffs_func_bind()
3060 vla_item_with_sz(d, struct ffs_ep, eps, ffs->eps_count); in _ffs_func_bind()
3062 full ? ffs->fs_descs_count + 1 : 0); in _ffs_func_bind()
3064 high ? ffs->hs_descs_count + 1 : 0); in _ffs_func_bind()
3066 super ? ffs->ss_descs_count + 1 : 0); in _ffs_func_bind()
3067 vla_item_with_sz(d, short, inums, ffs->interfaces_count); in _ffs_func_bind()
3069 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3071 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3073 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3075 ffs->ms_os_descs_ext_prop_count); in _ffs_func_bind()
3077 ffs->ms_os_descs_ext_prop_name_len); in _ffs_func_bind()
3079 ffs->ms_os_descs_ext_prop_data_len); in _ffs_func_bind()
3080 vla_item_with_sz(d, char, raw_descs, ffs->raw_descs_length); in _ffs_func_bind()
3085 return -ENOTSUPP; in _ffs_func_bind()
3090 return -ENOMEM; in _ffs_func_bind()
3092 ffs->ms_os_descs_ext_prop_avail = vla_ptr(vlabuf, d, ext_prop); in _ffs_func_bind()
3093 ffs->ms_os_descs_ext_prop_name_avail = in _ffs_func_bind()
3095 ffs->ms_os_descs_ext_prop_data_avail = in _ffs_func_bind()
3099 memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs, in _ffs_func_bind()
3100 ffs->raw_descs_length); in _ffs_func_bind()
3104 for (i = 0; i < ffs->eps_count; i++) in _ffs_func_bind()
3105 eps_ptr[i].num = -1; in _ffs_func_bind()
3108 * d_eps == vlabuf, func->eps used to kfree vlabuf later in _ffs_func_bind()
3110 func->eps = vla_ptr(vlabuf, d, eps); in _ffs_func_bind()
3111 func->interfaces_nums = vla_ptr(vlabuf, d, inums); in _ffs_func_bind()
3119 func->function.fs_descriptors = vla_ptr(vlabuf, d, fs_descs); in _ffs_func_bind()
3120 fs_len = ffs_do_descs(ffs->fs_descs_count, in _ffs_func_bind()
3133 func->function.hs_descriptors = vla_ptr(vlabuf, d, hs_descs); in _ffs_func_bind()
3134 hs_len = ffs_do_descs(ffs->hs_descs_count, in _ffs_func_bind()
3136 d_raw_descs__sz - fs_len, in _ffs_func_bind()
3147 func->function.ss_descriptors = func->function.ssp_descriptors = in _ffs_func_bind()
3149 ss_len = ffs_do_descs(ffs->ss_descs_count, in _ffs_func_bind()
3151 d_raw_descs__sz - fs_len - hs_len, in _ffs_func_bind()
3166 ret = ffs_do_descs(ffs->fs_descs_count + in _ffs_func_bind()
3167 (high ? ffs->hs_descs_count : 0) + in _ffs_func_bind()
3168 (super ? ffs->ss_descs_count : 0), in _ffs_func_bind()
3174 func->function.os_desc_table = vla_ptr(vlabuf, d, os_desc_table); in _ffs_func_bind()
3175 if (c->cdev->use_os_string) { in _ffs_func_bind()
3176 for (i = 0; i < ffs->interfaces_count; ++i) { in _ffs_func_bind()
3179 desc = func->function.os_desc_table[i].os_desc = in _ffs_func_bind()
3182 desc->ext_compat_id = in _ffs_func_bind()
3184 INIT_LIST_HEAD(&desc->ext_prop); in _ffs_func_bind()
3186 ret = ffs_do_os_descs(ffs->ms_os_descs_count, in _ffs_func_bind()
3189 d_raw_descs__sz - fs_len - hs_len - in _ffs_func_bind()
3195 func->function.os_desc_n = in _ffs_func_bind()
3196 c->cdev->use_os_string ? ffs->interfaces_count : 0; in _ffs_func_bind()
3218 if (ret && !--ffs_opts->refcnt) in ffs_func_bind()
3219 functionfs_unbind(func->ffs); in ffs_func_bind()
3238 struct ffs_data *ffs = func->ffs; in ffs_func_set_alt()
3241 if (alt != (unsigned)-1) { in ffs_func_set_alt()
3247 if (ffs->func) in ffs_func_set_alt()
3248 ffs_func_eps_disable(ffs->func); in ffs_func_set_alt()
3250 if (ffs->state == FFS_DEACTIVATED) { in ffs_func_set_alt()
3251 ffs->state = FFS_CLOSING; in ffs_func_set_alt()
3252 INIT_WORK(&ffs->reset_work, ffs_reset_work); in ffs_func_set_alt()
3253 schedule_work(&ffs->reset_work); in ffs_func_set_alt()
3254 return -ENODEV; in ffs_func_set_alt()
3257 if (ffs->state != FFS_ACTIVE) in ffs_func_set_alt()
3258 return -ENODEV; in ffs_func_set_alt()
3260 if (alt == (unsigned)-1) { in ffs_func_set_alt()
3261 ffs->func = NULL; in ffs_func_set_alt()
3266 ffs->func = func; in ffs_func_set_alt()
3275 ffs_func_set_alt(f, 0, (unsigned)-1); in ffs_func_disable()
3282 struct ffs_data *ffs = func->ffs; in ffs_func_setup()
3286 pr_vdebug("creq->bRequestType = %02x\n", creq->bRequestType); in ffs_func_setup()
3287 pr_vdebug("creq->bRequest = %02x\n", creq->bRequest); in ffs_func_setup()
3288 pr_vdebug("creq->wValue = %04x\n", le16_to_cpu(creq->wValue)); in ffs_func_setup()
3289 pr_vdebug("creq->wIndex = %04x\n", le16_to_cpu(creq->wIndex)); in ffs_func_setup()
3290 pr_vdebug("creq->wLength = %04x\n", le16_to_cpu(creq->wLength)); in ffs_func_setup()
3296 * passed to usb_configuration->setup() (if one is set). No in ffs_func_setup()
3302 if (ffs->state != FFS_ACTIVE) in ffs_func_setup()
3303 return -ENODEV; in ffs_func_setup()
3305 switch (creq->bRequestType & USB_RECIP_MASK) { in ffs_func_setup()
3307 ret = ffs_func_revmap_intf(func, le16_to_cpu(creq->wIndex)); in ffs_func_setup()
3313 ret = ffs_func_revmap_ep(func, le16_to_cpu(creq->wIndex)); in ffs_func_setup()
3316 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_func_setup()
3317 ret = func->ffs->eps_addrmap[ret]; in ffs_func_setup()
3321 if (func->ffs->user_flags & FUNCTIONFS_ALL_CTRL_RECIP) in ffs_func_setup()
3322 ret = le16_to_cpu(creq->wIndex); in ffs_func_setup()
3324 return -EOPNOTSUPP; in ffs_func_setup()
3327 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3328 ffs->ev.setup = *creq; in ffs_func_setup()
3329 ffs->ev.setup.wIndex = cpu_to_le16(ret); in ffs_func_setup()
3331 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3333 return creq->wLength == 0 ? USB_GADGET_DELAYED_STATUS : 0; in ffs_func_setup()
3342 if (config0 && !(func->ffs->user_flags & FUNCTIONFS_CONFIG0_SETUP)) in ffs_func_req_match()
3345 switch (creq->bRequestType & USB_RECIP_MASK) { in ffs_func_req_match()
3348 le16_to_cpu(creq->wIndex)) >= 0); in ffs_func_req_match()
3351 le16_to_cpu(creq->wIndex)) >= 0); in ffs_func_req_match()
3353 return (bool) (func->ffs->user_flags & in ffs_func_req_match()
3360 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_SUSPEND); in ffs_func_suspend()
3365 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_RESUME); in ffs_func_resume()
3371 static int ffs_func_revmap_ep(struct ffs_function *func, u8 num) in ffs_func_revmap_ep() argument
3373 num = func->eps_revmap[num & USB_ENDPOINT_NUMBER_MASK]; in ffs_func_revmap_ep()
3374 return num ? num : -EDOM; in ffs_func_revmap_ep()
3379 short *nums = func->interfaces_nums; in ffs_func_revmap_intf()
3380 unsigned count = func->ffs->interfaces_count; in ffs_func_revmap_intf()
3382 for (; count; --count, ++nums) { in ffs_func_revmap_intf()
3384 return nums - func->interfaces_nums; in ffs_func_revmap_intf()
3387 return -EDOM; in ffs_func_revmap_intf()
3403 if (strcmp(dev->name, name) == 0) in _ffs_do_find_dev()
3419 if (dev->single) in _ffs_get_single_dev()
3452 usb_put_function_instance(&opts->func_inst); in ffs_attr_release()
3472 ffs_release_dev(opts->dev); in ffs_free_inst()
3474 _ffs_free_dev(opts->dev); in ffs_free_inst()
3482 return -ENAMETOOLONG; in ffs_set_inst_name()
3483 return ffs_name_dev(to_f_fs_opts(fi)->dev, name); in ffs_set_inst_name()
3493 return ERR_PTR(-ENOMEM); in ffs_alloc_inst()
3495 opts->func_inst.set_inst_name = ffs_set_inst_name; in ffs_alloc_inst()
3496 opts->func_inst.free_func_inst = ffs_free_inst; in ffs_alloc_inst()
3504 opts->dev = dev; in ffs_alloc_inst()
3505 dev->opts = opts; in ffs_alloc_inst()
3507 config_group_init_type_name(&opts->func_inst.group, "", in ffs_alloc_inst()
3509 return &opts->func_inst; in ffs_alloc_inst()
3521 struct ffs_data *ffs = func->ffs; in ffs_func_unbind()
3523 container_of(f->fi, struct f_fs_opts, func_inst); in ffs_func_unbind()
3524 struct ffs_ep *ep = func->eps; in ffs_func_unbind()
3525 unsigned count = ffs->eps_count; in ffs_func_unbind()
3528 if (ffs->func == func) { in ffs_func_unbind()
3530 ffs->func = NULL; in ffs_func_unbind()
3534 drain_workqueue(ffs->io_completion_wq); in ffs_func_unbind()
3537 if (!--opts->refcnt) in ffs_func_unbind()
3541 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_unbind()
3542 while (count--) { in ffs_func_unbind()
3543 if (ep->ep && ep->req) in ffs_func_unbind()
3544 usb_ep_free_request(ep->ep, ep->req); in ffs_func_unbind()
3545 ep->req = NULL; in ffs_func_unbind()
3548 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_unbind()
3549 kfree(func->eps); in ffs_func_unbind()
3550 func->eps = NULL; in ffs_func_unbind()
3555 func->function.fs_descriptors = NULL; in ffs_func_unbind()
3556 func->function.hs_descriptors = NULL; in ffs_func_unbind()
3557 func->function.ss_descriptors = NULL; in ffs_func_unbind()
3558 func->function.ssp_descriptors = NULL; in ffs_func_unbind()
3559 func->interfaces_nums = NULL; in ffs_func_unbind()
3569 return ERR_PTR(-ENOMEM); in ffs_alloc()
3571 func->function.name = "Function FS Gadget"; in ffs_alloc()
3573 func->function.bind = ffs_func_bind; in ffs_alloc()
3574 func->function.unbind = ffs_func_unbind; in ffs_alloc()
3575 func->function.set_alt = ffs_func_set_alt; in ffs_alloc()
3576 func->function.disable = ffs_func_disable; in ffs_alloc()
3577 func->function.setup = ffs_func_setup; in ffs_alloc()
3578 func->function.req_match = ffs_func_req_match; in ffs_alloc()
3579 func->function.suspend = ffs_func_suspend; in ffs_alloc()
3580 func->function.resume = ffs_func_resume; in ffs_alloc()
3581 func->function.free_func = ffs_free; in ffs_alloc()
3583 return &func->function; in ffs_alloc()
3595 return ERR_PTR(-EBUSY); in _ffs_alloc_dev()
3599 return ERR_PTR(-ENOMEM); in _ffs_alloc_dev()
3609 list_add(&dev->entry, &ffs_devices); in _ffs_alloc_dev()
3623 strscpy(dev->name, name, ARRAY_SIZE(dev->name)); in ffs_name_dev()
3625 ret = -EBUSY; in ffs_name_dev()
3641 ret = -EBUSY; in ffs_single_dev()
3643 dev->single = true; in ffs_single_dev()
3655 list_del(&dev->entry); in _ffs_free_dev()
3671 ret = -ENOENT; in ffs_acquire_dev()
3672 } else if (ffs_dev->mounted) { in ffs_acquire_dev()
3673 ret = -EBUSY; in ffs_acquire_dev()
3674 } else if (ffs_dev->ffs_acquire_dev_callback && in ffs_acquire_dev()
3675 ffs_dev->ffs_acquire_dev_callback(ffs_dev)) { in ffs_acquire_dev()
3676 ret = -ENOENT; in ffs_acquire_dev()
3678 ffs_dev->mounted = true; in ffs_acquire_dev()
3679 ffs_dev->ffs_data = ffs_data; in ffs_acquire_dev()
3680 ffs_data->private_data = ffs_dev; in ffs_acquire_dev()
3691 if (ffs_dev && ffs_dev->mounted) { in ffs_release_dev()
3692 ffs_dev->mounted = false; in ffs_release_dev()
3693 if (ffs_dev->ffs_data) { in ffs_release_dev()
3694 ffs_dev->ffs_data->private_data = NULL; in ffs_release_dev()
3695 ffs_dev->ffs_data = NULL; in ffs_release_dev()
3698 if (ffs_dev->ffs_release_dev_callback) in ffs_release_dev()
3699 ffs_dev->ffs_release_dev_callback(ffs_dev); in ffs_release_dev()
3712 ffs_obj = ffs->private_data; in ffs_ready()
3714 ret = -EINVAL; in ffs_ready()
3717 if (WARN_ON(ffs_obj->desc_ready)) { in ffs_ready()
3718 ret = -EBUSY; in ffs_ready()
3722 ffs_obj->desc_ready = true; in ffs_ready()
3724 if (ffs_obj->ffs_ready_callback) { in ffs_ready()
3725 ret = ffs_obj->ffs_ready_callback(ffs); in ffs_ready()
3730 set_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags); in ffs_ready()
3744 ffs_obj = ffs->private_data; in ffs_closed()
3748 ffs_obj->desc_ready = false; in ffs_closed()
3750 if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags) && in ffs_closed()
3751 ffs_obj->ffs_closed_callback) in ffs_closed()
3752 ffs_obj->ffs_closed_callback(ffs); in ffs_closed()
3754 if (ffs_obj->opts) in ffs_closed()
3755 opts = ffs_obj->opts; in ffs_closed()
3759 if (opts->no_configfs || !opts->func_inst.group.cg_item.ci_parent in ffs_closed()
3760 || !kref_read(&opts->func_inst.group.cg_item.ci_kref)) in ffs_closed()
3763 ci = opts->func_inst.group.cg_item.ci_parent->ci_parent; in ffs_closed()
3766 if (test_bit(FFS_FL_BOUND, &ffs->flags)) in ffs_closed()
3778 ? mutex_trylock(mutex) ? 0 : -EAGAIN in ffs_mutex_lock()