Lines Matching +full:conf +full:- +full:ds

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. */
69 struct usb_configuration *conf;
91 cmpxchg(&ffs->setup_state, FFS_SETUP_CANCELLED, FFS_NO_SETUP);
118 struct usb_ep *ep; /* P: ffs->eps_lock */
119 struct usb_request *req; /* P: epfile->mutex */
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;
273 complete(&ffs->ep0req_completion);
277 __releases(&ffs->ev.waitq.lock)
279 struct usb_request *req = ffs->ep0req;
283 spin_unlock_irq(&ffs->ev.waitq.lock);
284 return -EINVAL;
287 req->zero = len < le16_to_cpu(ffs->ev.setup.wLength);
289 spin_unlock_irq(&ffs->ev.waitq.lock);
291 req->buf = data;
292 req->length = len;
299 if (req->buf == NULL)
300 req->buf = (void *)0xDEADBABE;
302 reinit_completion(&ffs->ep0req_completion);
304 ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC);
308 ret = wait_for_completion_interruptible(&ffs->ep0req_completion);
310 usb_ep_dequeue(ffs->gadget->ep0, req);
311 return -EINTR;
314 ffs->setup_state = FFS_NO_SETUP;
315 return req->status ? req->status : req->actual;
320 if (ffs->ev.can_stall) {
322 usb_ep_set_halt(ffs->gadget->ep0);
323 ffs->setup_state = FFS_NO_SETUP;
324 return -EL2HLT;
327 return -ESRCH;
334 struct ffs_data *ffs = file->private_data;
340 return -EIDRM;
343 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK);
348 switch (ffs->state) {
353 ret = -EINVAL;
364 if (ffs->state == FFS_READ_DESCRIPTORS) {
370 ffs->state = FFS_READ_STRINGS;
380 ffs->state = FFS_CLOSING;
384 ffs->state = FFS_ACTIVE;
385 mutex_unlock(&ffs->mutex);
389 ffs->state = FFS_CLOSING;
403 spin_lock_irq(&ffs->ev.waitq.lock);
406 ret = -EIDRM;
410 ret = -ESRCH;
418 if (!(ffs->ev.setup.bRequestType & USB_DIR_IN)) {
419 spin_unlock_irq(&ffs->ev.waitq.lock);
425 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength));
427 spin_unlock_irq(&ffs->ev.waitq.lock);
435 spin_lock_irq(&ffs->ev.waitq.lock);
445 * the only place FFS_SETUP_PENDING -> FFS_NO_SETUP
451 ret = -EIDRM;
453 spin_unlock_irq(&ffs->ev.waitq.lock);
462 ret = -EBADFD;
466 mutex_unlock(&ffs->mutex);
470 /* Called with ffs->ev.waitq.lock and ffs->mutex held, both released on exit. */
473 __releases(&ffs->ev.waitq.lock)
476 * n cannot be bigger than ffs->ev.count, which cannot be bigger than
477 * size of ffs->ev.types array (which is four) so that's how much space
480 struct usb_functionfs_event events[ARRAY_SIZE(ffs->ev.types)];
487 events[i].type = ffs->ev.types[i];
489 events[i].u.setup = ffs->ev.setup;
490 ffs->setup_state = FFS_SETUP_PENDING;
494 ffs->ev.count -= n;
495 if (ffs->ev.count)
496 memmove(ffs->ev.types, ffs->ev.types + n,
497 ffs->ev.count * sizeof *ffs->ev.types);
499 spin_unlock_irq(&ffs->ev.waitq.lock);
500 mutex_unlock(&ffs->mutex);
502 return copy_to_user(buf, events, size) ? -EFAULT : size;
508 struct ffs_data *ffs = file->private_data;
515 return -EIDRM;
518 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK);
523 if (ffs->state != FFS_ACTIVE) {
524 ret = -EBADFD;
532 spin_lock_irq(&ffs->ev.waitq.lock);
536 ret = -EIDRM;
542 ret = -EINVAL;
546 if ((file->f_flags & O_NONBLOCK) && !ffs->ev.count) {
547 ret = -EAGAIN;
551 if (wait_event_interruptible_exclusive_locked_irq(ffs->ev.waitq,
552 ffs->ev.count)) {
553 ret = -EINTR;
559 min(n, (size_t)ffs->ev.count));
562 if (ffs->ev.setup.bRequestType & USB_DIR_IN) {
563 spin_unlock_irq(&ffs->ev.waitq.lock);
568 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength));
570 spin_unlock_irq(&ffs->ev.waitq.lock);
575 ret = -ENOMEM;
580 spin_lock_irq(&ffs->ev.waitq.lock);
585 ret = -EIDRM;
592 ret = -EFAULT;
596 ret = -EBADFD;
600 spin_unlock_irq(&ffs->ev.waitq.lock);
602 mutex_unlock(&ffs->mutex);
609 struct ffs_data *ffs = inode->i_private;
611 if (ffs->state == FFS_CLOSING)
612 return -EBUSY;
614 file->private_data = ffs;
622 struct ffs_data *ffs = file->private_data;
631 struct ffs_data *ffs = file->private_data;
632 struct usb_gadget *gadget = ffs->gadget;
636 struct ffs_function *func = ffs->func;
637 ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV;
638 } else if (gadget && gadget->ops->ioctl) {
639 ret = gadget->ops->ioctl(gadget, code, value);
641 ret = -ENOTTY;
649 struct ffs_data *ffs = file->private_data;
653 poll_wait(file, &ffs->ev.waitq, wait);
655 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK);
659 switch (ffs->state) {
666 switch (ffs->setup_state) {
668 if (ffs->ev.count)
685 mutex_unlock(&ffs->mutex);
706 struct ffs_io_data *io_data = req->context;
708 if (req->status)
709 io_data->status = req->status;
711 io_data->status = req->actual;
713 complete(&io_data->done);
723 return -EFAULT;
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)
800 return ffs_build_sg_list(&io_data->sgt, data_len);
807 if (!io_data->buf)
810 if (io_data->use_sg) {
811 sg_free_table(&io_data->sgt);
812 vfree(io_data->buf);
814 kfree(io_data->buf);
822 int ret = io_data->status;
823 bool kiocb_has_eventfd = io_data->kiocb->ki_flags & IOCB_EVENTFD;
826 if (io_data->read && ret > 0) {
827 kthread_use_mm(io_data->mm);
828 ret = ffs_copy_to_iter(io_data->buf, ret, &io_data->data);
829 kthread_unuse_mm(io_data->mm);
832 io_data->kiocb->ki_complete(io_data->kiocb, ret);
834 if (io_data->ffs->ffs_eventfd && !kiocb_has_eventfd)
835 eventfd_signal(io_data->ffs->ffs_eventfd, 1);
837 spin_lock_irqsave(&io_data->ffs->eps_lock, flags);
838 usb_ep_free_request(io_data->ep, io_data->req);
839 io_data->req = NULL;
840 spin_unlock_irqrestore(&io_data->ffs->eps_lock, flags);
842 if (io_data->read)
843 kfree(io_data->to_free);
851 struct ffs_io_data *io_data = req->context;
852 struct ffs_data *ffs = io_data->ffs;
854 io_data->status = req->status ? req->status : req->actual;
856 INIT_WORK(&io_data->work, ffs_user_copy_worker);
857 queue_work(ffs->io_completion_wq, &io_data->work);
866 struct ffs_buffer *buf = xchg(&epfile->read_buffer, READ_BUFFER_DROP);
871 /* Assumes epfile->mutex is held. */
876 * Null out epfile->read_buffer so ffs_func_eps_disable does not free
880 struct ffs_buffer *buf = xchg(&epfile->read_buffer, NULL);
885 ret = copy_to_iter(buf->data, buf->length, iter);
886 if (buf->length == ret) {
892 ret = -EFAULT;
894 buf->length -= ret;
895 buf->data += ret;
898 if (cmpxchg(&epfile->read_buffer, NULL, buf))
904 /* Assumes epfile->mutex is held. */
916 return -EFAULT;
922 data_len -= ret;
925 return -ENOMEM;
926 buf->length = data_len;
927 buf->data = buf->storage;
928 memcpy(buf->storage, data + ret, flex_array_size(buf, storage, data_len));
936 if (cmpxchg(&epfile->read_buffer, NULL, buf))
944 struct ffs_epfile *epfile = file->private_data;
948 ssize_t ret, data_len = -EINVAL;
952 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE))
953 return -ENODEV;
956 ep = epfile->ep;
958 if (file->f_flags & O_NONBLOCK)
959 return -EAGAIN;
962 epfile->ffs->wait, (ep = epfile->ep));
964 return -EINTR;
968 halt = (!io_data->read == !epfile->in);
969 if (halt && epfile->isoc)
970 return -EINVAL;
973 ret = ffs_mutex_lock(&epfile->mutex, file->f_flags & O_NONBLOCK);
988 if (!io_data->aio && io_data->read) {
989 ret = __ffs_epfile_read_buffered(epfile, &io_data->data);
995 * if we _do_ wait above, the epfile->ffs->gadget might be NULL
999 gadget = epfile->ffs->gadget;
1001 spin_lock_irq(&epfile->ffs->eps_lock);
1003 if (epfile->ep != ep) {
1004 ret = -ESHUTDOWN;
1007 data_len = iov_iter_count(&io_data->data);
1012 if (io_data->read)
1013 data_len = usb_ep_align_maybe(gadget, ep->ep, data_len);
1015 io_data->use_sg = gadget->sg_supported && data_len > PAGE_SIZE;
1016 spin_unlock_irq(&epfile->ffs->eps_lock);
1020 ret = -ENOMEM;
1023 if (!io_data->read &&
1024 !copy_from_iter_full(data, data_len, &io_data->data)) {
1025 ret = -EFAULT;
1030 spin_lock_irq(&epfile->ffs->eps_lock);
1032 if (epfile->ep != ep) {
1034 ret = -ESHUTDOWN;
1036 ret = usb_ep_set_halt(ep->ep);
1038 ret = -EBADMSG;
1039 } else if (data_len == -EINVAL) {
1045 * being initialized to -EINVAL during its declaration, which
1051 WARN(1, "%s: data_len == -EINVAL\n", __func__);
1052 ret = -EINVAL;
1053 } else if (!io_data->aio) {
1056 req = ep->req;
1057 if (io_data->use_sg) {
1058 req->buf = NULL;
1059 req->sg = io_data->sgt.sgl;
1060 req->num_sgs = io_data->sgt.nents;
1062 req->buf = data;
1063 req->num_sgs = 0;
1065 req->length = data_len;
1067 io_data->buf = data;
1069 init_completion(&io_data->done);
1070 req->context = io_data;
1071 req->complete = ffs_epfile_io_complete;
1073 ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC);
1077 spin_unlock_irq(&epfile->ffs->eps_lock);
1079 if (wait_for_completion_interruptible(&io_data->done)) {
1080 spin_lock_irq(&epfile->ffs->eps_lock);
1081 if (epfile->ep != ep) {
1082 ret = -ESHUTDOWN;
1089 * condition with req->complete callback.
1091 usb_ep_dequeue(ep->ep, req);
1092 spin_unlock_irq(&epfile->ffs->eps_lock);
1093 wait_for_completion(&io_data->done);
1094 interrupted = io_data->status < 0;
1098 ret = -EINTR;
1099 else if (io_data->read && io_data->status > 0)
1100 ret = __ffs_epfile_read_data(epfile, data, io_data->status,
1101 &io_data->data);
1103 ret = io_data->status;
1105 } else if (!(req = usb_ep_alloc_request(ep->ep, GFP_ATOMIC))) {
1106 ret = -ENOMEM;
1108 if (io_data->use_sg) {
1109 req->buf = NULL;
1110 req->sg = io_data->sgt.sgl;
1111 req->num_sgs = io_data->sgt.nents;
1113 req->buf = data;
1114 req->num_sgs = 0;
1116 req->length = data_len;
1118 io_data->buf = data;
1119 io_data->ep = ep->ep;
1120 io_data->req = req;
1121 io_data->ffs = epfile->ffs;
1123 req->context = io_data;
1124 req->complete = ffs_epfile_async_io_complete;
1126 ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC);
1128 io_data->req = NULL;
1129 usb_ep_free_request(ep->ep, req);
1133 ret = -EIOCBQUEUED;
1142 spin_unlock_irq(&epfile->ffs->eps_lock);
1144 mutex_unlock(&epfile->mutex);
1146 if (ret != -EIOCBQUEUED) /* don't free if there is iocb queued */
1154 struct ffs_epfile *epfile = inode->i_private;
1156 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE))
1157 return -ENODEV;
1159 file->private_data = epfile;
1160 ffs_data_opened(epfile->ffs);
1167 struct ffs_io_data *io_data = kiocb->private;
1168 struct ffs_epfile *epfile = kiocb->ki_filp->private_data;
1172 spin_lock_irqsave(&epfile->ffs->eps_lock, flags);
1174 if (io_data && io_data->ep && io_data->req)
1175 value = usb_ep_dequeue(io_data->ep, io_data->req);
1177 value = -EINVAL;
1179 spin_unlock_irqrestore(&epfile->ffs->eps_lock, flags);
1192 return -ENOMEM;
1193 p->aio = true;
1196 p->aio = false;
1199 p->read = false;
1200 p->kiocb = kiocb;
1201 p->data = *from;
1202 p->mm = current->mm;
1204 kiocb->private = p;
1206 if (p->aio)
1209 res = ffs_epfile_io(kiocb->ki_filp, p);
1210 if (res == -EIOCBQUEUED)
1212 if (p->aio)
1215 *from = p->data;
1227 return -ENOMEM;
1228 p->aio = true;
1231 p->aio = false;
1234 p->read = true;
1235 p->kiocb = kiocb;
1236 if (p->aio) {
1237 p->to_free = dup_iter(&p->data, to, GFP_KERNEL);
1238 if (!iter_is_ubuf(&p->data) && !p->to_free) {
1240 return -ENOMEM;
1243 p->data = *to;
1244 p->to_free = NULL;
1246 p->mm = current->mm;
1248 kiocb->private = p;
1250 if (p->aio)
1253 res = ffs_epfile_io(kiocb->ki_filp, p);
1254 if (res == -EIOCBQUEUED)
1257 if (p->aio) {
1258 kfree(p->to_free);
1261 *to = p->data;
1269 struct ffs_epfile *epfile = inode->i_private;
1272 ffs_data_closed(epfile->ffs);
1280 struct ffs_epfile *epfile = file->private_data;
1284 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE))
1285 return -ENODEV;
1288 ep = epfile->ep;
1290 if (file->f_flags & O_NONBLOCK)
1291 return -EAGAIN;
1294 epfile->ffs->wait, (ep = epfile->ep));
1296 return -EINTR;
1299 spin_lock_irq(&epfile->ffs->eps_lock);
1302 if (epfile->ep != ep) {
1303 spin_unlock_irq(&epfile->ffs->eps_lock);
1304 return -ESHUTDOWN;
1309 ret = usb_ep_fifo_status(epfile->ep->ep);
1312 usb_ep_fifo_flush(epfile->ep->ep);
1316 ret = usb_ep_clear_halt(epfile->ep->ep);
1319 ret = epfile->ep->num;
1326 switch (epfile->ffs->gadget->speed) {
1338 desc = epfile->ep->descs[desc_idx];
1339 memcpy(&desc1, desc, desc->bLength);
1341 spin_unlock_irq(&epfile->ffs->eps_lock);
1344 ret = -EFAULT;
1348 ret = -ENOTTY;
1350 spin_unlock_irq(&epfile->ffs->eps_lock);
1387 inode->i_ino = get_next_ino();
1388 inode->i_mode = perms->mode;
1389 inode->i_uid = perms->uid;
1390 inode->i_gid = perms->gid;
1391 inode->i_atime = ts;
1392 inode->i_mtime = ts;
1393 inode->i_private = data;
1395 inode->i_fop = fops;
1397 inode->i_op = iops;
1408 struct ffs_data *ffs = sb->s_fs_info;
1412 dentry = d_alloc_name(sb->s_root, name);
1416 inode = ffs_sb_make_inode(sb, data, fops, NULL, &ffs->file_perms);
1442 struct ffs_sb_fill_data *data = fc->fs_private;
1444 struct ffs_data *ffs = data->ffs_data;
1446 ffs->sb = sb;
1447 data->ffs_data = NULL;
1448 sb->s_fs_info = ffs;
1449 sb->s_blocksize = PAGE_SIZE;
1450 sb->s_blocksize_bits = PAGE_SHIFT;
1451 sb->s_magic = FUNCTIONFS_MAGIC;
1452 sb->s_op = &ffs_sb_operations;
1453 sb->s_time_gran = 1;
1456 data->perms.mode = data->root_mode;
1460 &data->perms);
1461 sb->s_root = d_make_root(inode);
1462 if (!sb->s_root)
1463 return -ENOMEM;
1467 return -ENOMEM;
1493 struct ffs_sb_fill_data *data = fc->fs_private;
1503 data->no_disconnect = result.boolean;
1506 data->root_mode = (result.uint_32 & 0555) | S_IFDIR;
1509 data->perms.mode = (result.uint_32 & 0666) | S_IFREG;
1512 data->root_mode = (result.uint_32 & 0555) | S_IFDIR;
1513 data->perms.mode = (result.uint_32 & 0666) | S_IFREG;
1517 data->perms.uid = make_kuid(current_user_ns(), result.uint_32);
1518 if (!uid_valid(data->perms.uid))
1522 data->perms.gid = make_kgid(current_user_ns(), result.uint_32);
1523 if (!gid_valid(data->perms.gid))
1528 return -ENOPARAM;
1534 return invalf(fc, "%s: unmapped value: %u", param->key, result.uint_32);
1542 struct ffs_sb_fill_data *ctx = fc->fs_private;
1546 if (!fc->source)
1549 ffs = ffs_data_new(fc->source);
1551 return -ENOMEM;
1552 ffs->file_perms = ctx->perms;
1553 ffs->no_disconnect = ctx->no_disconnect;
1555 ffs->dev_name = kstrdup(fc->source, GFP_KERNEL);
1556 if (!ffs->dev_name) {
1558 return -ENOMEM;
1561 ret = ffs_acquire_dev(ffs->dev_name, ffs);
1567 ctx->ffs_data = ffs;
1573 struct ffs_sb_fill_data *ctx = fc->fs_private;
1576 if (ctx->ffs_data) {
1577 ffs_data_put(ctx->ffs_data);
1596 return -ENOMEM;
1598 ctx->perms.mode = S_IFREG | 0600;
1599 ctx->perms.uid = GLOBAL_ROOT_UID;
1600 ctx->perms.gid = GLOBAL_ROOT_GID;
1601 ctx->root_mode = S_IFDIR | 0500;
1602 ctx->no_disconnect = false;
1604 fc->fs_private = ctx;
1605 fc->ops = &ffs_fs_context_ops;
1613 if (sb->s_fs_info)
1614 ffs_data_closed(sb->s_fs_info);
1656 refcount_inc(&ffs->ref);
1661 refcount_inc(&ffs->ref);
1662 if (atomic_add_return(1, &ffs->opened) == 1 &&
1663 ffs->state == FFS_DEACTIVATED) {
1664 ffs->state = FFS_CLOSING;
1671 if (refcount_dec_and_test(&ffs->ref)) {
1674 ffs_release_dev(ffs->private_data);
1675 BUG_ON(waitqueue_active(&ffs->ev.waitq) ||
1676 swait_active(&ffs->ep0req_completion.wait) ||
1677 waitqueue_active(&ffs->wait));
1678 destroy_workqueue(ffs->io_completion_wq);
1679 kfree(ffs->dev_name);
1689 if (atomic_dec_and_test(&ffs->opened)) {
1690 if (ffs->no_disconnect) {
1691 ffs->state = FFS_DEACTIVATED;
1692 spin_lock_irqsave(&ffs->eps_lock, flags);
1693 epfiles = ffs->epfiles;
1694 ffs->epfiles = NULL;
1695 spin_unlock_irqrestore(&ffs->eps_lock,
1700 ffs->eps_count);
1702 if (ffs->setup_state == FFS_SETUP_PENDING)
1705 ffs->state = FFS_CLOSING;
1709 if (atomic_read(&ffs->opened) < 0) {
1710 ffs->state = FFS_CLOSING;
1723 ffs->io_completion_wq = alloc_ordered_workqueue("%s", 0, dev_name);
1724 if (!ffs->io_completion_wq) {
1729 refcount_set(&ffs->ref, 1);
1730 atomic_set(&ffs->opened, 0);
1731 ffs->state = FFS_READ_DESCRIPTORS;
1732 mutex_init(&ffs->mutex);
1733 spin_lock_init(&ffs->eps_lock);
1734 init_waitqueue_head(&ffs->ev.waitq);
1735 init_waitqueue_head(&ffs->wait);
1736 init_completion(&ffs->ep0req_completion);
1739 ffs->ev.can_stall = 1;
1751 BUG_ON(ffs->gadget);
1753 spin_lock_irqsave(&ffs->eps_lock, flags);
1754 epfiles = ffs->epfiles;
1755 ffs->epfiles = NULL;
1756 spin_unlock_irqrestore(&ffs->eps_lock, flags);
1761 * copy of epfile will save us from use-after-free.
1764 ffs_epfiles_destroy(epfiles, ffs->eps_count);
1765 ffs->epfiles = NULL;
1768 if (ffs->ffs_eventfd) {
1769 eventfd_ctx_put(ffs->ffs_eventfd);
1770 ffs->ffs_eventfd = NULL;
1773 kfree(ffs->raw_descs_data);
1774 kfree(ffs->raw_strings);
1775 kfree(ffs->stringtabs);
1782 ffs->raw_descs_data = NULL;
1783 ffs->raw_descs = NULL;
1784 ffs->raw_strings = NULL;
1785 ffs->stringtabs = NULL;
1787 ffs->raw_descs_length = 0;
1788 ffs->fs_descs_count = 0;
1789 ffs->hs_descs_count = 0;
1790 ffs->ss_descs_count = 0;
1792 ffs->strings_count = 0;
1793 ffs->interfaces_count = 0;
1794 ffs->eps_count = 0;
1796 ffs->ev.count = 0;
1798 ffs->state = FFS_READ_DESCRIPTORS;
1799 ffs->setup_state = FFS_NO_SETUP;
1800 ffs->flags = 0;
1802 ffs->ms_os_descs_ext_prop_count = 0;
1803 ffs->ms_os_descs_ext_prop_name_len = 0;
1804 ffs->ms_os_descs_ext_prop_data_len = 0;
1813 if ((ffs->state != FFS_ACTIVE
1814 || test_and_set_bit(FFS_FL_BOUND, &ffs->flags)))
1815 return -EBADFD;
1817 first_id = usb_string_ids_n(cdev, ffs->strings_count);
1821 ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL);
1822 if (!ffs->ep0req)
1823 return -ENOMEM;
1824 ffs->ep0req->complete = ffs_ep0_complete;
1825 ffs->ep0req->context = ffs;
1827 lang = ffs->stringtabs;
1830 struct usb_string *str = (*lang)->strings;
1832 for (; str->s; ++id, ++str)
1833 str->id = id;
1837 ffs->gadget = cdev->gadget;
1844 if (!WARN_ON(!ffs->gadget)) {
1846 usb_ep_dequeue(ffs->gadget->ep0, ffs->ep0req);
1847 mutex_lock(&ffs->mutex);
1848 usb_ep_free_request(ffs->gadget->ep0, ffs->ep0req);
1849 ffs->ep0req = NULL;
1850 ffs->gadget = NULL;
1851 clear_bit(FFS_FL_BOUND, &ffs->flags);
1852 mutex_unlock(&ffs->mutex);
1862 count = ffs->eps_count;
1865 return -ENOMEM;
1869 epfile->ffs = ffs;
1870 mutex_init(&epfile->mutex);
1871 if (ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR)
1872 sprintf(epfile->name, "ep%02x", ffs->eps_addrmap[i]);
1874 sprintf(epfile->name, "ep%u", i);
1875 epfile->dentry = ffs_sb_create_file(ffs->sb, epfile->name,
1878 if (!epfile->dentry) {
1879 ffs_epfiles_destroy(epfiles, i - 1);
1880 return -ENOMEM;
1884 ffs->epfiles = epfiles;
1892 for (; count; --count, ++epfile) {
1893 BUG_ON(mutex_is_locked(&epfile->mutex));
1894 if (epfile->dentry) {
1895 d_delete(epfile->dentry);
1896 dput(epfile->dentry);
1897 epfile->dentry = NULL;
1911 spin_lock_irqsave(&func->ffs->eps_lock, flags);
1912 count = func->ffs->eps_count;
1913 epfile = func->ffs->epfiles;
1914 ep = func->eps;
1915 while (count--) {
1917 if (ep->ep)
1918 usb_ep_disable(ep->ep);
1922 epfile->ep = NULL;
1927 spin_unlock_irqrestore(&func->ffs->eps_lock, flags);
1939 spin_lock_irqsave(&func->ffs->eps_lock, flags);
1940 ffs = func->ffs;
1941 ep = func->eps;
1942 epfile = ffs->epfiles;
1943 count = ffs->eps_count;
1944 while(count--) {
1945 ep->ep->driver_data = ep;
1947 ret = config_ep_by_speed(func->gadget, &func->function, ep->ep);
1950 __func__, ep->ep->name, ret);
1954 ret = usb_ep_enable(ep->ep);
1956 epfile->ep = ep;
1957 epfile->in = usb_endpoint_dir_in(ep->ep->desc);
1958 epfile->isoc = usb_endpoint_xfer_isoc(ep->ep->desc);
1967 wake_up_interruptible(&ffs->wait);
1968 spin_unlock_irqrestore(&func->ffs->eps_lock, flags);
2011 return -EINVAL;
2015 length = _ds->bLength;
2018 return -EINVAL;
2028 return -EINVAL; \
2039 switch (_ds->bDescriptorType) {
2046 _ds->bDescriptorType);
2047 return -EINVAL;
2050 struct usb_interface_descriptor *ds = (void *)_ds;
2052 if (length != sizeof *ds)
2055 __entity(INTERFACE, ds->bInterfaceNumber);
2056 if (ds->iInterface)
2057 __entity(STRING, ds->iInterface);
2058 *current_class = ds->bInterfaceClass;
2063 struct usb_endpoint_descriptor *ds = (void *)_ds;
2068 __entity(ENDPOINT, ds->bEndpointAddress);
2085 _ds->bDescriptorType, *current_class);
2086 return -EINVAL;
2095 struct usb_interface_assoc_descriptor *ds = (void *)_ds;
2097 if (length != sizeof *ds)
2099 if (ds->iFunction)
2100 __entity(STRING, ds->iFunction);
2116 pr_vdebug("unimplemented descriptor: %d\n", _ds->bDescriptorType);
2117 return -EINVAL;
2121 pr_vdebug("unknown descriptor: %d\n", _ds->bDescriptorType);
2122 return -EINVAL;
2126 _ds->bLength, _ds->bDescriptorType);
2127 return -EINVAL;
2144 int current_class = -1;
2161 return _len - len;
2170 len -= ret;
2193 if (*valuep >= helper->interfaces_count)
2194 helper->interfaces_count = *valuep + 1;
2202 if (*valuep > helper->ffs->strings_count)
2203 helper->ffs->strings_count = *valuep;
2208 helper->eps_count++;
2209 if (helper->eps_count >= FFS_MAX_EPS_COUNT)
2210 return -EINVAL;
2212 if (!helper->ffs->eps_count && !helper->ffs->interfaces_count)
2213 helper->ffs->eps_addrmap[helper->eps_count] =
2214 d->bEndpointAddress;
2215 else if (helper->ffs->eps_addrmap[helper->eps_count] !=
2216 d->bEndpointAddress)
2217 return -EINVAL;
2227 u16 bcd_version = le16_to_cpu(desc->bcdVersion);
2228 u16 w_index = le16_to_cpu(desc->wIndex);
2236 return -EINVAL;
2247 return -EINVAL;
2268 while (feature_count--) {
2275 len -= ret;
2277 return _len - len;
2295 return -EINVAL;
2304 if (le32_to_cpu(desc->dwLength) > len)
2305 return -EINVAL;
2314 * 16-bit hex "?? 00" Little Endian looks like 8-bit hex "??"
2316 feature_count = le16_to_cpu(desc->wCount);
2318 (feature_count > 255 || desc->Reserved))
2319 return -EINVAL;
2320 len -= ret;
2334 len -= ret;
2337 return _len - len;
2356 d->bFirstInterfaceNumber >= ffs->interfaces_count)
2357 return -EINVAL;
2358 if (d->Reserved1 != 1) {
2361 * but older kernels incorrectly rejected non-zero
2366 d->Reserved1 = 1;
2368 for (i = 0; i < ARRAY_SIZE(d->Reserved2); ++i)
2369 if (d->Reserved2[i])
2370 return -EINVAL;
2380 if (len < sizeof(*d) || h->interface >= ffs->interfaces_count)
2381 return -EINVAL;
2382 length = le32_to_cpu(d->dwSize);
2384 return -EINVAL;
2385 type = le32_to_cpu(d->dwPropertyDataType);
2390 return -EINVAL;
2392 pnl = le16_to_cpu(d->wPropertyNameLength);
2396 return -EINVAL;
2402 return -EINVAL;
2404 ++ffs->ms_os_descs_ext_prop_count;
2406 ffs->ms_os_descs_ext_prop_name_len += pnl * 2;
2407 ffs->ms_os_descs_ext_prop_data_len += pdl;
2412 return -EINVAL;
2422 int ret = -EINVAL, i;
2432 len -= 8;
2436 ffs->user_flags = flags;
2445 ret = -ENOSYS;
2449 len -= 12;
2458 ffs->ffs_eventfd =
2460 if (IS_ERR(ffs->ffs_eventfd)) {
2461 ret = PTR_ERR(ffs->ffs_eventfd);
2462 ffs->ffs_eventfd = NULL;
2466 len -= 4;
2478 len -= 4;
2487 len -= 4;
2502 if (!ffs->eps_count && !ffs->interfaces_count) {
2503 ffs->eps_count = helper.eps_count;
2504 ffs->interfaces_count = helper.interfaces_count;
2506 if (ffs->eps_count != helper.eps_count) {
2507 ret = -EINVAL;
2510 if (ffs->interfaces_count != helper.interfaces_count) {
2511 ret = -EINVAL;
2516 len -= ret;
2524 len -= ret;
2528 ret = -EINVAL;
2532 ffs->raw_descs_data = _data;
2533 ffs->raw_descs = raw_descs;
2534 ffs->raw_descs_length = data - raw_descs;
2535 ffs->fs_descs_count = counts[0];
2536 ffs->hs_descs_count = counts[1];
2537 ffs->ss_descs_count = counts[2];
2538 ffs->ms_os_descs_count = os_descs_count;
2567 needed_count = ffs->strings_count;
2594 return -ENOMEM;
2603 } while (--i);
2614 len -= 16;
2616 do { /* lang_count > 0 so we can use do-while */
2622 t->language = get_unaligned_le16(data);
2623 t->strings = s;
2627 len -= 2;
2630 do { /* str_count > 0 so we can use do-while */
2643 * s->id will be set while adding
2647 s->s = data;
2648 --needed;
2653 len -= length + 1;
2654 } while (--str_per_lang);
2656 s->id = 0; /* terminator */
2657 s->s = NULL;
2660 } while (--lang_count);
2667 ffs->stringtabs = stringtabs;
2668 ffs->raw_strings = _data;
2676 return -EINVAL;
2692 * of ffs->setup_state without holding the lock because when
2696 if (ffs->setup_state == FFS_SETUP_PENDING)
2697 ffs->setup_state = FFS_SETUP_CANCELLED;
2701 * evens on ffs->ev.types queue. This is important because the queue
2732 u8 *ev = ffs->ev.types, *out = ev;
2733 unsigned n = ffs->ev.count;
2734 for (; n; --n, ++ev)
2739 ffs->ev.count = out - ffs->ev.types;
2743 ffs->ev.types[ffs->ev.count++] = type;
2744 wake_up_locked(&ffs->ev.waitq);
2745 if (ffs->ffs_eventfd)
2746 eventfd_signal(ffs->ffs_eventfd, 1);
2753 spin_lock_irqsave(&ffs->ev.waitq.lock, flags);
2755 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags);
2764 for (i = 1; i < ARRAY_SIZE(ffs->eps_addrmap); ++i)
2765 if (ffs->eps_addrmap[i] == endpoint_address)
2767 return -ENOENT;
2774 struct usb_endpoint_descriptor *ds = (void *)desc;
2790 if (func->function.ss_descriptors) {
2792 func->function.ss_descriptors[(long)valuep] = desc;
2793 } else if (func->function.hs_descriptors) {
2795 func->function.hs_descriptors[(long)valuep] = desc;
2798 func->function.fs_descriptors[(long)valuep] = desc;
2801 if (!desc || desc->bDescriptorType != USB_DT_ENDPOINT)
2804 idx = ffs_ep_addr2idx(func->ffs, ds->bEndpointAddress) - 1;
2808 ffs_ep = func->eps + idx;
2810 if (ffs_ep->descs[ep_desc_id]) {
2813 ds->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
2814 return -EINVAL;
2816 ffs_ep->descs[ep_desc_id] = ds;
2818 ffs_dump_mem(": Original ep desc", ds, ds->bLength);
2819 if (ffs_ep->ep) {
2820 ds->bEndpointAddress = ffs_ep->descs[0]->bEndpointAddress;
2821 if (!ds->wMaxPacketSize)
2822 ds->wMaxPacketSize = ffs_ep->descs[0]->wMaxPacketSize;
2833 bEndpointAddress = ds->bEndpointAddress;
2838 wMaxPacketSize = ds->wMaxPacketSize;
2840 ep = usb_ep_autoconfig(func->gadget, ds);
2842 return -ENOTSUPP;
2843 ep->driver_data = func->eps + idx;
2847 return -ENOMEM;
2849 ffs_ep->ep = ep;
2850 ffs_ep->req = req;
2851 func->eps_revmap[ds->bEndpointAddress &
2857 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR)
2858 ds->bEndpointAddress = bEndpointAddress;
2863 ds->wMaxPacketSize = wMaxPacketSize;
2865 ffs_dump_mem(": Rewritten ep desc", ds, ds->bLength);
2886 if (func->interfaces_nums[idx] < 0) {
2887 int id = usb_interface_id(func->conf, &func->function);
2890 func->interfaces_nums[idx] = id;
2892 newValue = func->interfaces_nums[idx];
2897 newValue = func->ffs->stringtabs[0]->strings[*valuep - 1].id;
2905 if (desc->bDescriptorType == USB_DT_ENDPOINT)
2908 idx = (*valuep & USB_ENDPOINT_NUMBER_MASK) - 1;
2909 if (!func->eps[idx].ep)
2910 return -EINVAL;
2914 descs = func->eps[idx].descs;
2915 newValue = descs[descs[0] ? 0 : 1]->bEndpointAddress;
2920 pr_vdebug("%02x -> %02x\n", *valuep, newValue);
2937 t = &func->function.os_desc_table[desc->bFirstInterfaceNumber];
2938 t->if_id = func->interfaces_nums[desc->bFirstInterfaceNumber];
2939 memcpy(t->os_desc->ext_compat_id, &desc->CompatibleID,
2940 ARRAY_SIZE(desc->CompatibleID) +
2941 ARRAY_SIZE(desc->SubCompatibleID));
2952 t = &func->function.os_desc_table[h->interface];
2953 t->if_id = func->interfaces_nums[h->interface];
2955 ext_prop = func->ffs->ms_os_descs_ext_prop_avail;
2956 func->ffs->ms_os_descs_ext_prop_avail += sizeof(*ext_prop);
2958 ext_prop->type = le32_to_cpu(desc->dwPropertyDataType);
2959 ext_prop->name_len = le16_to_cpu(desc->wPropertyNameLength);
2960 ext_prop->data_len = le32_to_cpu(*(__le32 *)
2961 usb_ext_prop_data_len_ptr(data, ext_prop->name_len));
2962 length = ext_prop->name_len + ext_prop->data_len + 14;
2964 ext_prop_name = func->ffs->ms_os_descs_ext_prop_name_avail;
2965 func->ffs->ms_os_descs_ext_prop_name_avail +=
2966 ext_prop->name_len;
2968 ext_prop_data = func->ffs->ms_os_descs_ext_prop_data_avail;
2969 func->ffs->ms_os_descs_ext_prop_data_avail +=
2970 ext_prop->data_len;
2972 usb_ext_prop_data_ptr(data, ext_prop->name_len),
2973 ext_prop->data_len);
2975 switch (ext_prop->type) {
2980 ext_prop->data_len *= 2;
2983 ext_prop->data = ext_prop_data;
2986 ext_prop->name_len);
2988 ext_prop->name_len *= 2;
2989 ext_prop->name = ext_prop_name;
2991 t->os_desc->ext_prop_len +=
2992 ext_prop->name_len + ext_prop->data_len + 14;
2993 ++t->os_desc->ext_prop_count;
2994 list_add_tail(&ext_prop->entry, &t->os_desc->ext_prop);
3009 container_of(f->fi, struct f_fs_opts, func_inst);
3018 * Configfs-enabled gadgets however do need ffs_dev_lock.
3020 if (!ffs_opts->no_configfs)
3022 ret = ffs_opts->dev->desc_ready ? 0 : -ENODEV;
3023 ffs_data = ffs_opts->dev->ffs_data;
3024 if (!ffs_opts->no_configfs)
3029 func->ffs = ffs_data;
3030 func->conf = c;
3031 func->gadget = c->cdev->gadget;
3038 * with regard to ffs_opts->bound access
3040 if (!ffs_opts->refcnt) {
3041 ret = functionfs_bind(func->ffs, c->cdev);
3045 ffs_opts->refcnt++;
3046 func->function.strings = func->ffs->stringtabs;
3055 struct ffs_data *ffs = func->ffs;
3057 const int full = !!func->ffs->fs_descs_count;
3058 const int high = !!func->ffs->hs_descs_count;
3059 const int super = !!func->ffs->ss_descs_count;
3066 vla_item_with_sz(d, struct ffs_ep, eps, ffs->eps_count);
3068 full ? ffs->fs_descs_count + 1 : 0);
3070 high ? ffs->hs_descs_count + 1 : 0);
3072 super ? ffs->ss_descs_count + 1 : 0);
3073 vla_item_with_sz(d, short, inums, ffs->interfaces_count);
3075 c->cdev->use_os_string ? ffs->interfaces_count : 0);
3077 c->cdev->use_os_string ? ffs->interfaces_count : 0);
3079 c->cdev->use_os_string ? ffs->interfaces_count : 0);
3081 ffs->ms_os_descs_ext_prop_count);
3083 ffs->ms_os_descs_ext_prop_name_len);
3085 ffs->ms_os_descs_ext_prop_data_len);
3086 vla_item_with_sz(d, char, raw_descs, ffs->raw_descs_length);
3091 return -ENOTSUPP;
3096 return -ENOMEM;
3098 ffs->ms_os_descs_ext_prop_avail = vla_ptr(vlabuf, d, ext_prop);
3099 ffs->ms_os_descs_ext_prop_name_avail =
3101 ffs->ms_os_descs_ext_prop_data_avail =
3105 memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs,
3106 ffs->raw_descs_length);
3110 for (i = 0; i < ffs->eps_count; i++)
3111 eps_ptr[i].num = -1;
3114 * d_eps == vlabuf, func->eps used to kfree vlabuf later
3116 func->eps = vla_ptr(vlabuf, d, eps);
3117 func->interfaces_nums = vla_ptr(vlabuf, d, inums);
3125 func->function.fs_descriptors = vla_ptr(vlabuf, d, fs_descs);
3126 fs_len = ffs_do_descs(ffs->fs_descs_count,
3139 func->function.hs_descriptors = vla_ptr(vlabuf, d, hs_descs);
3140 hs_len = ffs_do_descs(ffs->hs_descs_count,
3142 d_raw_descs__sz - fs_len,
3153 func->function.ss_descriptors = func->function.ssp_descriptors =
3155 ss_len = ffs_do_descs(ffs->ss_descs_count,
3157 d_raw_descs__sz - fs_len - hs_len,
3172 ret = ffs_do_descs(ffs->fs_descs_count +
3173 (high ? ffs->hs_descs_count : 0) +
3174 (super ? ffs->ss_descs_count : 0),
3180 func->function.os_desc_table = vla_ptr(vlabuf, d, os_desc_table);
3181 if (c->cdev->use_os_string) {
3182 for (i = 0; i < ffs->interfaces_count; ++i) {
3185 desc = func->function.os_desc_table[i].os_desc =
3188 desc->ext_compat_id =
3190 INIT_LIST_HEAD(&desc->ext_prop);
3192 ret = ffs_do_os_descs(ffs->ms_os_descs_count,
3195 d_raw_descs__sz - fs_len - hs_len -
3201 func->function.os_desc_n =
3202 c->cdev->use_os_string ? ffs->interfaces_count : 0;
3224 if (ret && !--ffs_opts->refcnt)
3225 functionfs_unbind(func->ffs);
3244 struct ffs_data *ffs = func->ffs;
3247 if (alt != (unsigned)-1) {
3253 if (ffs->func)
3254 ffs_func_eps_disable(ffs->func);
3256 if (ffs->state == FFS_DEACTIVATED) {
3257 ffs->state = FFS_CLOSING;
3258 INIT_WORK(&ffs->reset_work, ffs_reset_work);
3259 schedule_work(&ffs->reset_work);
3260 return -ENODEV;
3263 if (ffs->state != FFS_ACTIVE)
3264 return -ENODEV;
3266 if (alt == (unsigned)-1) {
3267 ffs->func = NULL;
3272 ffs->func = func;
3281 ffs_func_set_alt(f, 0, (unsigned)-1);
3288 struct ffs_data *ffs = func->ffs;
3292 pr_vdebug("creq->bRequestType = %02x\n", creq->bRequestType);
3293 pr_vdebug("creq->bRequest = %02x\n", creq->bRequest);
3294 pr_vdebug("creq->wValue = %04x\n", le16_to_cpu(creq->wValue));
3295 pr_vdebug("creq->wIndex = %04x\n", le16_to_cpu(creq->wIndex));
3296 pr_vdebug("creq->wLength = %04x\n", le16_to_cpu(creq->wLength));
3302 * passed to usb_configuration->setup() (if one is set). No
3308 if (ffs->state != FFS_ACTIVE)
3309 return -ENODEV;
3311 switch (creq->bRequestType & USB_RECIP_MASK) {
3313 ret = ffs_func_revmap_intf(func, le16_to_cpu(creq->wIndex));
3319 ret = ffs_func_revmap_ep(func, le16_to_cpu(creq->wIndex));
3322 if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR)
3323 ret = func->ffs->eps_addrmap[ret];
3327 if (func->ffs->user_flags & FUNCTIONFS_ALL_CTRL_RECIP)
3328 ret = le16_to_cpu(creq->wIndex);
3330 return -EOPNOTSUPP;
3333 spin_lock_irqsave(&ffs->ev.waitq.lock, flags);
3334 ffs->ev.setup = *creq;
3335 ffs->ev.setup.wIndex = cpu_to_le16(ret);
3337 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags);
3339 return ffs->ev.setup.wLength == 0 ? USB_GADGET_DELAYED_STATUS : 0;
3348 if (config0 && !(func->ffs->user_flags & FUNCTIONFS_CONFIG0_SETUP))
3351 switch (creq->bRequestType & USB_RECIP_MASK) {
3354 le16_to_cpu(creq->wIndex)) >= 0);
3357 le16_to_cpu(creq->wIndex)) >= 0);
3359 return (bool) (func->ffs->user_flags &
3366 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_SUSPEND);
3371 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_RESUME);
3379 num = func->eps_revmap[num & USB_ENDPOINT_NUMBER_MASK];
3380 return num ? num : -EDOM;
3385 short *nums = func->interfaces_nums;
3386 unsigned count = func->ffs->interfaces_count;
3388 for (; count; --count, ++nums) {
3390 return nums - func->interfaces_nums;
3393 return -EDOM;
3409 if (strcmp(dev->name, name) == 0)
3425 if (dev->single)
3458 usb_put_function_instance(&opts->func_inst);
3478 ffs_release_dev(opts->dev);
3480 _ffs_free_dev(opts->dev);
3488 return -ENAMETOOLONG;
3489 return ffs_name_dev(to_f_fs_opts(fi)->dev, name);
3499 return ERR_PTR(-ENOMEM);
3501 opts->func_inst.set_inst_name = ffs_set_inst_name;
3502 opts->func_inst.free_func_inst = ffs_free_inst;
3510 opts->dev = dev;
3511 dev->opts = opts;
3513 config_group_init_type_name(&opts->func_inst.group, "",
3515 return &opts->func_inst;
3527 struct ffs_data *ffs = func->ffs;
3529 container_of(f->fi, struct f_fs_opts, func_inst);
3530 struct ffs_ep *ep = func->eps;
3531 unsigned count = ffs->eps_count;
3534 if (ffs->func == func) {
3536 ffs->func = NULL;
3540 drain_workqueue(ffs->io_completion_wq);
3543 if (!--opts->refcnt)
3547 spin_lock_irqsave(&func->ffs->eps_lock, flags);
3548 while (count--) {
3549 if (ep->ep && ep->req)
3550 usb_ep_free_request(ep->ep, ep->req);
3551 ep->req = NULL;
3554 spin_unlock_irqrestore(&func->ffs->eps_lock, flags);
3555 kfree(func->eps);
3556 func->eps = NULL;
3561 func->function.fs_descriptors = NULL;
3562 func->function.hs_descriptors = NULL;
3563 func->function.ss_descriptors = NULL;
3564 func->function.ssp_descriptors = NULL;
3565 func->interfaces_nums = NULL;
3575 return ERR_PTR(-ENOMEM);
3577 func->function.name = "Function FS Gadget";
3579 func->function.bind = ffs_func_bind;
3580 func->function.unbind = ffs_func_unbind;
3581 func->function.set_alt = ffs_func_set_alt;
3582 func->function.disable = ffs_func_disable;
3583 func->function.setup = ffs_func_setup;
3584 func->function.req_match = ffs_func_req_match;
3585 func->function.suspend = ffs_func_suspend;
3586 func->function.resume = ffs_func_resume;
3587 func->function.free_func = ffs_free;
3589 return &func->function;
3601 return ERR_PTR(-EBUSY);
3605 return ERR_PTR(-ENOMEM);
3615 list_add(&dev->entry, &ffs_devices);
3629 strscpy(dev->name, name, ARRAY_SIZE(dev->name));
3631 ret = -EBUSY;
3647 ret = -EBUSY;
3649 dev->single = true;
3661 list_del(&dev->entry);
3677 ret = -ENOENT;
3678 } else if (ffs_dev->mounted) {
3679 ret = -EBUSY;
3680 } else if (ffs_dev->ffs_acquire_dev_callback &&
3681 ffs_dev->ffs_acquire_dev_callback(ffs_dev)) {
3682 ret = -ENOENT;
3684 ffs_dev->mounted = true;
3685 ffs_dev->ffs_data = ffs_data;
3686 ffs_data->private_data = ffs_dev;
3697 if (ffs_dev && ffs_dev->mounted) {
3698 ffs_dev->mounted = false;
3699 if (ffs_dev->ffs_data) {
3700 ffs_dev->ffs_data->private_data = NULL;
3701 ffs_dev->ffs_data = NULL;
3704 if (ffs_dev->ffs_release_dev_callback)
3705 ffs_dev->ffs_release_dev_callback(ffs_dev);
3718 ffs_obj = ffs->private_data;
3720 ret = -EINVAL;
3723 if (WARN_ON(ffs_obj->desc_ready)) {
3724 ret = -EBUSY;
3728 ffs_obj->desc_ready = true;
3730 if (ffs_obj->ffs_ready_callback) {
3731 ret = ffs_obj->ffs_ready_callback(ffs);
3736 set_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags);
3750 ffs_obj = ffs->private_data;
3754 ffs_obj->desc_ready = false;
3756 if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags) &&
3757 ffs_obj->ffs_closed_callback)
3758 ffs_obj->ffs_closed_callback(ffs);
3760 if (ffs_obj->opts)
3761 opts = ffs_obj->opts;
3765 if (opts->no_configfs || !opts->func_inst.group.cg_item.ci_parent
3766 || !kref_read(&opts->func_inst.group.cg_item.ci_kref))
3769 ci = opts->func_inst.group.cg_item.ci_parent->ci_parent;
3772 if (test_bit(FFS_FL_BOUND, &ffs->flags))
3784 ? mutex_trylock(mutex) ? 0 : -EAGAIN