aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/f_fs.c
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-03-07 19:47:36 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-03-07 19:47:36 -0500
commit7338a0659365ec0fbdc6f79de8b9fba2280fd155 (patch)
tree876358e9d7187cad93d41b9e9918653fc24fa38a /drivers/usb/gadget/f_fs.c
parentc9050b64940a1b47dfa623630431fec400edbf33 (diff)
parent4b76e14d95f7b69e71eabc002dcb0dcb9ebb5340 (diff)
Merge tag 'usb-for-v3.15' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next
Felipe writes: usb: patches for v3.15 another substantial pull request with new features all over the place. dwc3 got a bit closer towards hibernation support with after a few patches re-factoring code to be reused for hibernation. Also in dwc3 two new workarounds for known silicon bugs have been implemented, some randconfig build errors have been fixed, and it was taught about the new generic phy layer. MUSB on AM335x now supports isochronous transfers thanks to George Cherian's work. The atmel_usba driver got two crash fixes: one when no endpoint was specified in DeviceTree data and another when stopping the UDC in DEBUG builds. Function FS got a much needed fix to ffs_epfile_io() which was copying too much data to userspace in some cases. The printer gadget got a fix for a possible deadlock and plugged a memory leak. Ethernet drivers now use NAPI for RX which gives improved throughput. Other than that, the usual miscelaneous fixes, cleanups, and the like. Signed-of-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/gadget/f_fs.c')
-rw-r--r--drivers/usb/gadget/f_fs.c612
1 files changed, 476 insertions, 136 deletions
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index 2b4334394076..10c086afa2f4 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -28,6 +28,10 @@
28#include <linux/usb/composite.h> 28#include <linux/usb/composite.h>
29#include <linux/usb/functionfs.h> 29#include <linux/usb/functionfs.h>
30 30
31#include <linux/aio.h>
32#include <linux/mmu_context.h>
33#include <linux/poll.h>
34
31#include "u_fs.h" 35#include "u_fs.h"
32#include "configfs.h" 36#include "configfs.h"
33 37
@@ -99,6 +103,14 @@ static struct ffs_function *ffs_func_from_usb(struct usb_function *f)
99} 103}
100 104
101 105
106static inline enum ffs_setup_state
107ffs_setup_state_clear_cancelled(struct ffs_data *ffs)
108{
109 return (enum ffs_setup_state)
110 cmpxchg(&ffs->setup_state, FFS_SETUP_CANCELLED, FFS_NO_SETUP);
111}
112
113
102static void ffs_func_eps_disable(struct ffs_function *func); 114static void ffs_func_eps_disable(struct ffs_function *func);
103static int __must_check ffs_func_eps_enable(struct ffs_function *func); 115static int __must_check ffs_func_eps_enable(struct ffs_function *func);
104 116
@@ -122,8 +134,8 @@ struct ffs_ep {
122 struct usb_ep *ep; /* P: ffs->eps_lock */ 134 struct usb_ep *ep; /* P: ffs->eps_lock */
123 struct usb_request *req; /* P: epfile->mutex */ 135 struct usb_request *req; /* P: epfile->mutex */
124 136
125 /* [0]: full speed, [1]: high speed */ 137 /* [0]: full speed, [1]: high speed, [2]: super speed */
126 struct usb_endpoint_descriptor *descs[2]; 138 struct usb_endpoint_descriptor *descs[3];
127 139
128 u8 num; 140 u8 num;
129 141
@@ -148,6 +160,25 @@ struct ffs_epfile {
148 unsigned char _pad; 160 unsigned char _pad;
149}; 161};
150 162
163/* ffs_io_data structure ***************************************************/
164
165struct ffs_io_data {
166 bool aio;
167 bool read;
168
169 struct kiocb *kiocb;
170 const struct iovec *iovec;
171 unsigned long nr_segs;
172 char __user *buf;
173 size_t len;
174
175 struct mm_struct *mm;
176 struct work_struct work;
177
178 struct usb_ep *ep;
179 struct usb_request *req;
180};
181
151static int __must_check ffs_epfiles_create(struct ffs_data *ffs); 182static int __must_check ffs_epfiles_create(struct ffs_data *ffs);
152static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count); 183static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count);
153 184
@@ -161,8 +192,10 @@ ffs_sb_create_file(struct super_block *sb, const char *name, void *data,
161DEFINE_MUTEX(ffs_lock); 192DEFINE_MUTEX(ffs_lock);
162EXPORT_SYMBOL(ffs_lock); 193EXPORT_SYMBOL(ffs_lock);
163 194
164static struct ffs_dev *ffs_find_dev(const char *name); 195static struct ffs_dev *_ffs_find_dev(const char *name);
196static struct ffs_dev *_ffs_alloc_dev(void);
165static int _ffs_name_dev(struct ffs_dev *dev, const char *name); 197static int _ffs_name_dev(struct ffs_dev *dev, const char *name);
198static void _ffs_free_dev(struct ffs_dev *dev);
166static void *ffs_acquire_dev(const char *dev_name); 199static void *ffs_acquire_dev(const char *dev_name);
167static void ffs_release_dev(struct ffs_data *ffs_data); 200static void ffs_release_dev(struct ffs_data *ffs_data);
168static int ffs_ready(struct ffs_data *ffs); 201static int ffs_ready(struct ffs_data *ffs);
@@ -218,7 +251,7 @@ static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len)
218 } 251 }
219 252
220 ffs->setup_state = FFS_NO_SETUP; 253 ffs->setup_state = FFS_NO_SETUP;
221 return ffs->ep0req_status; 254 return req->status ? req->status : req->actual;
222} 255}
223 256
224static int __ffs_ep0_stall(struct ffs_data *ffs) 257static int __ffs_ep0_stall(struct ffs_data *ffs)
@@ -244,7 +277,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
244 ENTER(); 277 ENTER();
245 278
246 /* Fast check if setup was canceled */ 279 /* Fast check if setup was canceled */
247 if (FFS_SETUP_STATE(ffs) == FFS_SETUP_CANCELED) 280 if (ffs_setup_state_clear_cancelled(ffs) == FFS_SETUP_CANCELLED)
248 return -EIDRM; 281 return -EIDRM;
249 282
250 /* Acquire mutex */ 283 /* Acquire mutex */
@@ -310,8 +343,8 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
310 * rather then _irqsave 343 * rather then _irqsave
311 */ 344 */
312 spin_lock_irq(&ffs->ev.waitq.lock); 345 spin_lock_irq(&ffs->ev.waitq.lock);
313 switch (FFS_SETUP_STATE(ffs)) { 346 switch (ffs_setup_state_clear_cancelled(ffs)) {
314 case FFS_SETUP_CANCELED: 347 case FFS_SETUP_CANCELLED:
315 ret = -EIDRM; 348 ret = -EIDRM;
316 goto done_spin; 349 goto done_spin;
317 350
@@ -346,7 +379,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
346 /* 379 /*
347 * We are guaranteed to be still in FFS_ACTIVE state 380 * We are guaranteed to be still in FFS_ACTIVE state
348 * but the state of setup could have changed from 381 * but the state of setup could have changed from
349 * FFS_SETUP_PENDING to FFS_SETUP_CANCELED so we need 382 * FFS_SETUP_PENDING to FFS_SETUP_CANCELLED so we need
350 * to check for that. If that happened we copied data 383 * to check for that. If that happened we copied data
351 * from user space in vain but it's unlikely. 384 * from user space in vain but it's unlikely.
352 * 385 *
@@ -355,7 +388,8 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
355 * transition can be performed and it's protected by 388 * transition can be performed and it's protected by
356 * mutex. 389 * mutex.
357 */ 390 */
358 if (FFS_SETUP_STATE(ffs) == FFS_SETUP_CANCELED) { 391 if (ffs_setup_state_clear_cancelled(ffs) ==
392 FFS_SETUP_CANCELLED) {
359 ret = -EIDRM; 393 ret = -EIDRM;
360done_spin: 394done_spin:
361 spin_unlock_irq(&ffs->ev.waitq.lock); 395 spin_unlock_irq(&ffs->ev.waitq.lock);
@@ -421,7 +455,7 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
421 ENTER(); 455 ENTER();
422 456
423 /* Fast check if setup was canceled */ 457 /* Fast check if setup was canceled */
424 if (FFS_SETUP_STATE(ffs) == FFS_SETUP_CANCELED) 458 if (ffs_setup_state_clear_cancelled(ffs) == FFS_SETUP_CANCELLED)
425 return -EIDRM; 459 return -EIDRM;
426 460
427 /* Acquire mutex */ 461 /* Acquire mutex */
@@ -441,8 +475,8 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
441 */ 475 */
442 spin_lock_irq(&ffs->ev.waitq.lock); 476 spin_lock_irq(&ffs->ev.waitq.lock);
443 477
444 switch (FFS_SETUP_STATE(ffs)) { 478 switch (ffs_setup_state_clear_cancelled(ffs)) {
445 case FFS_SETUP_CANCELED: 479 case FFS_SETUP_CANCELLED:
446 ret = -EIDRM; 480 ret = -EIDRM;
447 break; 481 break;
448 482
@@ -489,7 +523,8 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
489 spin_lock_irq(&ffs->ev.waitq.lock); 523 spin_lock_irq(&ffs->ev.waitq.lock);
490 524
491 /* See ffs_ep0_write() */ 525 /* See ffs_ep0_write() */
492 if (FFS_SETUP_STATE(ffs) == FFS_SETUP_CANCELED) { 526 if (ffs_setup_state_clear_cancelled(ffs) ==
527 FFS_SETUP_CANCELLED) {
493 ret = -EIDRM; 528 ret = -EIDRM;
494 break; 529 break;
495 } 530 }
@@ -558,6 +593,45 @@ static long ffs_ep0_ioctl(struct file *file, unsigned code, unsigned long value)
558 return ret; 593 return ret;
559} 594}
560 595
596static unsigned int ffs_ep0_poll(struct file *file, poll_table *wait)
597{
598 struct ffs_data *ffs = file->private_data;
599 unsigned int mask = POLLWRNORM;
600 int ret;
601
602 poll_wait(file, &ffs->ev.waitq, wait);
603
604 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK);
605 if (unlikely(ret < 0))
606 return mask;
607
608 switch (ffs->state) {
609 case FFS_READ_DESCRIPTORS:
610 case FFS_READ_STRINGS:
611 mask |= POLLOUT;
612 break;
613
614 case FFS_ACTIVE:
615 switch (ffs->setup_state) {
616 case FFS_NO_SETUP:
617 if (ffs->ev.count)
618 mask |= POLLIN;
619 break;
620
621 case FFS_SETUP_PENDING:
622 case FFS_SETUP_CANCELLED:
623 mask |= (POLLIN | POLLOUT);
624 break;
625 }
626 case FFS_CLOSING:
627 break;
628 }
629
630 mutex_unlock(&ffs->mutex);
631
632 return mask;
633}
634
561static const struct file_operations ffs_ep0_operations = { 635static const struct file_operations ffs_ep0_operations = {
562 .llseek = no_llseek, 636 .llseek = no_llseek,
563 637
@@ -566,6 +640,7 @@ static const struct file_operations ffs_ep0_operations = {
566 .read = ffs_ep0_read, 640 .read = ffs_ep0_read,
567 .release = ffs_ep0_release, 641 .release = ffs_ep0_release,
568 .unlocked_ioctl = ffs_ep0_ioctl, 642 .unlocked_ioctl = ffs_ep0_ioctl,
643 .poll = ffs_ep0_poll,
569}; 644};
570 645
571 646
@@ -581,8 +656,52 @@ static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req)
581 } 656 }
582} 657}
583 658
584static ssize_t ffs_epfile_io(struct file *file, 659static void ffs_user_copy_worker(struct work_struct *work)
585 char __user *buf, size_t len, int read) 660{
661 struct ffs_io_data *io_data = container_of(work, struct ffs_io_data,
662 work);
663 int ret = io_data->req->status ? io_data->req->status :
664 io_data->req->actual;
665
666 if (io_data->read && ret > 0) {
667 int i;
668 size_t pos = 0;
669 use_mm(io_data->mm);
670 for (i = 0; i < io_data->nr_segs; i++) {
671 if (unlikely(copy_to_user(io_data->iovec[i].iov_base,
672 &io_data->buf[pos],
673 io_data->iovec[i].iov_len))) {
674 ret = -EFAULT;
675 break;
676 }
677 pos += io_data->iovec[i].iov_len;
678 }
679 unuse_mm(io_data->mm);
680 }
681
682 aio_complete(io_data->kiocb, ret, ret);
683
684 usb_ep_free_request(io_data->ep, io_data->req);
685
686 io_data->kiocb->private = NULL;
687 if (io_data->read)
688 kfree(io_data->iovec);
689 kfree(io_data->buf);
690 kfree(io_data);
691}
692
693static void ffs_epfile_async_io_complete(struct usb_ep *_ep,
694 struct usb_request *req)
695{
696 struct ffs_io_data *io_data = req->context;
697
698 ENTER();
699
700 INIT_WORK(&io_data->work, ffs_user_copy_worker);
701 schedule_work(&io_data->work);
702}
703
704static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
586{ 705{
587 struct ffs_epfile *epfile = file->private_data; 706 struct ffs_epfile *epfile = file->private_data;
588 struct ffs_ep *ep; 707 struct ffs_ep *ep;
@@ -612,7 +731,7 @@ static ssize_t ffs_epfile_io(struct file *file,
612 } 731 }
613 732
614 /* Do we halt? */ 733 /* Do we halt? */
615 halt = !read == !epfile->in; 734 halt = (!io_data->read == !epfile->in);
616 if (halt && epfile->isoc) { 735 if (halt && epfile->isoc) {
617 ret = -EINVAL; 736 ret = -EINVAL;
618 goto error; 737 goto error;
@@ -630,15 +749,32 @@ static ssize_t ffs_epfile_io(struct file *file,
630 * Controller may require buffer size to be aligned to 749 * Controller may require buffer size to be aligned to
631 * maxpacketsize of an out endpoint. 750 * maxpacketsize of an out endpoint.
632 */ 751 */
633 data_len = read ? usb_ep_align_maybe(gadget, ep->ep, len) : len; 752 data_len = io_data->read ?
753 usb_ep_align_maybe(gadget, ep->ep, io_data->len) :
754 io_data->len;
634 755
635 data = kmalloc(data_len, GFP_KERNEL); 756 data = kmalloc(data_len, GFP_KERNEL);
636 if (unlikely(!data)) 757 if (unlikely(!data))
637 return -ENOMEM; 758 return -ENOMEM;
638 759 if (io_data->aio && !io_data->read) {
639 if (!read && unlikely(copy_from_user(data, buf, len))) { 760 int i;
640 ret = -EFAULT; 761 size_t pos = 0;
641 goto error; 762 for (i = 0; i < io_data->nr_segs; i++) {
763 if (unlikely(copy_from_user(&data[pos],
764 io_data->iovec[i].iov_base,
765 io_data->iovec[i].iov_len))) {
766 ret = -EFAULT;
767 goto error;
768 }
769 pos += io_data->iovec[i].iov_len;
770 }
771 } else {
772 if (!io_data->read &&
773 unlikely(__copy_from_user(data, io_data->buf,
774 io_data->len))) {
775 ret = -EFAULT;
776 goto error;
777 }
642 } 778 }
643 } 779 }
644 780
@@ -661,40 +797,74 @@ static ssize_t ffs_epfile_io(struct file *file,
661 ret = -EBADMSG; 797 ret = -EBADMSG;
662 } else { 798 } else {
663 /* Fire the request */ 799 /* Fire the request */
664 DECLARE_COMPLETION_ONSTACK(done); 800 struct usb_request *req;
665 801
666 struct usb_request *req = ep->req; 802 if (io_data->aio) {
667 req->context = &done; 803 req = usb_ep_alloc_request(ep->ep, GFP_KERNEL);
668 req->complete = ffs_epfile_io_complete; 804 if (unlikely(!req))
669 req->buf = data; 805 goto error;
670 req->length = data_len;
671 806
672 ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC); 807 req->buf = data;
808 req->length = io_data->len;
673 809
674 spin_unlock_irq(&epfile->ffs->eps_lock); 810 io_data->buf = data;
811 io_data->ep = ep->ep;
812 io_data->req = req;
675 813
676 if (unlikely(ret < 0)) { 814 req->context = io_data;
677 /* nop */ 815 req->complete = ffs_epfile_async_io_complete;
678 } else if (unlikely(wait_for_completion_interruptible(&done))) { 816
679 ret = -EINTR; 817 ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC);
680 usb_ep_dequeue(ep->ep, req); 818 if (unlikely(ret)) {
819 usb_ep_free_request(ep->ep, req);
820 goto error;
821 }
822 ret = -EIOCBQUEUED;
823
824 spin_unlock_irq(&epfile->ffs->eps_lock);
681 } else { 825 } else {
682 /* 826 DECLARE_COMPLETION_ONSTACK(done);
683 * XXX We may end up silently droping data here. 827
684 * Since data_len (i.e. req->length) may be bigger 828 req = ep->req;
685 * than len (after being rounded up to maxpacketsize), 829 req->buf = data;
686 * we may end up with more data then user space has 830 req->length = io_data->len;
687 * space for. 831
688 */ 832 req->context = &done;
689 ret = ep->status; 833 req->complete = ffs_epfile_io_complete;
690 if (read && ret > 0 && 834
691 unlikely(copy_to_user(buf, data, 835 ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC);
692 min_t(size_t, ret, len)))) 836
693 ret = -EFAULT; 837 spin_unlock_irq(&epfile->ffs->eps_lock);
838
839 if (unlikely(ret < 0)) {
840 /* nop */
841 } else if (unlikely(
842 wait_for_completion_interruptible(&done))) {
843 ret = -EINTR;
844 usb_ep_dequeue(ep->ep, req);
845 } else {
846 /*
847 * XXX We may end up silently droping data
848 * here. Since data_len (i.e. req->length) may
849 * be bigger than len (after being rounded up
850 * to maxpacketsize), we may end up with more
851 * data then user space has space for.
852 */
853 ret = ep->status;
854 if (io_data->read && ret > 0) {
855 ret = min_t(size_t, ret, io_data->len);
856
857 if (unlikely(copy_to_user(io_data->buf,
858 data, ret)))
859 ret = -EFAULT;
860 }
861 }
862 kfree(data);
694 } 863 }
695 } 864 }
696 865
697 mutex_unlock(&epfile->mutex); 866 mutex_unlock(&epfile->mutex);
867 return ret;
698error: 868error:
699 kfree(data); 869 kfree(data);
700 return ret; 870 return ret;
@@ -704,17 +874,31 @@ static ssize_t
704ffs_epfile_write(struct file *file, const char __user *buf, size_t len, 874ffs_epfile_write(struct file *file, const char __user *buf, size_t len,
705 loff_t *ptr) 875 loff_t *ptr)
706{ 876{
877 struct ffs_io_data io_data;
878
707 ENTER(); 879 ENTER();
708 880
709 return ffs_epfile_io(file, (char __user *)buf, len, 0); 881 io_data.aio = false;
882 io_data.read = false;
883 io_data.buf = (char * __user)buf;
884 io_data.len = len;
885
886 return ffs_epfile_io(file, &io_data);
710} 887}
711 888
712static ssize_t 889static ssize_t
713ffs_epfile_read(struct file *file, char __user *buf, size_t len, loff_t *ptr) 890ffs_epfile_read(struct file *file, char __user *buf, size_t len, loff_t *ptr)
714{ 891{
892 struct ffs_io_data io_data;
893
715 ENTER(); 894 ENTER();
716 895
717 return ffs_epfile_io(file, buf, len, 1); 896 io_data.aio = false;
897 io_data.read = true;
898 io_data.buf = buf;
899 io_data.len = len;
900
901 return ffs_epfile_io(file, &io_data);
718} 902}
719 903
720static int 904static int
@@ -733,6 +917,89 @@ ffs_epfile_open(struct inode *inode, struct file *file)
733 return 0; 917 return 0;
734} 918}
735 919
920static int ffs_aio_cancel(struct kiocb *kiocb)
921{
922 struct ffs_io_data *io_data = kiocb->private;
923 struct ffs_epfile *epfile = kiocb->ki_filp->private_data;
924 int value;
925
926 ENTER();
927
928 spin_lock_irq(&epfile->ffs->eps_lock);
929
930 if (likely(io_data && io_data->ep && io_data->req))
931 value = usb_ep_dequeue(io_data->ep, io_data->req);
932 else
933 value = -EINVAL;
934
935 spin_unlock_irq(&epfile->ffs->eps_lock);
936
937 return value;
938}
939
940static ssize_t ffs_epfile_aio_write(struct kiocb *kiocb,
941 const struct iovec *iovec,
942 unsigned long nr_segs, loff_t loff)
943{
944 struct ffs_io_data *io_data;
945
946 ENTER();
947
948 io_data = kmalloc(sizeof(*io_data), GFP_KERNEL);
949 if (unlikely(!io_data))
950 return -ENOMEM;
951
952 io_data->aio = true;
953 io_data->read = false;
954 io_data->kiocb = kiocb;
955 io_data->iovec = iovec;
956 io_data->nr_segs = nr_segs;
957 io_data->len = kiocb->ki_nbytes;
958 io_data->mm = current->mm;
959
960 kiocb->private = io_data;
961
962 kiocb_set_cancel_fn(kiocb, ffs_aio_cancel);
963
964 return ffs_epfile_io(kiocb->ki_filp, io_data);
965}
966
967static ssize_t ffs_epfile_aio_read(struct kiocb *kiocb,
968 const struct iovec *iovec,
969 unsigned long nr_segs, loff_t loff)
970{
971 struct ffs_io_data *io_data;
972 struct iovec *iovec_copy;
973
974 ENTER();
975
976 iovec_copy = kmalloc_array(nr_segs, sizeof(*iovec_copy), GFP_KERNEL);
977 if (unlikely(!iovec_copy))
978 return -ENOMEM;
979
980 memcpy(iovec_copy, iovec, sizeof(struct iovec)*nr_segs);
981
982 io_data = kmalloc(sizeof(*io_data), GFP_KERNEL);
983 if (unlikely(!io_data)) {
984 kfree(iovec_copy);
985 return -ENOMEM;
986 }
987
988 io_data->aio = true;
989 io_data->read = true;
990 io_data->kiocb = kiocb;
991 io_data->iovec = iovec_copy;
992 io_data->nr_segs = nr_segs;
993 io_data->len = kiocb->ki_nbytes;
994 io_data->mm = current->mm;
995
996 kiocb->private = io_data;
997
998 kiocb_set_cancel_fn(kiocb, ffs_aio_cancel);
999
1000 return ffs_epfile_io(kiocb->ki_filp, io_data);
1001}
1002
736static int 1003static int
737ffs_epfile_release(struct inode *inode, struct file *file) 1004ffs_epfile_release(struct inode *inode, struct file *file)
738{ 1005{
@@ -789,6 +1056,8 @@ static const struct file_operations ffs_epfile_operations = {
789 .open = ffs_epfile_open, 1056 .open = ffs_epfile_open,
790 .write = ffs_epfile_write, 1057 .write = ffs_epfile_write,
791 .read = ffs_epfile_read, 1058 .read = ffs_epfile_read,
1059 .aio_write = ffs_epfile_aio_write,
1060 .aio_read = ffs_epfile_aio_read,
792 .release = ffs_epfile_release, 1061 .release = ffs_epfile_release,
793 .unlocked_ioctl = ffs_epfile_ioctl, 1062 .unlocked_ioctl = ffs_epfile_ioctl,
794}; 1063};
@@ -1172,7 +1441,7 @@ static void ffs_data_clear(struct ffs_data *ffs)
1172 if (ffs->epfiles) 1441 if (ffs->epfiles)
1173 ffs_epfiles_destroy(ffs->epfiles, ffs->eps_count); 1442 ffs_epfiles_destroy(ffs->epfiles, ffs->eps_count);
1174 1443
1175 kfree(ffs->raw_descs); 1444 kfree(ffs->raw_descs_data);
1176 kfree(ffs->raw_strings); 1445 kfree(ffs->raw_strings);
1177 kfree(ffs->stringtabs); 1446 kfree(ffs->stringtabs);
1178} 1447}
@@ -1184,14 +1453,15 @@ static void ffs_data_reset(struct ffs_data *ffs)
1184 ffs_data_clear(ffs); 1453 ffs_data_clear(ffs);
1185 1454
1186 ffs->epfiles = NULL; 1455 ffs->epfiles = NULL;
1456 ffs->raw_descs_data = NULL;
1187 ffs->raw_descs = NULL; 1457 ffs->raw_descs = NULL;
1188 ffs->raw_strings = NULL; 1458 ffs->raw_strings = NULL;
1189 ffs->stringtabs = NULL; 1459 ffs->stringtabs = NULL;
1190 1460
1191 ffs->raw_descs_length = 0; 1461 ffs->raw_descs_length = 0;
1192 ffs->raw_fs_descs_length = 0;
1193 ffs->fs_descs_count = 0; 1462 ffs->fs_descs_count = 0;
1194 ffs->hs_descs_count = 0; 1463 ffs->hs_descs_count = 0;
1464 ffs->ss_descs_count = 0;
1195 1465
1196 ffs->strings_count = 0; 1466 ffs->strings_count = 0;
1197 ffs->interfaces_count = 0; 1467 ffs->interfaces_count = 0;
@@ -1334,7 +1604,24 @@ static int ffs_func_eps_enable(struct ffs_function *func)
1334 spin_lock_irqsave(&func->ffs->eps_lock, flags); 1604 spin_lock_irqsave(&func->ffs->eps_lock, flags);
1335 do { 1605 do {
1336 struct usb_endpoint_descriptor *ds; 1606 struct usb_endpoint_descriptor *ds;
1337 ds = ep->descs[ep->descs[1] ? 1 : 0]; 1607 int desc_idx;
1608
1609 if (ffs->gadget->speed == USB_SPEED_SUPER)
1610 desc_idx = 2;
1611 else if (ffs->gadget->speed == USB_SPEED_HIGH)
1612 desc_idx = 1;
1613 else
1614 desc_idx = 0;
1615
1616 /* fall-back to lower speed if desc missing for current speed */
1617 do {
1618 ds = ep->descs[desc_idx];
1619 } while (!ds && --desc_idx >= 0);
1620
1621 if (!ds) {
1622 ret = -EINVAL;
1623 break;
1624 }
1338 1625
1339 ep->ep->driver_data = ep; 1626 ep->ep->driver_data = ep;
1340 ep->ep->desc = ds; 1627 ep->ep->desc = ds;
@@ -1469,6 +1756,12 @@ static int __must_check ffs_do_desc(char *data, unsigned len,
1469 } 1756 }
1470 break; 1757 break;
1471 1758
1759 case USB_DT_SS_ENDPOINT_COMP:
1760 pr_vdebug("EP SS companion descriptor\n");
1761 if (length != sizeof(struct usb_ss_ep_comp_descriptor))
1762 goto inv_length;
1763 break;
1764
1472 case USB_DT_OTHER_SPEED_CONFIG: 1765 case USB_DT_OTHER_SPEED_CONFIG:
1473 case USB_DT_INTERFACE_POWER: 1766 case USB_DT_INTERFACE_POWER:
1474 case USB_DT_DEBUG: 1767 case USB_DT_DEBUG:
@@ -1579,60 +1872,76 @@ static int __ffs_data_do_entity(enum ffs_entity_type type,
1579static int __ffs_data_got_descs(struct ffs_data *ffs, 1872static int __ffs_data_got_descs(struct ffs_data *ffs,
1580 char *const _data, size_t len) 1873 char *const _data, size_t len)
1581{ 1874{
1582 unsigned fs_count, hs_count; 1875 char *data = _data, *raw_descs;
1583 int fs_len, ret = -EINVAL; 1876 unsigned counts[3], flags;
1584 char *data = _data; 1877 int ret = -EINVAL, i;
1585 1878
1586 ENTER(); 1879 ENTER();
1587 1880
1588 if (unlikely(get_unaligned_le32(data) != FUNCTIONFS_DESCRIPTORS_MAGIC || 1881 if (get_unaligned_le32(data + 4) != len)
1589 get_unaligned_le32(data + 4) != len))
1590 goto error; 1882 goto error;
1591 fs_count = get_unaligned_le32(data + 8);
1592 hs_count = get_unaligned_le32(data + 12);
1593
1594 if (!fs_count && !hs_count)
1595 goto einval;
1596 1883
1597 data += 16; 1884 switch (get_unaligned_le32(data)) {
1598 len -= 16; 1885 case FUNCTIONFS_DESCRIPTORS_MAGIC:
1599 1886 flags = FUNCTIONFS_HAS_FS_DESC | FUNCTIONFS_HAS_HS_DESC;
1600 if (likely(fs_count)) { 1887 data += 8;
1601 fs_len = ffs_do_descs(fs_count, data, len, 1888 len -= 8;
1602 __ffs_data_do_entity, ffs); 1889 break;
1603 if (unlikely(fs_len < 0)) { 1890 case FUNCTIONFS_DESCRIPTORS_MAGIC_V2:
1604 ret = fs_len; 1891 flags = get_unaligned_le32(data + 8);
1892 if (flags & ~(FUNCTIONFS_HAS_FS_DESC |
1893 FUNCTIONFS_HAS_HS_DESC |
1894 FUNCTIONFS_HAS_SS_DESC)) {
1895 ret = -ENOSYS;
1605 goto error; 1896 goto error;
1606 } 1897 }
1898 data += 12;
1899 len -= 12;
1900 break;
1901 default:
1902 goto error;
1903 }
1607 1904
1608 data += fs_len; 1905 /* Read fs_count, hs_count and ss_count (if present) */
1609 len -= fs_len; 1906 for (i = 0; i < 3; ++i) {
1610 } else { 1907 if (!(flags & (1 << i))) {
1611 fs_len = 0; 1908 counts[i] = 0;
1909 } else if (len < 4) {
1910 goto error;
1911 } else {
1912 counts[i] = get_unaligned_le32(data);
1913 data += 4;
1914 len -= 4;
1915 }
1612 } 1916 }
1613 1917
1614 if (likely(hs_count)) { 1918 /* Read descriptors */
1615 ret = ffs_do_descs(hs_count, data, len, 1919 raw_descs = data;
1920 for (i = 0; i < 3; ++i) {
1921 if (!counts[i])
1922 continue;
1923 ret = ffs_do_descs(counts[i], data, len,
1616 __ffs_data_do_entity, ffs); 1924 __ffs_data_do_entity, ffs);
1617 if (unlikely(ret < 0)) 1925 if (ret < 0)
1618 goto error; 1926 goto error;
1619 } else { 1927 data += ret;
1620 ret = 0; 1928 len -= ret;
1621 } 1929 }
1622 1930
1623 if (unlikely(len != ret)) 1931 if (raw_descs == data || len) {
1624 goto einval; 1932 ret = -EINVAL;
1933 goto error;
1934 }
1625 1935
1626 ffs->raw_fs_descs_length = fs_len; 1936 ffs->raw_descs_data = _data;
1627 ffs->raw_descs_length = fs_len + ret; 1937 ffs->raw_descs = raw_descs;
1628 ffs->raw_descs = _data; 1938 ffs->raw_descs_length = data - raw_descs;
1629 ffs->fs_descs_count = fs_count; 1939 ffs->fs_descs_count = counts[0];
1630 ffs->hs_descs_count = hs_count; 1940 ffs->hs_descs_count = counts[1];
1941 ffs->ss_descs_count = counts[2];
1631 1942
1632 return 0; 1943 return 0;
1633 1944
1634einval:
1635 ret = -EINVAL;
1636error: 1945error:
1637 kfree(_data); 1946 kfree(_data);
1638 return ret; 1947 return ret;
@@ -1789,7 +2098,7 @@ static void __ffs_event_add(struct ffs_data *ffs,
1789 * the source does nothing. 2098 * the source does nothing.
1790 */ 2099 */
1791 if (ffs->setup_state == FFS_SETUP_PENDING) 2100 if (ffs->setup_state == FFS_SETUP_PENDING)
1792 ffs->setup_state = FFS_SETUP_CANCELED; 2101 ffs->setup_state = FFS_SETUP_CANCELLED;
1793 2102
1794 switch (type) { 2103 switch (type) {
1795 case FUNCTIONFS_RESUME: 2104 case FUNCTIONFS_RESUME:
@@ -1850,21 +2159,28 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep,
1850 struct usb_endpoint_descriptor *ds = (void *)desc; 2159 struct usb_endpoint_descriptor *ds = (void *)desc;
1851 struct ffs_function *func = priv; 2160 struct ffs_function *func = priv;
1852 struct ffs_ep *ffs_ep; 2161 struct ffs_ep *ffs_ep;
1853 2162 unsigned ep_desc_id, idx;
1854 /* 2163 static const char *speed_names[] = { "full", "high", "super" };
1855 * If hs_descriptors is not NULL then we are reading hs
1856 * descriptors now
1857 */
1858 const int isHS = func->function.hs_descriptors != NULL;
1859 unsigned idx;
1860 2164
1861 if (type != FFS_DESCRIPTOR) 2165 if (type != FFS_DESCRIPTOR)
1862 return 0; 2166 return 0;
1863 2167
1864 if (isHS) 2168 /*
2169 * If ss_descriptors is not NULL, we are reading super speed
2170 * descriptors; if hs_descriptors is not NULL, we are reading high
2171 * speed descriptors; otherwise, we are reading full speed
2172 * descriptors.
2173 */
2174 if (func->function.ss_descriptors) {
2175 ep_desc_id = 2;
2176 func->function.ss_descriptors[(long)valuep] = desc;
2177 } else if (func->function.hs_descriptors) {
2178 ep_desc_id = 1;
1865 func->function.hs_descriptors[(long)valuep] = desc; 2179 func->function.hs_descriptors[(long)valuep] = desc;
1866 else 2180 } else {
2181 ep_desc_id = 0;
1867 func->function.fs_descriptors[(long)valuep] = desc; 2182 func->function.fs_descriptors[(long)valuep] = desc;
2183 }
1868 2184
1869 if (!desc || desc->bDescriptorType != USB_DT_ENDPOINT) 2185 if (!desc || desc->bDescriptorType != USB_DT_ENDPOINT)
1870 return 0; 2186 return 0;
@@ -1872,13 +2188,13 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep,
1872 idx = (ds->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) - 1; 2188 idx = (ds->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) - 1;
1873 ffs_ep = func->eps + idx; 2189 ffs_ep = func->eps + idx;
1874 2190
1875 if (unlikely(ffs_ep->descs[isHS])) { 2191 if (unlikely(ffs_ep->descs[ep_desc_id])) {
1876 pr_vdebug("two %sspeed descriptors for EP %d\n", 2192 pr_err("two %sspeed descriptors for EP %d\n",
1877 isHS ? "high" : "full", 2193 speed_names[ep_desc_id],
1878 ds->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 2194 ds->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
1879 return -EINVAL; 2195 return -EINVAL;
1880 } 2196 }
1881 ffs_ep->descs[isHS] = ds; 2197 ffs_ep->descs[ep_desc_id] = ds;
1882 2198
1883 ffs_dump_mem(": Original ep desc", ds, ds->bLength); 2199 ffs_dump_mem(": Original ep desc", ds, ds->bLength);
1884 if (ffs_ep->ep) { 2200 if (ffs_ep->ep) {
@@ -2022,8 +2338,10 @@ static int _ffs_func_bind(struct usb_configuration *c,
2022 const int full = !!func->ffs->fs_descs_count; 2338 const int full = !!func->ffs->fs_descs_count;
2023 const int high = gadget_is_dualspeed(func->gadget) && 2339 const int high = gadget_is_dualspeed(func->gadget) &&
2024 func->ffs->hs_descs_count; 2340 func->ffs->hs_descs_count;
2341 const int super = gadget_is_superspeed(func->gadget) &&
2342 func->ffs->ss_descs_count;
2025 2343
2026 int ret; 2344 int fs_len, hs_len, ret;
2027 2345
2028 /* Make it a single chunk, less management later on */ 2346 /* Make it a single chunk, less management later on */
2029 vla_group(d); 2347 vla_group(d);
@@ -2032,15 +2350,16 @@ static int _ffs_func_bind(struct usb_configuration *c,
2032 full ? ffs->fs_descs_count + 1 : 0); 2350 full ? ffs->fs_descs_count + 1 : 0);
2033 vla_item_with_sz(d, struct usb_descriptor_header *, hs_descs, 2351 vla_item_with_sz(d, struct usb_descriptor_header *, hs_descs,
2034 high ? ffs->hs_descs_count + 1 : 0); 2352 high ? ffs->hs_descs_count + 1 : 0);
2353 vla_item_with_sz(d, struct usb_descriptor_header *, ss_descs,
2354 super ? ffs->ss_descs_count + 1 : 0);
2035 vla_item_with_sz(d, short, inums, ffs->interfaces_count); 2355 vla_item_with_sz(d, short, inums, ffs->interfaces_count);
2036 vla_item_with_sz(d, char, raw_descs, 2356 vla_item_with_sz(d, char, raw_descs, ffs->raw_descs_length);
2037 high ? ffs->raw_descs_length : ffs->raw_fs_descs_length);
2038 char *vlabuf; 2357 char *vlabuf;
2039 2358
2040 ENTER(); 2359 ENTER();
2041 2360
2042 /* Only high speed but not supported by gadget? */ 2361 /* Has descriptors only for speeds gadget does not support */
2043 if (unlikely(!(full | high))) 2362 if (unlikely(!(full | high | super)))
2044 return -ENOTSUPP; 2363 return -ENOTSUPP;
2045 2364
2046 /* Allocate a single chunk, less management later on */ 2365 /* Allocate a single chunk, less management later on */
@@ -2050,8 +2369,10 @@ static int _ffs_func_bind(struct usb_configuration *c,
2050 2369
2051 /* Zero */ 2370 /* Zero */
2052 memset(vla_ptr(vlabuf, d, eps), 0, d_eps__sz); 2371 memset(vla_ptr(vlabuf, d, eps), 0, d_eps__sz);
2053 memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs + 16, 2372 /* Copy descriptors */
2054 d_raw_descs__sz); 2373 memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs,
2374 ffs->raw_descs_length);
2375
2055 memset(vla_ptr(vlabuf, d, inums), 0xff, d_inums__sz); 2376 memset(vla_ptr(vlabuf, d, inums), 0xff, d_inums__sz);
2056 for (ret = ffs->eps_count; ret; --ret) { 2377 for (ret = ffs->eps_count; ret; --ret) {
2057 struct ffs_ep *ptr; 2378 struct ffs_ep *ptr;
@@ -2073,22 +2394,38 @@ static int _ffs_func_bind(struct usb_configuration *c,
2073 */ 2394 */
2074 if (likely(full)) { 2395 if (likely(full)) {
2075 func->function.fs_descriptors = vla_ptr(vlabuf, d, fs_descs); 2396 func->function.fs_descriptors = vla_ptr(vlabuf, d, fs_descs);
2076 ret = ffs_do_descs(ffs->fs_descs_count, 2397 fs_len = ffs_do_descs(ffs->fs_descs_count,
2077 vla_ptr(vlabuf, d, raw_descs), 2398 vla_ptr(vlabuf, d, raw_descs),
2078 d_raw_descs__sz, 2399 d_raw_descs__sz,
2079 __ffs_func_bind_do_descs, func); 2400 __ffs_func_bind_do_descs, func);
2080 if (unlikely(ret < 0)) 2401 if (unlikely(fs_len < 0)) {
2402 ret = fs_len;
2081 goto error; 2403 goto error;
2404 }
2082 } else { 2405 } else {
2083 ret = 0; 2406 fs_len = 0;
2084 } 2407 }
2085 2408
2086 if (likely(high)) { 2409 if (likely(high)) {
2087 func->function.hs_descriptors = vla_ptr(vlabuf, d, hs_descs); 2410 func->function.hs_descriptors = vla_ptr(vlabuf, d, hs_descs);
2088 ret = ffs_do_descs(ffs->hs_descs_count, 2411 hs_len = ffs_do_descs(ffs->hs_descs_count,
2089 vla_ptr(vlabuf, d, raw_descs) + ret, 2412 vla_ptr(vlabuf, d, raw_descs) + fs_len,
2090 d_raw_descs__sz - ret, 2413 d_raw_descs__sz - fs_len,
2091 __ffs_func_bind_do_descs, func); 2414 __ffs_func_bind_do_descs, func);
2415 if (unlikely(hs_len < 0)) {
2416 ret = hs_len;
2417 goto error;
2418 }
2419 } else {
2420 hs_len = 0;
2421 }
2422
2423 if (likely(super)) {
2424 func->function.ss_descriptors = vla_ptr(vlabuf, d, ss_descs);
2425 ret = ffs_do_descs(ffs->ss_descs_count,
2426 vla_ptr(vlabuf, d, raw_descs) + fs_len + hs_len,
2427 d_raw_descs__sz - fs_len - hs_len,
2428 __ffs_func_bind_do_descs, func);
2092 if (unlikely(ret < 0)) 2429 if (unlikely(ret < 0))
2093 goto error; 2430 goto error;
2094 } 2431 }
@@ -2099,7 +2436,8 @@ static int _ffs_func_bind(struct usb_configuration *c,
2099 * now. 2436 * now.
2100 */ 2437 */
2101 ret = ffs_do_descs(ffs->fs_descs_count + 2438 ret = ffs_do_descs(ffs->fs_descs_count +
2102 (high ? ffs->hs_descs_count : 0), 2439 (high ? ffs->hs_descs_count : 0) +
2440 (super ? ffs->ss_descs_count : 0),
2103 vla_ptr(vlabuf, d, raw_descs), d_raw_descs__sz, 2441 vla_ptr(vlabuf, d, raw_descs), d_raw_descs__sz,
2104 __ffs_func_bind_do_nums, func); 2442 __ffs_func_bind_do_nums, func);
2105 if (unlikely(ret < 0)) 2443 if (unlikely(ret < 0))
@@ -2258,7 +2596,7 @@ static int ffs_func_revmap_intf(struct ffs_function *func, u8 intf)
2258 2596
2259static LIST_HEAD(ffs_devices); 2597static LIST_HEAD(ffs_devices);
2260 2598
2261static struct ffs_dev *_ffs_find_dev(const char *name) 2599static struct ffs_dev *_ffs_do_find_dev(const char *name)
2262{ 2600{
2263 struct ffs_dev *dev; 2601 struct ffs_dev *dev;
2264 2602
@@ -2275,7 +2613,7 @@ static struct ffs_dev *_ffs_find_dev(const char *name)
2275/* 2613/*
2276 * ffs_lock must be taken by the caller of this function 2614 * ffs_lock must be taken by the caller of this function
2277 */ 2615 */
2278static struct ffs_dev *ffs_get_single_dev(void) 2616static struct ffs_dev *_ffs_get_single_dev(void)
2279{ 2617{
2280 struct ffs_dev *dev; 2618 struct ffs_dev *dev;
2281 2619
@@ -2291,15 +2629,15 @@ static struct ffs_dev *ffs_get_single_dev(void)
2291/* 2629/*
2292 * ffs_lock must be taken by the caller of this function 2630 * ffs_lock must be taken by the caller of this function
2293 */ 2631 */
2294static struct ffs_dev *ffs_find_dev(const char *name) 2632static struct ffs_dev *_ffs_find_dev(const char *name)
2295{ 2633{
2296 struct ffs_dev *dev; 2634 struct ffs_dev *dev;
2297 2635
2298 dev = ffs_get_single_dev(); 2636 dev = _ffs_get_single_dev();
2299 if (dev) 2637 if (dev)
2300 return dev; 2638 return dev;
2301 2639
2302 return _ffs_find_dev(name); 2640 return _ffs_do_find_dev(name);
2303} 2641}
2304 2642
2305/* Configfs support *********************************************************/ 2643/* Configfs support *********************************************************/
@@ -2335,7 +2673,7 @@ static void ffs_free_inst(struct usb_function_instance *f)
2335 2673
2336 opts = to_f_fs_opts(f); 2674 opts = to_f_fs_opts(f);
2337 ffs_dev_lock(); 2675 ffs_dev_lock();
2338 ffs_free_dev(opts->dev); 2676 _ffs_free_dev(opts->dev);
2339 ffs_dev_unlock(); 2677 ffs_dev_unlock();
2340 kfree(opts); 2678 kfree(opts);
2341} 2679}
@@ -2390,7 +2728,7 @@ static struct usb_function_instance *ffs_alloc_inst(void)
2390 opts->func_inst.set_inst_name = ffs_set_inst_name; 2728 opts->func_inst.set_inst_name = ffs_set_inst_name;
2391 opts->func_inst.free_func_inst = ffs_free_inst; 2729 opts->func_inst.free_func_inst = ffs_free_inst;
2392 ffs_dev_lock(); 2730 ffs_dev_lock();
2393 dev = ffs_alloc_dev(); 2731 dev = _ffs_alloc_dev();
2394 ffs_dev_unlock(); 2732 ffs_dev_unlock();
2395 if (IS_ERR(dev)) { 2733 if (IS_ERR(dev)) {
2396 kfree(opts); 2734 kfree(opts);
@@ -2446,6 +2784,7 @@ static void ffs_func_unbind(struct usb_configuration *c,
2446 */ 2784 */
2447 func->function.fs_descriptors = NULL; 2785 func->function.fs_descriptors = NULL;
2448 func->function.hs_descriptors = NULL; 2786 func->function.hs_descriptors = NULL;
2787 func->function.ss_descriptors = NULL;
2449 func->interfaces_nums = NULL; 2788 func->interfaces_nums = NULL;
2450 2789
2451 ffs_event_add(ffs, FUNCTIONFS_UNBIND); 2790 ffs_event_add(ffs, FUNCTIONFS_UNBIND);
@@ -2478,12 +2817,12 @@ static struct usb_function *ffs_alloc(struct usb_function_instance *fi)
2478/* 2817/*
2479 * ffs_lock must be taken by the caller of this function 2818 * ffs_lock must be taken by the caller of this function
2480 */ 2819 */
2481struct ffs_dev *ffs_alloc_dev(void) 2820static struct ffs_dev *_ffs_alloc_dev(void)
2482{ 2821{
2483 struct ffs_dev *dev; 2822 struct ffs_dev *dev;
2484 int ret; 2823 int ret;
2485 2824
2486 if (ffs_get_single_dev()) 2825 if (_ffs_get_single_dev())
2487 return ERR_PTR(-EBUSY); 2826 return ERR_PTR(-EBUSY);
2488 2827
2489 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 2828 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
@@ -2511,10 +2850,10 @@ static int _ffs_name_dev(struct ffs_dev *dev, const char *name)
2511{ 2850{
2512 struct ffs_dev *existing; 2851 struct ffs_dev *existing;
2513 2852
2514 existing = _ffs_find_dev(name); 2853 existing = _ffs_do_find_dev(name);
2515 if (existing) 2854 if (existing)
2516 return -EBUSY; 2855 return -EBUSY;
2517 2856
2518 dev->name = name; 2857 dev->name = name;
2519 2858
2520 return 0; 2859 return 0;
@@ -2555,7 +2894,7 @@ EXPORT_SYMBOL(ffs_single_dev);
2555/* 2894/*
2556 * ffs_lock must be taken by the caller of this function 2895 * ffs_lock must be taken by the caller of this function
2557 */ 2896 */
2558void ffs_free_dev(struct ffs_dev *dev) 2897static void _ffs_free_dev(struct ffs_dev *dev)
2559{ 2898{
2560 list_del(&dev->entry); 2899 list_del(&dev->entry);
2561 if (dev->name_allocated) 2900 if (dev->name_allocated)
@@ -2572,7 +2911,7 @@ static void *ffs_acquire_dev(const char *dev_name)
2572 ENTER(); 2911 ENTER();
2573 ffs_dev_lock(); 2912 ffs_dev_lock();
2574 2913
2575 ffs_dev = ffs_find_dev(dev_name); 2914 ffs_dev = _ffs_find_dev(dev_name);
2576 if (!ffs_dev) 2915 if (!ffs_dev)
2577 ffs_dev = ERR_PTR(-ENODEV); 2916 ffs_dev = ERR_PTR(-ENODEV);
2578 else if (ffs_dev->mounted) 2917 else if (ffs_dev->mounted)
@@ -2595,11 +2934,12 @@ static void ffs_release_dev(struct ffs_data *ffs_data)
2595 ffs_dev_lock(); 2934 ffs_dev_lock();
2596 2935
2597 ffs_dev = ffs_data->private_data; 2936 ffs_dev = ffs_data->private_data;
2598 if (ffs_dev) 2937 if (ffs_dev) {
2599 ffs_dev->mounted = false; 2938 ffs_dev->mounted = false;
2600 2939
2601 if (ffs_dev->ffs_release_dev_callback) 2940 if (ffs_dev->ffs_release_dev_callback)
2602 ffs_dev->ffs_release_dev_callback(ffs_dev); 2941 ffs_dev->ffs_release_dev_callback(ffs_dev);
2942 }
2603 2943
2604 ffs_dev_unlock(); 2944 ffs_dev_unlock();
2605} 2945}