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
126 int status; /* P: epfile->mutex */
130 /* Protects ep->ep and ep->req. */
134 struct ffs_ep *ep; /* P: ffs->eps_lock */
149 * can never run concurrently (they are synchronised by epfile->mutex)
159 * pointer is not-NULL (namely READ_BUFFER_DROP) it will instead free
194 #define READ_BUFFER_DROP ((struct ffs_buffer *)ERR_PTR(-ESHUTDOWN))
198 unsigned char in; /* P: ffs->eps_lock */
199 unsigned char isoc; /* P: ffs->eps_lock */
270 struct ffs_data *ffs = req->context; in ffs_ep0_complete()
272 complete(&ffs->ep0req_completion); in ffs_ep0_complete()
276 __releases(&ffs->ev.waitq.lock) in __ffs_ep0_queue_wait()
278 struct usb_request *req = ffs->ep0req; in __ffs_ep0_queue_wait()
281 req->zero = len < le16_to_cpu(ffs->ev.setup.wLength); in __ffs_ep0_queue_wait()
283 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_queue_wait()
285 req->buf = data; in __ffs_ep0_queue_wait()
286 req->length = len; in __ffs_ep0_queue_wait()
293 if (req->buf == NULL) in __ffs_ep0_queue_wait()
294 req->buf = (void *)0xDEADBABE; in __ffs_ep0_queue_wait()
296 reinit_completion(&ffs->ep0req_completion); in __ffs_ep0_queue_wait()
298 ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC); in __ffs_ep0_queue_wait()
302 ret = wait_for_completion_interruptible(&ffs->ep0req_completion); in __ffs_ep0_queue_wait()
304 usb_ep_dequeue(ffs->gadget->ep0, req); in __ffs_ep0_queue_wait()
305 return -EINTR; in __ffs_ep0_queue_wait()
308 ffs->setup_state = FFS_NO_SETUP; in __ffs_ep0_queue_wait()
309 return req->status ? req->status : req->actual; in __ffs_ep0_queue_wait()
314 if (ffs->ev.can_stall) { in __ffs_ep0_stall()
316 usb_ep_set_halt(ffs->gadget->ep0); in __ffs_ep0_stall()
317 ffs->setup_state = FFS_NO_SETUP; in __ffs_ep0_stall()
318 return -EL2HLT; in __ffs_ep0_stall()
321 return -ESRCH; in __ffs_ep0_stall()
328 struct ffs_data *ffs = file->private_data; in ffs_ep0_write()
336 return -EIDRM; in ffs_ep0_write()
339 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_write()
344 switch (ffs->state) { in ffs_ep0_write()
349 ret = -EINVAL; in ffs_ep0_write()
360 if (ffs->state == FFS_READ_DESCRIPTORS) { in ffs_ep0_write()
366 ffs->state = FFS_READ_STRINGS; in ffs_ep0_write()
369 pr_info("read strings\n"); in ffs_ep0_write()
376 ffs->state = FFS_CLOSING; in ffs_ep0_write()
380 ffs->state = FFS_ACTIVE; in ffs_ep0_write()
381 mutex_unlock(&ffs->mutex); in ffs_ep0_write()
385 ffs->state = FFS_CLOSING; in ffs_ep0_write()
399 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
402 ret = -EIDRM; in ffs_ep0_write()
406 ret = -ESRCH; in ffs_ep0_write()
414 if (!(ffs->ev.setup.bRequestType & USB_DIR_IN)) { in ffs_ep0_write()
415 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
421 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); in ffs_ep0_write()
423 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
431 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
441 * the only place FFS_SETUP_PENDING -> FFS_NO_SETUP in ffs_ep0_write()
447 ret = -EIDRM; in ffs_ep0_write()
449 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_write()
458 ret = -EBADFD; in ffs_ep0_write()
462 mutex_unlock(&ffs->mutex); in ffs_ep0_write()
466 /* Called with ffs->ev.waitq.lock and ffs->mutex held, both released on exit. */
469 __releases(&ffs->ev.waitq.lock) in __ffs_ep0_read_events()
472 * n cannot be bigger than ffs->ev.count, which cannot be bigger than in __ffs_ep0_read_events()
473 * size of ffs->ev.types array (which is four) so that's how much space in __ffs_ep0_read_events()
476 struct usb_functionfs_event events[ARRAY_SIZE(ffs->ev.types)]; in __ffs_ep0_read_events()
483 events[i].type = ffs->ev.types[i]; in __ffs_ep0_read_events()
485 events[i].u.setup = ffs->ev.setup; in __ffs_ep0_read_events()
486 ffs->setup_state = FFS_SETUP_PENDING; in __ffs_ep0_read_events()
490 ffs->ev.count -= n; in __ffs_ep0_read_events()
491 if (ffs->ev.count) in __ffs_ep0_read_events()
492 memmove(ffs->ev.types, ffs->ev.types + n, in __ffs_ep0_read_events()
493 ffs->ev.count * sizeof *ffs->ev.types); in __ffs_ep0_read_events()
495 spin_unlock_irq(&ffs->ev.waitq.lock); in __ffs_ep0_read_events()
496 mutex_unlock(&ffs->mutex); in __ffs_ep0_read_events()
498 return unlikely(copy_to_user(buf, events, size)) ? -EFAULT : size; in __ffs_ep0_read_events()
504 struct ffs_data *ffs = file->private_data; in ffs_ep0_read()
513 return -EIDRM; in ffs_ep0_read()
516 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_read()
521 if (ffs->state != FFS_ACTIVE) { in ffs_ep0_read()
522 ret = -EBADFD; in ffs_ep0_read()
530 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
534 ret = -EIDRM; in ffs_ep0_read()
540 ret = -EINVAL; in ffs_ep0_read()
544 if ((file->f_flags & O_NONBLOCK) && !ffs->ev.count) { in ffs_ep0_read()
545 ret = -EAGAIN; in ffs_ep0_read()
549 if (wait_event_interruptible_exclusive_locked_irq(ffs->ev.waitq, in ffs_ep0_read()
550 ffs->ev.count)) { in ffs_ep0_read()
551 ret = -EINTR; in ffs_ep0_read()
557 min(n, (size_t)ffs->ev.count)); in ffs_ep0_read()
560 if (ffs->ev.setup.bRequestType & USB_DIR_IN) { in ffs_ep0_read()
561 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
566 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); in ffs_ep0_read()
568 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
573 ret = -ENOMEM; in ffs_ep0_read()
578 spin_lock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
583 ret = -EIDRM; in ffs_ep0_read()
590 ret = -EFAULT; in ffs_ep0_read()
594 ret = -EBADFD; in ffs_ep0_read()
598 spin_unlock_irq(&ffs->ev.waitq.lock); in ffs_ep0_read()
600 mutex_unlock(&ffs->mutex); in ffs_ep0_read()
607 struct ffs_data *ffs = inode->i_private; in ffs_ep0_open()
611 if (unlikely(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()
633 struct ffs_data *ffs = file->private_data; in ffs_ep0_ioctl()
634 struct usb_gadget *gadget = ffs->gadget; in ffs_ep0_ioctl()
640 struct ffs_function *func = ffs->func; in ffs_ep0_ioctl()
641 ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV; in ffs_ep0_ioctl()
642 } else if (gadget && gadget->ops->ioctl) { in ffs_ep0_ioctl()
643 ret = gadget->ops->ioctl(gadget, code, value); in ffs_ep0_ioctl()
645 ret = -ENOTTY; in ffs_ep0_ioctl()
653 struct ffs_data *ffs = file->private_data; in ffs_ep0_poll()
657 poll_wait(file, &ffs->ev.waitq, wait); in ffs_ep0_poll()
659 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); in ffs_ep0_poll()
663 switch (ffs->state) { in ffs_ep0_poll()
670 switch (ffs->setup_state) { in ffs_ep0_poll()
672 if (ffs->ev.count) in ffs_ep0_poll()
687 mutex_unlock(&ffs->mutex); in ffs_ep0_poll()
709 if (likely(req->context)) { in ffs_epfile_io_complete()
710 struct ffs_ep *ep = _ep->driver_data; in ffs_epfile_io_complete()
711 ep->status = req->status ? req->status : req->actual; in ffs_epfile_io_complete()
712 complete(req->context); 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->req->status ? io_data->req->status : in ffs_user_copy_worker()
823 io_data->req->actual; in ffs_user_copy_worker()
824 bool kiocb_has_eventfd = io_data->kiocb->ki_flags & IOCB_EVENTFD; in ffs_user_copy_worker()
826 if (io_data->read && ret > 0) { in ffs_user_copy_worker()
827 kthread_use_mm(io_data->mm); in ffs_user_copy_worker()
828 ret = ffs_copy_to_iter(io_data->buf, ret, &io_data->data); in ffs_user_copy_worker()
829 kthread_unuse_mm(io_data->mm); in ffs_user_copy_worker()
832 io_data->kiocb->ki_complete(io_data->kiocb, ret, ret); in ffs_user_copy_worker()
834 if (io_data->ffs->ffs_eventfd && !kiocb_has_eventfd) in ffs_user_copy_worker()
835 eventfd_signal(io_data->ffs->ffs_eventfd, 1); in ffs_user_copy_worker()
837 usb_ep_free_request(io_data->ep, io_data->req); in ffs_user_copy_worker()
839 if (io_data->read) in ffs_user_copy_worker()
840 kfree(io_data->to_free); in ffs_user_copy_worker()
848 struct ffs_io_data *io_data = req->context; in ffs_epfile_async_io_complete()
849 struct ffs_data *ffs = io_data->ffs; in ffs_epfile_async_io_complete()
853 INIT_WORK(&io_data->work, ffs_user_copy_worker); in ffs_epfile_async_io_complete()
854 queue_work(ffs->io_completion_wq, &io_data->work); in ffs_epfile_async_io_complete()
863 struct ffs_buffer *buf = xchg(&epfile->read_buffer, READ_BUFFER_DROP); in __ffs_epfile_read_buffer_free()
868 /* Assumes epfile->mutex is held. */
873 * Null out epfile->read_buffer so ffs_func_eps_disable does not free in __ffs_epfile_read_buffered()
877 struct ffs_buffer *buf = xchg(&epfile->read_buffer, NULL); in __ffs_epfile_read_buffered()
882 ret = copy_to_iter(buf->data, buf->length, iter); in __ffs_epfile_read_buffered()
883 if (buf->length == ret) { in __ffs_epfile_read_buffered()
889 ret = -EFAULT; in __ffs_epfile_read_buffered()
891 buf->length -= ret; in __ffs_epfile_read_buffered()
892 buf->data += ret; in __ffs_epfile_read_buffered()
895 if (cmpxchg(&epfile->read_buffer, NULL, buf)) in __ffs_epfile_read_buffered()
901 /* Assumes epfile->mutex is held. */
913 return -EFAULT; in __ffs_epfile_read_data()
919 data_len -= ret; in __ffs_epfile_read_data()
922 return -ENOMEM; in __ffs_epfile_read_data()
923 buf->length = data_len; in __ffs_epfile_read_data()
924 buf->data = buf->storage; in __ffs_epfile_read_data()
925 memcpy(buf->storage, data + ret, data_len); in __ffs_epfile_read_data()
933 if (unlikely(cmpxchg(&epfile->read_buffer, NULL, buf))) in __ffs_epfile_read_data()
941 struct ffs_epfile *epfile = file->private_data; in ffs_epfile_io()
945 ssize_t ret, data_len = -EINVAL; in ffs_epfile_io()
949 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_io()
950 return -ENODEV; in ffs_epfile_io()
953 ep = epfile->ep; in ffs_epfile_io()
955 if (file->f_flags & O_NONBLOCK) in ffs_epfile_io()
956 return -EAGAIN; in ffs_epfile_io()
959 epfile->ffs->wait, (ep = epfile->ep)); in ffs_epfile_io()
961 return -EINTR; in ffs_epfile_io()
965 halt = (!io_data->read == !epfile->in); in ffs_epfile_io()
966 if (halt && epfile->isoc) in ffs_epfile_io()
967 return -EINVAL; in ffs_epfile_io()
970 ret = ffs_mutex_lock(&epfile->mutex, file->f_flags & O_NONBLOCK); in ffs_epfile_io()
985 if (!io_data->aio && io_data->read) { in ffs_epfile_io()
986 ret = __ffs_epfile_read_buffered(epfile, &io_data->data); in ffs_epfile_io()
992 * if we _do_ wait above, the epfile->ffs->gadget might be NULL in ffs_epfile_io()
996 gadget = epfile->ffs->gadget; in ffs_epfile_io()
998 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1000 if (epfile->ep != ep) { in ffs_epfile_io()
1001 ret = -ESHUTDOWN; in ffs_epfile_io()
1004 data_len = iov_iter_count(&io_data->data); in ffs_epfile_io()
1009 if (io_data->read) in ffs_epfile_io()
1010 data_len = usb_ep_align_maybe(gadget, ep->ep, data_len); in ffs_epfile_io()
1012 io_data->use_sg = gadget->sg_supported && data_len > PAGE_SIZE; in ffs_epfile_io()
1013 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1017 ret = -ENOMEM; in ffs_epfile_io()
1020 if (!io_data->read && in ffs_epfile_io()
1021 !copy_from_iter_full(data, data_len, &io_data->data)) { in ffs_epfile_io()
1022 ret = -EFAULT; in ffs_epfile_io()
1027 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1029 if (epfile->ep != ep) { in ffs_epfile_io()
1031 ret = -ESHUTDOWN; in ffs_epfile_io()
1033 ret = usb_ep_set_halt(ep->ep); in ffs_epfile_io()
1035 ret = -EBADMSG; in ffs_epfile_io()
1036 } else if (unlikely(data_len == -EINVAL)) { in ffs_epfile_io()
1042 * being initialized to -EINVAL during its declaration, which in ffs_epfile_io()
1048 WARN(1, "%s: data_len == -EINVAL\n", __func__); in ffs_epfile_io()
1049 ret = -EINVAL; in ffs_epfile_io()
1050 } else if (!io_data->aio) { in ffs_epfile_io()
1054 req = ep->req; in ffs_epfile_io()
1055 if (io_data->use_sg) { in ffs_epfile_io()
1056 req->buf = NULL; in ffs_epfile_io()
1057 req->sg = io_data->sgt.sgl; in ffs_epfile_io()
1058 req->num_sgs = io_data->sgt.nents; in ffs_epfile_io()
1060 req->buf = data; in ffs_epfile_io()
1061 req->num_sgs = 0; in ffs_epfile_io()
1063 req->length = data_len; in ffs_epfile_io()
1065 io_data->buf = data; in ffs_epfile_io()
1067 req->context = &done; in ffs_epfile_io()
1068 req->complete = ffs_epfile_io_complete; in ffs_epfile_io()
1070 ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC); in ffs_epfile_io()
1074 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1081 * condition with req->complete callback. in ffs_epfile_io()
1083 usb_ep_dequeue(ep->ep, req); in ffs_epfile_io()
1085 interrupted = ep->status < 0; in ffs_epfile_io()
1089 ret = -EINTR; in ffs_epfile_io()
1090 else if (io_data->read && ep->status > 0) in ffs_epfile_io()
1091 ret = __ffs_epfile_read_data(epfile, data, ep->status, in ffs_epfile_io()
1092 &io_data->data); in ffs_epfile_io()
1094 ret = ep->status; in ffs_epfile_io()
1096 } else if (!(req = usb_ep_alloc_request(ep->ep, GFP_ATOMIC))) { in ffs_epfile_io()
1097 ret = -ENOMEM; in ffs_epfile_io()
1099 if (io_data->use_sg) { in ffs_epfile_io()
1100 req->buf = NULL; in ffs_epfile_io()
1101 req->sg = io_data->sgt.sgl; in ffs_epfile_io()
1102 req->num_sgs = io_data->sgt.nents; in ffs_epfile_io()
1104 req->buf = data; in ffs_epfile_io()
1105 req->num_sgs = 0; in ffs_epfile_io()
1107 req->length = data_len; in ffs_epfile_io()
1109 io_data->buf = data; in ffs_epfile_io()
1110 io_data->ep = ep->ep; in ffs_epfile_io()
1111 io_data->req = req; in ffs_epfile_io()
1112 io_data->ffs = epfile->ffs; in ffs_epfile_io()
1114 req->context = io_data; in ffs_epfile_io()
1115 req->complete = ffs_epfile_async_io_complete; in ffs_epfile_io()
1117 ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC); in ffs_epfile_io()
1119 io_data->req = NULL; in ffs_epfile_io()
1120 usb_ep_free_request(ep->ep, req); in ffs_epfile_io()
1124 ret = -EIOCBQUEUED; in ffs_epfile_io()
1133 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_io()
1135 mutex_unlock(&epfile->mutex); in ffs_epfile_io()
1137 if (ret != -EIOCBQUEUED) /* don't free if there is iocb queued */ in ffs_epfile_io()
1145 struct ffs_epfile *epfile = inode->i_private; in ffs_epfile_open()
1149 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_open()
1150 return -ENODEV; in ffs_epfile_open()
1152 file->private_data = epfile; in ffs_epfile_open()
1153 ffs_data_opened(epfile->ffs); in ffs_epfile_open()
1160 struct ffs_io_data *io_data = kiocb->private; in ffs_aio_cancel()
1161 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 (likely(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()
1189 return -ENOMEM; in ffs_epfile_write_iter()
1190 p->aio = true; in ffs_epfile_write_iter()
1193 p->aio = false; in ffs_epfile_write_iter()
1196 p->read = false; in ffs_epfile_write_iter()
1197 p->kiocb = kiocb; in ffs_epfile_write_iter()
1198 p->data = *from; in ffs_epfile_write_iter()
1199 p->mm = current->mm; in ffs_epfile_write_iter()
1201 kiocb->private = p; in ffs_epfile_write_iter()
1203 if (p->aio) in ffs_epfile_write_iter()
1206 res = ffs_epfile_io(kiocb->ki_filp, p); in ffs_epfile_write_iter()
1207 if (res == -EIOCBQUEUED) in ffs_epfile_write_iter()
1209 if (p->aio) in ffs_epfile_write_iter()
1212 *from = p->data; in ffs_epfile_write_iter()
1226 return -ENOMEM; in ffs_epfile_read_iter()
1227 p->aio = true; in ffs_epfile_read_iter()
1230 p->aio = false; in ffs_epfile_read_iter()
1233 p->read = true; in ffs_epfile_read_iter()
1234 p->kiocb = kiocb; in ffs_epfile_read_iter()
1235 if (p->aio) { in ffs_epfile_read_iter()
1236 p->to_free = dup_iter(&p->data, to, GFP_KERNEL); in ffs_epfile_read_iter()
1237 if (!p->to_free) { in ffs_epfile_read_iter()
1239 return -ENOMEM; in ffs_epfile_read_iter()
1242 p->data = *to; in ffs_epfile_read_iter()
1243 p->to_free = NULL; in ffs_epfile_read_iter()
1245 p->mm = current->mm; in ffs_epfile_read_iter()
1247 kiocb->private = p; in ffs_epfile_read_iter()
1249 if (p->aio) in ffs_epfile_read_iter()
1252 res = ffs_epfile_io(kiocb->ki_filp, p); in ffs_epfile_read_iter()
1253 if (res == -EIOCBQUEUED) in ffs_epfile_read_iter()
1256 if (p->aio) { in ffs_epfile_read_iter()
1257 kfree(p->to_free); in ffs_epfile_read_iter()
1260 *to = p->data; in ffs_epfile_read_iter()
1268 struct ffs_epfile *epfile = inode->i_private; in ffs_epfile_release()
1273 ffs_data_closed(epfile->ffs); in ffs_epfile_release()
1281 struct ffs_epfile *epfile = file->private_data; in ffs_epfile_ioctl()
1287 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) in ffs_epfile_ioctl()
1288 return -ENODEV; in ffs_epfile_ioctl()
1291 ep = epfile->ep; in ffs_epfile_ioctl()
1293 if (file->f_flags & O_NONBLOCK) in ffs_epfile_ioctl()
1294 return -EAGAIN; in ffs_epfile_ioctl()
1297 epfile->ffs->wait, (ep = epfile->ep)); in ffs_epfile_ioctl()
1299 return -EINTR; in ffs_epfile_ioctl()
1302 spin_lock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1305 if (epfile->ep != ep) { in ffs_epfile_ioctl()
1306 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1307 return -ESHUTDOWN; in ffs_epfile_ioctl()
1312 ret = usb_ep_fifo_status(epfile->ep->ep); in ffs_epfile_ioctl()
1315 usb_ep_fifo_flush(epfile->ep->ep); in ffs_epfile_ioctl()
1319 ret = usb_ep_clear_halt(epfile->ep->ep); in ffs_epfile_ioctl()
1322 ret = epfile->ep->num; in ffs_epfile_ioctl()
1329 switch (epfile->ffs->gadget->speed) { in ffs_epfile_ioctl()
1340 desc = epfile->ep->descs[desc_idx]; in ffs_epfile_ioctl()
1341 memcpy(&desc1, desc, desc->bLength); in ffs_epfile_ioctl()
1343 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1346 ret = -EFAULT; in ffs_epfile_ioctl()
1350 ret = -ENOTTY; in ffs_epfile_ioctl()
1352 spin_unlock_irq(&epfile->ffs->eps_lock); in ffs_epfile_ioctl()
1391 inode->i_ino = get_next_ino(); in ffs_sb_make_inode()
1392 inode->i_mode = perms->mode; in ffs_sb_make_inode()
1393 inode->i_uid = perms->uid; in ffs_sb_make_inode()
1394 inode->i_gid = perms->gid; in ffs_sb_make_inode()
1395 inode->i_atime = ts; in ffs_sb_make_inode()
1396 inode->i_mtime = ts; in ffs_sb_make_inode()
1397 inode->i_ctime = ts; in ffs_sb_make_inode()
1398 inode->i_private = data; in ffs_sb_make_inode()
1400 inode->i_fop = fops; in ffs_sb_make_inode()
1402 inode->i_op = iops; in ffs_sb_make_inode()
1413 struct ffs_data *ffs = sb->s_fs_info; in ffs_sb_create_file()
1419 dentry = d_alloc_name(sb->s_root, name); in ffs_sb_create_file()
1423 inode = ffs_sb_make_inode(sb, data, fops, NULL, &ffs->file_perms); in ffs_sb_create_file()
1449 struct ffs_sb_fill_data *data = fc->fs_private; in ffs_sb_fill()
1451 struct ffs_data *ffs = data->ffs_data; in ffs_sb_fill()
1455 ffs->sb = sb; in ffs_sb_fill()
1456 data->ffs_data = NULL; in ffs_sb_fill()
1457 sb->s_fs_info = ffs; in ffs_sb_fill()
1458 sb->s_blocksize = PAGE_SIZE; in ffs_sb_fill()
1459 sb->s_blocksize_bits = PAGE_SHIFT; in ffs_sb_fill()
1460 sb->s_magic = FUNCTIONFS_MAGIC; in ffs_sb_fill()
1461 sb->s_op = &ffs_sb_operations; in ffs_sb_fill()
1462 sb->s_time_gran = 1; in ffs_sb_fill()
1465 data->perms.mode = data->root_mode; in ffs_sb_fill()
1469 &data->perms); in ffs_sb_fill()
1470 sb->s_root = d_make_root(inode); in ffs_sb_fill()
1471 if (unlikely(!sb->s_root)) in ffs_sb_fill()
1472 return -ENOMEM; in ffs_sb_fill()
1477 return -ENOMEM; in ffs_sb_fill()
1503 struct ffs_sb_fill_data *data = fc->fs_private; in ffs_fs_parse_param()
1515 data->no_disconnect = result.boolean; in ffs_fs_parse_param()
1518 data->root_mode = (result.uint_32 & 0555) | S_IFDIR; in ffs_fs_parse_param()
1521 data->perms.mode = (result.uint_32 & 0666) | S_IFREG; in ffs_fs_parse_param()
1524 data->root_mode = (result.uint_32 & 0555) | S_IFDIR; in ffs_fs_parse_param()
1525 data->perms.mode = (result.uint_32 & 0666) | S_IFREG; in ffs_fs_parse_param()
1529 data->perms.uid = make_kuid(current_user_ns(), result.uint_32); in ffs_fs_parse_param()
1530 if (!uid_valid(data->perms.uid)) in ffs_fs_parse_param()
1534 data->perms.gid = make_kgid(current_user_ns(), result.uint_32); in ffs_fs_parse_param()
1535 if (!gid_valid(data->perms.gid)) in ffs_fs_parse_param()
1540 return -ENOPARAM; in ffs_fs_parse_param()
1546 return invalf(fc, "%s: unmapped value: %u", param->key, result.uint_32); in ffs_fs_parse_param()
1554 struct ffs_sb_fill_data *ctx = fc->fs_private; in ffs_fs_get_tree()
1560 if (!fc->source) in ffs_fs_get_tree()
1563 ffs = ffs_data_new(fc->source); in ffs_fs_get_tree()
1565 return -ENOMEM; in ffs_fs_get_tree()
1566 ffs->file_perms = ctx->perms; in ffs_fs_get_tree()
1567 ffs->no_disconnect = ctx->no_disconnect; in ffs_fs_get_tree()
1569 ffs->dev_name = kstrdup(fc->source, GFP_KERNEL); in ffs_fs_get_tree()
1570 if (unlikely(!ffs->dev_name)) { in ffs_fs_get_tree()
1572 return -ENOMEM; in ffs_fs_get_tree()
1575 ffs_dev = ffs_acquire_dev(ffs->dev_name); in ffs_fs_get_tree()
1581 ffs->private_data = ffs_dev; in ffs_fs_get_tree()
1582 ctx->ffs_data = ffs; in ffs_fs_get_tree()
1588 struct ffs_sb_fill_data *ctx = fc->fs_private; in ffs_fs_free_fc()
1591 if (ctx->ffs_data) { in ffs_fs_free_fc()
1592 ffs_release_dev(ctx->ffs_data); in ffs_fs_free_fc()
1593 ffs_data_put(ctx->ffs_data); in ffs_fs_free_fc()
1612 return -ENOMEM; in ffs_fs_init_fs_context()
1614 ctx->perms.mode = S_IFREG | 0600; in ffs_fs_init_fs_context()
1615 ctx->perms.uid = GLOBAL_ROOT_UID; in ffs_fs_init_fs_context()
1616 ctx->perms.gid = GLOBAL_ROOT_GID; in ffs_fs_init_fs_context()
1617 ctx->root_mode = S_IFDIR | 0500; in ffs_fs_init_fs_context()
1618 ctx->no_disconnect = false; in ffs_fs_init_fs_context()
1620 fc->fs_private = ctx; in ffs_fs_init_fs_context()
1621 fc->ops = &ffs_fs_context_ops; in ffs_fs_init_fs_context()
1631 if (sb->s_fs_info) { in ffs_fs_kill_sb()
1632 ffs_release_dev(sb->s_fs_info); in ffs_fs_kill_sb()
1633 ffs_data_closed(sb->s_fs_info); in ffs_fs_kill_sb()
1682 refcount_inc(&ffs->ref); in ffs_data_get()
1689 refcount_inc(&ffs->ref); in ffs_data_opened()
1690 if (atomic_add_return(1, &ffs->opened) == 1 && in ffs_data_opened()
1691 ffs->state == FFS_DEACTIVATED) { in ffs_data_opened()
1692 ffs->state = FFS_CLOSING; in ffs_data_opened()
1701 if (unlikely(refcount_dec_and_test(&ffs->ref))) { in ffs_data_put()
1704 BUG_ON(waitqueue_active(&ffs->ev.waitq) || in ffs_data_put()
1705 swait_active(&ffs->ep0req_completion.wait) || in ffs_data_put()
1706 waitqueue_active(&ffs->wait)); in ffs_data_put()
1707 destroy_workqueue(ffs->io_completion_wq); in ffs_data_put()
1708 kfree(ffs->dev_name); in ffs_data_put()
1717 if (atomic_dec_and_test(&ffs->opened)) { in ffs_data_closed()
1718 if (ffs->no_disconnect) { in ffs_data_closed()
1719 ffs->state = FFS_DEACTIVATED; in ffs_data_closed()
1720 if (ffs->epfiles) { in ffs_data_closed()
1721 ffs_epfiles_destroy(ffs->epfiles, in ffs_data_closed()
1722 ffs->eps_count); in ffs_data_closed()
1723 ffs->epfiles = NULL; in ffs_data_closed()
1725 if (ffs->setup_state == FFS_SETUP_PENDING) in ffs_data_closed()
1728 ffs->state = FFS_CLOSING; in ffs_data_closed()
1732 if (atomic_read(&ffs->opened) < 0) { in ffs_data_closed()
1733 ffs->state = FFS_CLOSING; in ffs_data_closed()
1748 ffs->io_completion_wq = alloc_ordered_workqueue("%s", 0, dev_name); in ffs_data_new()
1749 if (!ffs->io_completion_wq) { in ffs_data_new()
1754 refcount_set(&ffs->ref, 1); in ffs_data_new()
1755 atomic_set(&ffs->opened, 0); in ffs_data_new()
1756 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_new()
1757 mutex_init(&ffs->mutex); in ffs_data_new()
1758 spin_lock_init(&ffs->eps_lock); in ffs_data_new()
1759 init_waitqueue_head(&ffs->ev.waitq); in ffs_data_new()
1760 init_waitqueue_head(&ffs->wait); in ffs_data_new()
1761 init_completion(&ffs->ep0req_completion); in ffs_data_new()
1764 ffs->ev.can_stall = 1; in ffs_data_new()
1775 BUG_ON(ffs->gadget); in ffs_data_clear()
1777 if (ffs->epfiles) in ffs_data_clear()
1778 ffs_epfiles_destroy(ffs->epfiles, ffs->eps_count); in ffs_data_clear()
1780 if (ffs->ffs_eventfd) in ffs_data_clear()
1781 eventfd_ctx_put(ffs->ffs_eventfd); in ffs_data_clear()
1783 kfree(ffs->raw_descs_data); in ffs_data_clear()
1784 kfree(ffs->raw_strings); in ffs_data_clear()
1785 kfree(ffs->stringtabs); in ffs_data_clear()
1794 ffs->epfiles = NULL; in ffs_data_reset()
1795 ffs->raw_descs_data = NULL; in ffs_data_reset()
1796 ffs->raw_descs = NULL; in ffs_data_reset()
1797 ffs->raw_strings = NULL; in ffs_data_reset()
1798 ffs->stringtabs = NULL; in ffs_data_reset()
1800 ffs->raw_descs_length = 0; in ffs_data_reset()
1801 ffs->fs_descs_count = 0; in ffs_data_reset()
1802 ffs->hs_descs_count = 0; in ffs_data_reset()
1803 ffs->ss_descs_count = 0; in ffs_data_reset()
1805 ffs->strings_count = 0; in ffs_data_reset()
1806 ffs->interfaces_count = 0; in ffs_data_reset()
1807 ffs->eps_count = 0; in ffs_data_reset()
1809 ffs->ev.count = 0; in ffs_data_reset()
1811 ffs->state = FFS_READ_DESCRIPTORS; in ffs_data_reset()
1812 ffs->setup_state = FFS_NO_SETUP; in ffs_data_reset()
1813 ffs->flags = 0; in ffs_data_reset()
1815 ffs->ms_os_descs_ext_prop_count = 0; in ffs_data_reset()
1816 ffs->ms_os_descs_ext_prop_name_len = 0; in ffs_data_reset()
1817 ffs->ms_os_descs_ext_prop_data_len = 0; in ffs_data_reset()
1828 if (WARN_ON(ffs->state != FFS_ACTIVE in functionfs_bind()
1829 || test_and_set_bit(FFS_FL_BOUND, &ffs->flags))) in functionfs_bind()
1830 return -EBADFD; in functionfs_bind()
1832 first_id = usb_string_ids_n(cdev, ffs->strings_count); in functionfs_bind()
1836 ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL); in functionfs_bind()
1837 if (unlikely(!ffs->ep0req)) in functionfs_bind()
1838 return -ENOMEM; in functionfs_bind()
1839 ffs->ep0req->complete = ffs_ep0_complete; in functionfs_bind()
1840 ffs->ep0req->context = ffs; in functionfs_bind()
1842 lang = ffs->stringtabs; in functionfs_bind()
1845 struct usb_string *str = (*lang)->strings; in functionfs_bind()
1847 for (; str->s; ++id, ++str) in functionfs_bind()
1848 str->id = id; in functionfs_bind()
1852 ffs->gadget = cdev->gadget; in functionfs_bind()
1861 if (!WARN_ON(!ffs->gadget)) { in functionfs_unbind()
1862 usb_ep_free_request(ffs->gadget->ep0, ffs->ep0req); in functionfs_unbind()
1863 ffs->ep0req = NULL; in functionfs_unbind()
1864 ffs->gadget = NULL; in functionfs_unbind()
1865 clear_bit(FFS_FL_BOUND, &ffs->flags); in functionfs_unbind()
1877 count = ffs->eps_count; in ffs_epfiles_create()
1880 return -ENOMEM; in ffs_epfiles_create()
1884 epfile->ffs = ffs; in ffs_epfiles_create()
1885 mutex_init(&epfile->mutex); in ffs_epfiles_create()
1886 if (ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_epfiles_create()
1887 sprintf(epfile->name, "ep%02x", ffs->eps_addrmap[i]); in ffs_epfiles_create()
1889 sprintf(epfile->name, "ep%u", i); in ffs_epfiles_create()
1890 epfile->dentry = ffs_sb_create_file(ffs->sb, epfile->name, in ffs_epfiles_create()
1893 if (unlikely(!epfile->dentry)) { in ffs_epfiles_create()
1894 ffs_epfiles_destroy(epfiles, i - 1); in ffs_epfiles_create()
1895 return -ENOMEM; in ffs_epfiles_create()
1899 ffs->epfiles = epfiles; in ffs_epfiles_create()
1909 for (; count; --count, ++epfile) { in ffs_epfiles_destroy()
1910 BUG_ON(mutex_is_locked(&epfile->mutex)); in ffs_epfiles_destroy()
1911 if (epfile->dentry) { in ffs_epfiles_destroy()
1912 d_delete(epfile->dentry); in ffs_epfiles_destroy()
1913 dput(epfile->dentry); in ffs_epfiles_destroy()
1914 epfile->dentry = NULL; in ffs_epfiles_destroy()
1923 struct ffs_ep *ep = func->eps; in ffs_func_eps_disable()
1924 struct ffs_epfile *epfile = func->ffs->epfiles; in ffs_func_eps_disable()
1925 unsigned count = func->ffs->eps_count; in ffs_func_eps_disable()
1928 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
1929 while (count--) { in ffs_func_eps_disable()
1931 if (likely(ep->ep)) in ffs_func_eps_disable()
1932 usb_ep_disable(ep->ep); in ffs_func_eps_disable()
1936 epfile->ep = NULL; in ffs_func_eps_disable()
1941 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_disable()
1946 struct ffs_data *ffs = func->ffs; in ffs_func_eps_enable()
1947 struct ffs_ep *ep = func->eps; in ffs_func_eps_enable()
1948 struct ffs_epfile *epfile = ffs->epfiles; in ffs_func_eps_enable()
1949 unsigned count = ffs->eps_count; in ffs_func_eps_enable()
1953 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
1954 while(count--) { in ffs_func_eps_enable()
1955 ep->ep->driver_data = ep; in ffs_func_eps_enable()
1957 ret = config_ep_by_speed(func->gadget, &func->function, ep->ep); in ffs_func_eps_enable()
1960 __func__, ep->ep->name, ret); in ffs_func_eps_enable()
1964 ret = usb_ep_enable(ep->ep); in ffs_func_eps_enable()
1966 epfile->ep = ep; in ffs_func_eps_enable()
1967 epfile->in = usb_endpoint_dir_in(ep->ep->desc); in ffs_func_eps_enable()
1968 epfile->isoc = usb_endpoint_xfer_isoc(ep->ep->desc); in ffs_func_eps_enable()
1977 wake_up_interruptible(&ffs->wait); in ffs_func_eps_enable()
1978 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_eps_enable()
1984 /* Parsing and building descriptors and strings *****************************/
1988 * well as record how many interfaces, endpoints and strings are
2023 return -EINVAL; in ffs_do_single_desc()
2027 length = _ds->bLength; in ffs_do_single_desc()
2030 return -EINVAL; in ffs_do_single_desc()
2040 return -EINVAL; \ in ffs_do_single_desc()
2051 switch (_ds->bDescriptorType) { in ffs_do_single_desc()
2058 _ds->bDescriptorType); in ffs_do_single_desc()
2059 return -EINVAL; in ffs_do_single_desc()
2067 __entity(INTERFACE, ds->bInterfaceNumber); in ffs_do_single_desc()
2068 if (ds->iInterface) in ffs_do_single_desc()
2069 __entity(STRING, ds->iInterface); in ffs_do_single_desc()
2070 *current_class = ds->bInterfaceClass; in ffs_do_single_desc()
2080 __entity(ENDPOINT, ds->bEndpointAddress); in ffs_do_single_desc()
2097 _ds->bDescriptorType, *current_class); in ffs_do_single_desc()
2098 return -EINVAL; in ffs_do_single_desc()
2111 if (ds->iFunction) in ffs_do_single_desc()
2112 __entity(STRING, ds->iFunction); in ffs_do_single_desc()
2128 pr_vdebug("unimplemented descriptor: %d\n", _ds->bDescriptorType); in ffs_do_single_desc()
2129 return -EINVAL; in ffs_do_single_desc()
2133 pr_vdebug("unknown descriptor: %d\n", _ds->bDescriptorType); in ffs_do_single_desc()
2134 return -EINVAL; in ffs_do_single_desc()
2138 _ds->bLength, _ds->bDescriptorType); in ffs_do_single_desc()
2139 return -EINVAL; in ffs_do_single_desc()
2155 unsigned long num = 0; in ffs_do_descs() local
2156 int current_class = -1; in ffs_do_descs()
2163 if (num == count) in ffs_do_descs()
2167 ret = entity(FFS_DESCRIPTOR, (u8 *)num, (void *)data, priv); in ffs_do_descs()
2170 num, ret); in ffs_do_descs()
2175 return _len - len; in ffs_do_descs()
2184 len -= ret; in ffs_do_descs()
2186 ++num; in ffs_do_descs()
2209 if (*valuep >= helper->interfaces_count) in __ffs_data_do_entity()
2210 helper->interfaces_count = *valuep + 1; in __ffs_data_do_entity()
2215 * Strings are indexed from 1 (0 is reserved in __ffs_data_do_entity()
2218 if (*valuep > helper->ffs->strings_count) in __ffs_data_do_entity()
2219 helper->ffs->strings_count = *valuep; in __ffs_data_do_entity()
2224 helper->eps_count++; in __ffs_data_do_entity()
2225 if (helper->eps_count >= FFS_MAX_EPS_COUNT) in __ffs_data_do_entity()
2226 return -EINVAL; in __ffs_data_do_entity()
2228 if (!helper->ffs->eps_count && !helper->ffs->interfaces_count) in __ffs_data_do_entity()
2229 helper->ffs->eps_addrmap[helper->eps_count] = in __ffs_data_do_entity()
2230 d->bEndpointAddress; in __ffs_data_do_entity()
2231 else if (helper->ffs->eps_addrmap[helper->eps_count] != in __ffs_data_do_entity()
2232 d->bEndpointAddress) in __ffs_data_do_entity()
2233 return -EINVAL; in __ffs_data_do_entity()
2243 u16 bcd_version = le16_to_cpu(desc->bcdVersion); in __ffs_do_os_desc_header()
2244 u16 w_index = le16_to_cpu(desc->wIndex); in __ffs_do_os_desc_header()
2249 return -EINVAL; in __ffs_do_os_desc_header()
2260 return -EINVAL; in __ffs_do_os_desc_header()
2283 while (feature_count--) { in ffs_do_single_os_desc()
2290 len -= ret; in ffs_do_single_os_desc()
2292 return _len - len; in ffs_do_single_os_desc()
2301 unsigned long num = 0; in ffs_do_os_descs() local
2305 for (num = 0; num < count; ++num) { in ffs_do_os_descs()
2312 return -EINVAL; in ffs_do_os_descs()
2321 if (le32_to_cpu(desc->dwLength) > len) in ffs_do_os_descs()
2322 return -EINVAL; in ffs_do_os_descs()
2327 num, ret); in ffs_do_os_descs()
2331 * 16-bit hex "?? 00" Little Endian looks like 8-bit hex "??" in ffs_do_os_descs()
2333 feature_count = le16_to_cpu(desc->wCount); in ffs_do_os_descs()
2335 (feature_count > 255 || desc->Reserved)) in ffs_do_os_descs()
2336 return -EINVAL; in ffs_do_os_descs()
2337 len -= ret; in ffs_do_os_descs()
2351 len -= ret; in ffs_do_os_descs()
2354 return _len - len; in ffs_do_os_descs()
2375 d->bFirstInterfaceNumber >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2376 return -EINVAL; in __ffs_data_do_os_desc()
2377 if (d->Reserved1 != 1) { in __ffs_data_do_os_desc()
2380 * but older kernels incorrectly rejected non-zero in __ffs_data_do_os_desc()
2385 d->Reserved1 = 1; in __ffs_data_do_os_desc()
2387 for (i = 0; i < ARRAY_SIZE(d->Reserved2); ++i) in __ffs_data_do_os_desc()
2388 if (d->Reserved2[i]) in __ffs_data_do_os_desc()
2389 return -EINVAL; in __ffs_data_do_os_desc()
2399 if (len < sizeof(*d) || h->interface >= ffs->interfaces_count) in __ffs_data_do_os_desc()
2400 return -EINVAL; in __ffs_data_do_os_desc()
2401 length = le32_to_cpu(d->dwSize); in __ffs_data_do_os_desc()
2403 return -EINVAL; in __ffs_data_do_os_desc()
2404 type = le32_to_cpu(d->dwPropertyDataType); in __ffs_data_do_os_desc()
2409 return -EINVAL; in __ffs_data_do_os_desc()
2411 pnl = le16_to_cpu(d->wPropertyNameLength); in __ffs_data_do_os_desc()
2415 return -EINVAL; in __ffs_data_do_os_desc()
2421 return -EINVAL; in __ffs_data_do_os_desc()
2423 ++ffs->ms_os_descs_ext_prop_count; in __ffs_data_do_os_desc()
2425 ffs->ms_os_descs_ext_prop_name_len += pnl * 2; in __ffs_data_do_os_desc()
2426 ffs->ms_os_descs_ext_prop_data_len += pdl; in __ffs_data_do_os_desc()
2431 return -EINVAL; in __ffs_data_do_os_desc()
2441 int ret = -EINVAL, i; in __ffs_data_got_descs()
2453 len -= 8; in __ffs_data_got_descs()
2457 ffs->user_flags = flags; in __ffs_data_got_descs()
2466 ret = -ENOSYS; in __ffs_data_got_descs()
2470 len -= 12; in __ffs_data_got_descs()
2479 ffs->ffs_eventfd = in __ffs_data_got_descs()
2481 if (IS_ERR(ffs->ffs_eventfd)) { in __ffs_data_got_descs()
2482 ret = PTR_ERR(ffs->ffs_eventfd); in __ffs_data_got_descs()
2483 ffs->ffs_eventfd = NULL; in __ffs_data_got_descs()
2487 len -= 4; in __ffs_data_got_descs()
2499 len -= 4; in __ffs_data_got_descs()
2508 len -= 4; in __ffs_data_got_descs()
2523 if (!ffs->eps_count && !ffs->interfaces_count) { in __ffs_data_got_descs()
2524 ffs->eps_count = helper.eps_count; in __ffs_data_got_descs()
2525 ffs->interfaces_count = helper.interfaces_count; in __ffs_data_got_descs()
2527 if (ffs->eps_count != helper.eps_count) { in __ffs_data_got_descs()
2528 ret = -EINVAL; in __ffs_data_got_descs()
2531 if (ffs->interfaces_count != helper.interfaces_count) { in __ffs_data_got_descs()
2532 ret = -EINVAL; in __ffs_data_got_descs()
2537 len -= ret; in __ffs_data_got_descs()
2545 len -= ret; in __ffs_data_got_descs()
2549 ret = -EINVAL; in __ffs_data_got_descs()
2553 ffs->raw_descs_data = _data; in __ffs_data_got_descs()
2554 ffs->raw_descs = raw_descs; in __ffs_data_got_descs()
2555 ffs->raw_descs_length = data - raw_descs; in __ffs_data_got_descs()
2556 ffs->fs_descs_count = counts[0]; in __ffs_data_got_descs()
2557 ffs->hs_descs_count = counts[1]; in __ffs_data_got_descs()
2558 ffs->ss_descs_count = counts[2]; in __ffs_data_got_descs()
2559 ffs->ms_os_descs_count = os_descs_count; in __ffs_data_got_descs()
2589 /* Do we have at least as many strings as descriptors need? */ in __ffs_data_got_strings()
2590 needed_count = ffs->strings_count; in __ffs_data_got_strings()
2595 * If we don't need any strings just return and free all in __ffs_data_got_strings()
2610 vla_item(d, struct usb_string, strings, in __ffs_data_got_strings()
2617 return -ENOMEM; in __ffs_data_got_strings()
2626 } while (--i); in __ffs_data_got_strings()
2632 s = vla_ptr(vlabuf, d, strings); in __ffs_data_got_strings()
2637 len -= 16; in __ffs_data_got_strings()
2639 do { /* lang_count > 0 so we can use do-while */ in __ffs_data_got_strings()
2644 t->language = get_unaligned_le16(data); in __ffs_data_got_strings()
2645 t->strings = s; in __ffs_data_got_strings()
2649 len -= 2; in __ffs_data_got_strings()
2652 do { /* str_count > 0 so we can use do-while */ in __ffs_data_got_strings()
2659 * User may provide more strings then we need, in __ffs_data_got_strings()
2665 * s->id will be set while adding in __ffs_data_got_strings()
2669 s->s = data; in __ffs_data_got_strings()
2670 --needed; in __ffs_data_got_strings()
2675 len -= length + 1; in __ffs_data_got_strings()
2676 } while (--str_count); in __ffs_data_got_strings()
2678 s->id = 0; /* terminator */ in __ffs_data_got_strings()
2679 s->s = NULL; in __ffs_data_got_strings()
2682 } while (--lang_count); in __ffs_data_got_strings()
2689 ffs->stringtabs = stringtabs; in __ffs_data_got_strings()
2690 ffs->raw_strings = _data; in __ffs_data_got_strings()
2698 return -EINVAL; in __ffs_data_got_strings()
2714 * of ffs->setup_state without holding the lock because when in __ffs_event_add()
2718 if (ffs->setup_state == FFS_SETUP_PENDING) in __ffs_event_add()
2719 ffs->setup_state = FFS_SETUP_CANCELLED; in __ffs_event_add()
2723 * evens on ffs->ev.types queue. This is important because the queue in __ffs_event_add()
2754 u8 *ev = ffs->ev.types, *out = ev; in __ffs_event_add()
2755 unsigned n = ffs->ev.count; in __ffs_event_add()
2756 for (; n; --n, ++ev) in __ffs_event_add()
2761 ffs->ev.count = out - ffs->ev.types; in __ffs_event_add()
2765 ffs->ev.types[ffs->ev.count++] = type; in __ffs_event_add()
2766 wake_up_locked(&ffs->ev.waitq); in __ffs_event_add()
2767 if (ffs->ffs_eventfd) in __ffs_event_add()
2768 eventfd_signal(ffs->ffs_eventfd, 1); in __ffs_event_add()
2775 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_event_add()
2777 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_event_add()
2786 for (i = 1; i < ARRAY_SIZE(ffs->eps_addrmap); ++i) in ffs_ep_addr2idx()
2787 if (ffs->eps_addrmap[i] == endpoint_address) in ffs_ep_addr2idx()
2789 return -ENOENT; in ffs_ep_addr2idx()
2812 if (func->function.ss_descriptors) { in __ffs_func_bind_do_descs()
2814 func->function.ss_descriptors[(long)valuep] = desc; in __ffs_func_bind_do_descs()
2815 } else if (func->function.hs_descriptors) { in __ffs_func_bind_do_descs()
2817 func->function.hs_descriptors[(long)valuep] = desc; in __ffs_func_bind_do_descs()
2820 func->function.fs_descriptors[(long)valuep] = desc; in __ffs_func_bind_do_descs()
2823 if (!desc || desc->bDescriptorType != USB_DT_ENDPOINT) in __ffs_func_bind_do_descs()
2826 idx = ffs_ep_addr2idx(func->ffs, ds->bEndpointAddress) - 1; in __ffs_func_bind_do_descs()
2830 ffs_ep = func->eps + idx; in __ffs_func_bind_do_descs()
2832 if (unlikely(ffs_ep->descs[ep_desc_id])) { in __ffs_func_bind_do_descs()
2835 ds->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); in __ffs_func_bind_do_descs()
2836 return -EINVAL; in __ffs_func_bind_do_descs()
2838 ffs_ep->descs[ep_desc_id] = ds; in __ffs_func_bind_do_descs()
2840 ffs_dump_mem(": Original ep desc", ds, ds->bLength); in __ffs_func_bind_do_descs()
2841 if (ffs_ep->ep) { in __ffs_func_bind_do_descs()
2842 ds->bEndpointAddress = ffs_ep->descs[0]->bEndpointAddress; in __ffs_func_bind_do_descs()
2843 if (!ds->wMaxPacketSize) in __ffs_func_bind_do_descs()
2844 ds->wMaxPacketSize = ffs_ep->descs[0]->wMaxPacketSize; in __ffs_func_bind_do_descs()
2855 bEndpointAddress = ds->bEndpointAddress; in __ffs_func_bind_do_descs()
2860 wMaxPacketSize = ds->wMaxPacketSize; in __ffs_func_bind_do_descs()
2862 ep = usb_ep_autoconfig(func->gadget, ds); in __ffs_func_bind_do_descs()
2864 return -ENOTSUPP; in __ffs_func_bind_do_descs()
2865 ep->driver_data = func->eps + idx; in __ffs_func_bind_do_descs()
2869 return -ENOMEM; in __ffs_func_bind_do_descs()
2871 ffs_ep->ep = ep; in __ffs_func_bind_do_descs()
2872 ffs_ep->req = req; in __ffs_func_bind_do_descs()
2873 func->eps_revmap[ds->bEndpointAddress & in __ffs_func_bind_do_descs()
2879 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in __ffs_func_bind_do_descs()
2880 ds->bEndpointAddress = bEndpointAddress; in __ffs_func_bind_do_descs()
2885 ds->wMaxPacketSize = wMaxPacketSize; in __ffs_func_bind_do_descs()
2887 ffs_dump_mem(": Rewritten ep desc", ds, ds->bLength); in __ffs_func_bind_do_descs()
2908 if (func->interfaces_nums[idx] < 0) { in __ffs_func_bind_do_nums()
2909 int id = usb_interface_id(func->conf, &func->function); in __ffs_func_bind_do_nums()
2912 func->interfaces_nums[idx] = id; in __ffs_func_bind_do_nums()
2914 newValue = func->interfaces_nums[idx]; in __ffs_func_bind_do_nums()
2919 newValue = func->ffs->stringtabs[0]->strings[*valuep - 1].id; in __ffs_func_bind_do_nums()
2927 if (desc->bDescriptorType == USB_DT_ENDPOINT) in __ffs_func_bind_do_nums()
2930 idx = (*valuep & USB_ENDPOINT_NUMBER_MASK) - 1; in __ffs_func_bind_do_nums()
2931 if (unlikely(!func->eps[idx].ep)) in __ffs_func_bind_do_nums()
2932 return -EINVAL; in __ffs_func_bind_do_nums()
2936 descs = func->eps[idx].descs; in __ffs_func_bind_do_nums()
2937 newValue = descs[descs[0] ? 0 : 1]->bEndpointAddress; in __ffs_func_bind_do_nums()
2942 pr_vdebug("%02x -> %02x\n", *valuep, newValue); in __ffs_func_bind_do_nums()
2959 t = &func->function.os_desc_table[desc->bFirstInterfaceNumber]; in __ffs_func_bind_do_os_desc()
2960 t->if_id = func->interfaces_nums[desc->bFirstInterfaceNumber]; in __ffs_func_bind_do_os_desc()
2961 memcpy(t->os_desc->ext_compat_id, &desc->CompatibleID, in __ffs_func_bind_do_os_desc()
2962 ARRAY_SIZE(desc->CompatibleID) + in __ffs_func_bind_do_os_desc()
2963 ARRAY_SIZE(desc->SubCompatibleID)); in __ffs_func_bind_do_os_desc()
2974 t = &func->function.os_desc_table[h->interface]; in __ffs_func_bind_do_os_desc()
2975 t->if_id = func->interfaces_nums[h->interface]; in __ffs_func_bind_do_os_desc()
2977 ext_prop = func->ffs->ms_os_descs_ext_prop_avail; in __ffs_func_bind_do_os_desc()
2978 func->ffs->ms_os_descs_ext_prop_avail += sizeof(*ext_prop); in __ffs_func_bind_do_os_desc()
2980 ext_prop->type = le32_to_cpu(desc->dwPropertyDataType); in __ffs_func_bind_do_os_desc()
2981 ext_prop->name_len = le16_to_cpu(desc->wPropertyNameLength); in __ffs_func_bind_do_os_desc()
2982 ext_prop->data_len = le32_to_cpu(*(__le32 *) in __ffs_func_bind_do_os_desc()
2983 usb_ext_prop_data_len_ptr(data, ext_prop->name_len)); in __ffs_func_bind_do_os_desc()
2984 length = ext_prop->name_len + ext_prop->data_len + 14; in __ffs_func_bind_do_os_desc()
2986 ext_prop_name = func->ffs->ms_os_descs_ext_prop_name_avail; in __ffs_func_bind_do_os_desc()
2987 func->ffs->ms_os_descs_ext_prop_name_avail += in __ffs_func_bind_do_os_desc()
2988 ext_prop->name_len; in __ffs_func_bind_do_os_desc()
2990 ext_prop_data = func->ffs->ms_os_descs_ext_prop_data_avail; in __ffs_func_bind_do_os_desc()
2991 func->ffs->ms_os_descs_ext_prop_data_avail += in __ffs_func_bind_do_os_desc()
2992 ext_prop->data_len; in __ffs_func_bind_do_os_desc()
2994 usb_ext_prop_data_ptr(data, ext_prop->name_len), in __ffs_func_bind_do_os_desc()
2995 ext_prop->data_len); in __ffs_func_bind_do_os_desc()
2997 switch (ext_prop->type) { in __ffs_func_bind_do_os_desc()
3002 ext_prop->data_len *= 2; in __ffs_func_bind_do_os_desc()
3005 ext_prop->data = ext_prop_data; in __ffs_func_bind_do_os_desc()
3008 ext_prop->name_len); in __ffs_func_bind_do_os_desc()
3010 ext_prop->name_len *= 2; in __ffs_func_bind_do_os_desc()
3011 ext_prop->name = ext_prop_name; in __ffs_func_bind_do_os_desc()
3013 t->os_desc->ext_prop_len += in __ffs_func_bind_do_os_desc()
3014 ext_prop->name_len + ext_prop->data_len + 14; in __ffs_func_bind_do_os_desc()
3015 ++t->os_desc->ext_prop_count; in __ffs_func_bind_do_os_desc()
3016 list_add_tail(&ext_prop->entry, &t->os_desc->ext_prop); in __ffs_func_bind_do_os_desc()
3031 container_of(f->fi, struct f_fs_opts, func_inst); in ffs_do_functionfs_bind()
3041 * Configfs-enabled gadgets however do need ffs_dev_lock. in ffs_do_functionfs_bind()
3043 if (!ffs_opts->no_configfs) in ffs_do_functionfs_bind()
3045 ret = ffs_opts->dev->desc_ready ? 0 : -ENODEV; in ffs_do_functionfs_bind()
3046 func->ffs = ffs_opts->dev->ffs_data; in ffs_do_functionfs_bind()
3047 if (!ffs_opts->no_configfs) in ffs_do_functionfs_bind()
3052 func->conf = c; in ffs_do_functionfs_bind()
3053 func->gadget = c->cdev->gadget; in ffs_do_functionfs_bind()
3060 * with regard to ffs_opts->bound access in ffs_do_functionfs_bind()
3062 if (!ffs_opts->refcnt) { in ffs_do_functionfs_bind()
3063 ret = functionfs_bind(func->ffs, c->cdev); in ffs_do_functionfs_bind()
3067 ffs_opts->refcnt++; in ffs_do_functionfs_bind()
3068 func->function.strings = func->ffs->stringtabs; in ffs_do_functionfs_bind()
3077 struct ffs_data *ffs = func->ffs; in _ffs_func_bind()
3079 const int full = !!func->ffs->fs_descs_count; in _ffs_func_bind()
3080 const int high = !!func->ffs->hs_descs_count; in _ffs_func_bind()
3081 const int super = !!func->ffs->ss_descs_count; in _ffs_func_bind()
3088 vla_item_with_sz(d, struct ffs_ep, eps, ffs->eps_count); in _ffs_func_bind()
3090 full ? ffs->fs_descs_count + 1 : 0); in _ffs_func_bind()
3092 high ? ffs->hs_descs_count + 1 : 0); in _ffs_func_bind()
3094 super ? ffs->ss_descs_count + 1 : 0); in _ffs_func_bind()
3095 vla_item_with_sz(d, short, inums, ffs->interfaces_count); in _ffs_func_bind()
3097 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3099 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3101 c->cdev->use_os_string ? ffs->interfaces_count : 0); in _ffs_func_bind()
3103 ffs->ms_os_descs_ext_prop_count); in _ffs_func_bind()
3105 ffs->ms_os_descs_ext_prop_name_len); in _ffs_func_bind()
3107 ffs->ms_os_descs_ext_prop_data_len); in _ffs_func_bind()
3108 vla_item_with_sz(d, char, raw_descs, ffs->raw_descs_length); in _ffs_func_bind()
3115 return -ENOTSUPP; in _ffs_func_bind()
3120 return -ENOMEM; in _ffs_func_bind()
3122 ffs->ms_os_descs_ext_prop_avail = vla_ptr(vlabuf, d, ext_prop); in _ffs_func_bind()
3123 ffs->ms_os_descs_ext_prop_name_avail = in _ffs_func_bind()
3125 ffs->ms_os_descs_ext_prop_data_avail = in _ffs_func_bind()
3129 memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs, in _ffs_func_bind()
3130 ffs->raw_descs_length); in _ffs_func_bind()
3134 for (i = 0; i < ffs->eps_count; i++) in _ffs_func_bind()
3135 eps_ptr[i].num = -1; in _ffs_func_bind()
3138 * d_eps == vlabuf, func->eps used to kfree vlabuf later in _ffs_func_bind()
3140 func->eps = vla_ptr(vlabuf, d, eps); in _ffs_func_bind()
3141 func->interfaces_nums = vla_ptr(vlabuf, d, inums); in _ffs_func_bind()
3149 func->function.fs_descriptors = vla_ptr(vlabuf, d, fs_descs); in _ffs_func_bind()
3150 fs_len = ffs_do_descs(ffs->fs_descs_count, in _ffs_func_bind()
3163 func->function.hs_descriptors = vla_ptr(vlabuf, d, hs_descs); in _ffs_func_bind()
3164 hs_len = ffs_do_descs(ffs->hs_descs_count, in _ffs_func_bind()
3166 d_raw_descs__sz - fs_len, in _ffs_func_bind()
3177 func->function.ss_descriptors = vla_ptr(vlabuf, d, ss_descs); in _ffs_func_bind()
3178 ss_len = ffs_do_descs(ffs->ss_descs_count, in _ffs_func_bind()
3180 d_raw_descs__sz - fs_len - hs_len, in _ffs_func_bind()
3195 ret = ffs_do_descs(ffs->fs_descs_count + in _ffs_func_bind()
3196 (high ? ffs->hs_descs_count : 0) + in _ffs_func_bind()
3197 (super ? ffs->ss_descs_count : 0), in _ffs_func_bind()
3203 func->function.os_desc_table = vla_ptr(vlabuf, d, os_desc_table); in _ffs_func_bind()
3204 if (c->cdev->use_os_string) { in _ffs_func_bind()
3205 for (i = 0; i < ffs->interfaces_count; ++i) { in _ffs_func_bind()
3208 desc = func->function.os_desc_table[i].os_desc = in _ffs_func_bind()
3211 desc->ext_compat_id = in _ffs_func_bind()
3213 INIT_LIST_HEAD(&desc->ext_prop); in _ffs_func_bind()
3215 ret = ffs_do_os_descs(ffs->ms_os_descs_count, in _ffs_func_bind()
3218 d_raw_descs__sz - fs_len - hs_len - in _ffs_func_bind()
3224 func->function.os_desc_n = in _ffs_func_bind()
3225 c->cdev->use_os_string ? ffs->interfaces_count : 0; in _ffs_func_bind()
3247 if (ret && !--ffs_opts->refcnt) in ffs_func_bind()
3248 functionfs_unbind(func->ffs); in ffs_func_bind()
3267 struct ffs_data *ffs = func->ffs; in ffs_func_set_alt()
3270 if (alt != (unsigned)-1) { in ffs_func_set_alt()
3276 if (ffs->func) in ffs_func_set_alt()
3277 ffs_func_eps_disable(ffs->func); in ffs_func_set_alt()
3279 if (ffs->state == FFS_DEACTIVATED) { in ffs_func_set_alt()
3280 ffs->state = FFS_CLOSING; in ffs_func_set_alt()
3281 INIT_WORK(&ffs->reset_work, ffs_reset_work); in ffs_func_set_alt()
3282 schedule_work(&ffs->reset_work); in ffs_func_set_alt()
3283 return -ENODEV; in ffs_func_set_alt()
3286 if (ffs->state != FFS_ACTIVE) in ffs_func_set_alt()
3287 return -ENODEV; in ffs_func_set_alt()
3289 if (alt == (unsigned)-1) { in ffs_func_set_alt()
3290 ffs->func = NULL; in ffs_func_set_alt()
3295 ffs->func = func; in ffs_func_set_alt()
3304 ffs_func_set_alt(f, 0, (unsigned)-1); in ffs_func_disable()
3311 struct ffs_data *ffs = func->ffs; in ffs_func_setup()
3317 pr_vdebug("creq->bRequestType = %02x\n", creq->bRequestType); in ffs_func_setup()
3318 pr_vdebug("creq->bRequest = %02x\n", creq->bRequest); in ffs_func_setup()
3319 pr_vdebug("creq->wValue = %04x\n", le16_to_cpu(creq->wValue)); in ffs_func_setup()
3320 pr_vdebug("creq->wIndex = %04x\n", le16_to_cpu(creq->wIndex)); in ffs_func_setup()
3321 pr_vdebug("creq->wLength = %04x\n", le16_to_cpu(creq->wLength)); in ffs_func_setup()
3327 * passed to usb_configuration->setup() (if one is set). No in ffs_func_setup()
3333 if (ffs->state != FFS_ACTIVE) in ffs_func_setup()
3334 return -ENODEV; in ffs_func_setup()
3336 switch (creq->bRequestType & USB_RECIP_MASK) { in ffs_func_setup()
3338 ret = ffs_func_revmap_intf(func, le16_to_cpu(creq->wIndex)); in ffs_func_setup()
3344 ret = ffs_func_revmap_ep(func, le16_to_cpu(creq->wIndex)); in ffs_func_setup()
3347 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) in ffs_func_setup()
3348 ret = func->ffs->eps_addrmap[ret]; in ffs_func_setup()
3352 if (func->ffs->user_flags & FUNCTIONFS_ALL_CTRL_RECIP) in ffs_func_setup()
3353 ret = le16_to_cpu(creq->wIndex); in ffs_func_setup()
3355 return -EOPNOTSUPP; in ffs_func_setup()
3358 spin_lock_irqsave(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3359 ffs->ev.setup = *creq; in ffs_func_setup()
3360 ffs->ev.setup.wIndex = cpu_to_le16(ret); in ffs_func_setup()
3362 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); in ffs_func_setup()
3364 return creq->wLength == 0 ? USB_GADGET_DELAYED_STATUS : 0; in ffs_func_setup()
3373 if (config0 && !(func->ffs->user_flags & FUNCTIONFS_CONFIG0_SETUP)) in ffs_func_req_match()
3376 switch (creq->bRequestType & USB_RECIP_MASK) { in ffs_func_req_match()
3379 le16_to_cpu(creq->wIndex)) >= 0); in ffs_func_req_match()
3382 le16_to_cpu(creq->wIndex)) >= 0); in ffs_func_req_match()
3384 return (bool) (func->ffs->user_flags & in ffs_func_req_match()
3392 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_SUSPEND); in ffs_func_suspend()
3398 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_RESUME); in ffs_func_resume()
3404 static int ffs_func_revmap_ep(struct ffs_function *func, u8 num) in ffs_func_revmap_ep() argument
3406 num = func->eps_revmap[num & USB_ENDPOINT_NUMBER_MASK]; in ffs_func_revmap_ep()
3407 return num ? num : -EDOM; in ffs_func_revmap_ep()
3412 short *nums = func->interfaces_nums; in ffs_func_revmap_intf()
3413 unsigned count = func->ffs->interfaces_count; in ffs_func_revmap_intf()
3415 for (; count; --count, ++nums) { in ffs_func_revmap_intf()
3417 return nums - func->interfaces_nums; in ffs_func_revmap_intf()
3420 return -EDOM; in ffs_func_revmap_intf()
3436 if (strcmp(dev->name, name) == 0) in _ffs_do_find_dev()
3452 if (dev->single) in _ffs_get_single_dev()
3485 usb_put_function_instance(&opts->func_inst); in ffs_attr_release()
3506 _ffs_free_dev(opts->dev); in ffs_free_inst()
3514 return -ENAMETOOLONG; in ffs_set_inst_name()
3515 return ffs_name_dev(to_f_fs_opts(fi)->dev, name); in ffs_set_inst_name()
3525 return ERR_PTR(-ENOMEM); in ffs_alloc_inst()
3527 opts->func_inst.set_inst_name = ffs_set_inst_name; in ffs_alloc_inst()
3528 opts->func_inst.free_func_inst = ffs_free_inst; in ffs_alloc_inst()
3536 opts->dev = dev; in ffs_alloc_inst()
3537 dev->opts = opts; in ffs_alloc_inst()
3539 config_group_init_type_name(&opts->func_inst.group, "", in ffs_alloc_inst()
3541 return &opts->func_inst; in ffs_alloc_inst()
3553 struct ffs_data *ffs = func->ffs; in ffs_func_unbind()
3555 container_of(f->fi, struct f_fs_opts, func_inst); in ffs_func_unbind()
3556 struct ffs_ep *ep = func->eps; in ffs_func_unbind()
3557 unsigned count = ffs->eps_count; in ffs_func_unbind()
3561 if (ffs->func == func) { in ffs_func_unbind()
3563 ffs->func = NULL; in ffs_func_unbind()
3566 if (!--opts->refcnt) in ffs_func_unbind()
3570 spin_lock_irqsave(&func->ffs->eps_lock, flags); in ffs_func_unbind()
3571 while (count--) { in ffs_func_unbind()
3572 if (ep->ep && ep->req) in ffs_func_unbind()
3573 usb_ep_free_request(ep->ep, ep->req); in ffs_func_unbind()
3574 ep->req = NULL; in ffs_func_unbind()
3577 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); in ffs_func_unbind()
3578 kfree(func->eps); in ffs_func_unbind()
3579 func->eps = NULL; in ffs_func_unbind()
3584 func->function.fs_descriptors = NULL; in ffs_func_unbind()
3585 func->function.hs_descriptors = NULL; in ffs_func_unbind()
3586 func->function.ss_descriptors = NULL; in ffs_func_unbind()
3587 func->interfaces_nums = NULL; in ffs_func_unbind()
3600 return ERR_PTR(-ENOMEM); in ffs_alloc()
3602 func->function.name = "Function FS Gadget"; in ffs_alloc()
3604 func->function.bind = ffs_func_bind; in ffs_alloc()
3605 func->function.unbind = ffs_func_unbind; in ffs_alloc()
3606 func->function.set_alt = ffs_func_set_alt; in ffs_alloc()
3607 func->function.disable = ffs_func_disable; in ffs_alloc()
3608 func->function.setup = ffs_func_setup; in ffs_alloc()
3609 func->function.req_match = ffs_func_req_match; in ffs_alloc()
3610 func->function.suspend = ffs_func_suspend; in ffs_alloc()
3611 func->function.resume = ffs_func_resume; in ffs_alloc()
3612 func->function.free_func = ffs_free; in ffs_alloc()
3614 return &func->function; in ffs_alloc()
3626 return ERR_PTR(-EBUSY); in _ffs_alloc_dev()
3630 return ERR_PTR(-ENOMEM); in _ffs_alloc_dev()
3640 list_add(&dev->entry, &ffs_devices); in _ffs_alloc_dev()
3654 strlcpy(dev->name, name, ARRAY_SIZE(dev->name)); in ffs_name_dev()
3656 ret = -EBUSY; in ffs_name_dev()
3672 ret = -EBUSY; in ffs_single_dev()
3674 dev->single = true; in ffs_single_dev()
3686 list_del(&dev->entry); in _ffs_free_dev()
3689 if (dev->ffs_data) in _ffs_free_dev()
3690 dev->ffs_data->private_data = NULL; in _ffs_free_dev()
3706 ffs_dev = ERR_PTR(-ENOENT); in ffs_acquire_dev()
3707 else if (ffs_dev->mounted) in ffs_acquire_dev()
3708 ffs_dev = ERR_PTR(-EBUSY); in ffs_acquire_dev()
3709 else if (ffs_dev->ffs_acquire_dev_callback && in ffs_acquire_dev()
3710 ffs_dev->ffs_acquire_dev_callback(ffs_dev)) in ffs_acquire_dev()
3711 ffs_dev = ERR_PTR(-ENOENT); in ffs_acquire_dev()
3713 ffs_dev->mounted = true; in ffs_acquire_dev()
3726 ffs_dev = ffs_data->private_data; in ffs_release_dev()
3728 ffs_dev->mounted = false; in ffs_release_dev()
3730 if (ffs_dev->ffs_release_dev_callback) in ffs_release_dev()
3731 ffs_dev->ffs_release_dev_callback(ffs_dev); in ffs_release_dev()
3745 ffs_obj = ffs->private_data; in ffs_ready()
3747 ret = -EINVAL; in ffs_ready()
3750 if (WARN_ON(ffs_obj->desc_ready)) { in ffs_ready()
3751 ret = -EBUSY; in ffs_ready()
3755 ffs_obj->desc_ready = true; in ffs_ready()
3756 ffs_obj->ffs_data = ffs; in ffs_ready()
3758 if (ffs_obj->ffs_ready_callback) { in ffs_ready()
3759 ret = ffs_obj->ffs_ready_callback(ffs); in ffs_ready()
3764 set_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags); in ffs_ready()
3779 ffs_obj = ffs->private_data; in ffs_closed()
3783 ffs_obj->desc_ready = false; in ffs_closed()
3784 ffs_obj->ffs_data = NULL; in ffs_closed()
3786 if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags) && in ffs_closed()
3787 ffs_obj->ffs_closed_callback) in ffs_closed()
3788 ffs_obj->ffs_closed_callback(ffs); in ffs_closed()
3790 if (ffs_obj->opts) in ffs_closed()
3791 opts = ffs_obj->opts; in ffs_closed()
3795 if (opts->no_configfs || !opts->func_inst.group.cg_item.ci_parent in ffs_closed()
3796 || !kref_read(&opts->func_inst.group.cg_item.ci_kref)) in ffs_closed()
3799 ci = opts->func_inst.group.cg_item.ci_parent->ci_parent; in ffs_closed()
3802 if (test_bit(FFS_FL_BOUND, &ffs->flags)) in ffs_closed()
3814 ? likely(mutex_trylock(mutex)) ? 0 : -EAGAIN in ffs_mutex_lock()
3827 return ERR_PTR(-ENOMEM); in ffs_prepare_buffer()
3831 return ERR_PTR(-EFAULT); in ffs_prepare_buffer()