aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorMichal Nazarewicz <mina86@mina86.com>2010-11-12 08:29:28 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2010-11-16 16:54:46 -0500
commit5ab54cf7acf418573c9204371cf1ab3497c451ee (patch)
tree0de5d62ef608409c4737db60dd1db5b4ce1347b1 /drivers/usb
parent7189ba939ea0e74f73d7b30573b849c732835fc5 (diff)
usb: gadget: FunctionFS: fix typos and coding style
This commit changes FunctionFS as to make it more compliant with coding style as well as fixes several typos. Signed-off-by: Michal Nazarewicz <mina86@mina86.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/gadget/f_fs.c325
-rw-r--r--drivers/usb/gadget/g_ffs.c39
2 files changed, 186 insertions, 178 deletions
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index 38bb20001d9e..474f2d9f3a0f 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * f_fs.c -- user mode filesystem api for usb composite funtcion controllers 2 * f_fs.c -- user mode file system API for USB composite function controllers
3 * 3 *
4 * Copyright (C) 2010 Samsung Electronics 4 * Copyright (C) 2010 Samsung Electronics
5 * Author: Michal Nazarewicz <m.nazarewicz@samsung.com> 5 * Author: Michal Nazarewicz <m.nazarewicz@samsung.com>
6 * 6 *
7 * Based on inode.c (GadgetFS): 7 * Based on inode.c (GadgetFS) which was:
8 * Copyright (C) 2003-2004 David Brownell 8 * Copyright (C) 2003-2004 David Brownell
9 * Copyright (C) 2003 Agilent Technologies 9 * Copyright (C) 2003 Agilent Technologies
10 * 10 *
@@ -39,7 +39,7 @@
39#define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */ 39#define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */
40 40
41 41
42/* Debuging *****************************************************************/ 42/* Debugging ****************************************************************/
43 43
44#define ffs_printk(level, fmt, args...) printk(level "f_fs: " fmt "\n", ## args) 44#define ffs_printk(level, fmt, args...) printk(level "f_fs: " fmt "\n", ## args)
45 45
@@ -71,30 +71,39 @@
71/* The data structure and setup file ****************************************/ 71/* The data structure and setup file ****************************************/
72 72
73enum ffs_state { 73enum ffs_state {
74 /* Waiting for descriptors and strings. */ 74 /*
75 /* In this state no open(2), read(2) or write(2) on epfiles 75 * Waiting for descriptors and strings.
76 *
77 * In this state no open(2), read(2) or write(2) on epfiles
76 * may succeed (which should not be the problem as there 78 * may succeed (which should not be the problem as there
77 * should be no such files opened in the firts place). */ 79 * should be no such files opened in the first place).
80 */
78 FFS_READ_DESCRIPTORS, 81 FFS_READ_DESCRIPTORS,
79 FFS_READ_STRINGS, 82 FFS_READ_STRINGS,
80 83
81 /* We've got descriptors and strings. We are or have called 84 /*
85 * We've got descriptors and strings. We are or have called
82 * functionfs_ready_callback(). functionfs_bind() may have 86 * functionfs_ready_callback(). functionfs_bind() may have
83 * been called but we don't know. */ 87 * been called but we don't know.
84 /* This is the only state in which operations on epfiles may 88 *
85 * succeed. */ 89 * This is the only state in which operations on epfiles may
90 * succeed.
91 */
86 FFS_ACTIVE, 92 FFS_ACTIVE,
87 93
88 /* All endpoints have been closed. This state is also set if 94 /*
95 * All endpoints have been closed. This state is also set if
89 * we encounter an unrecoverable error. The only 96 * we encounter an unrecoverable error. The only
90 * unrecoverable error is situation when after reading strings 97 * unrecoverable error is situation when after reading strings
91 * from user space we fail to initialise EP files or 98 * from user space we fail to initialise epfiles or
92 * functionfs_ready_callback() returns with error (<0). */ 99 * functionfs_ready_callback() returns with error (<0).
93 /* In this state no open(2), read(2) or write(2) (both on ep0 100 *
101 * In this state no open(2), read(2) or write(2) (both on ep0
94 * as well as epfile) may succeed (at this point epfiles are 102 * as well as epfile) may succeed (at this point epfiles are
95 * unlinked and all closed so this is not a problem; ep0 is 103 * unlinked and all closed so this is not a problem; ep0 is
96 * also closed but ep0 file exists and so open(2) on ep0 must 104 * also closed but ep0 file exists and so open(2) on ep0 must
97 * fail). */ 105 * fail).
106 */
98 FFS_CLOSING 107 FFS_CLOSING
99}; 108};
100 109
@@ -102,14 +111,18 @@ enum ffs_state {
102enum ffs_setup_state { 111enum ffs_setup_state {
103 /* There is no setup request pending. */ 112 /* There is no setup request pending. */
104 FFS_NO_SETUP, 113 FFS_NO_SETUP,
105 /* User has read events and there was a setup request event 114 /*
115 * User has read events and there was a setup request event
106 * there. The next read/write on ep0 will handle the 116 * there. The next read/write on ep0 will handle the
107 * request. */ 117 * request.
118 */
108 FFS_SETUP_PENDING, 119 FFS_SETUP_PENDING,
109 /* There was event pending but before user space handled it 120 /*
121 * There was event pending but before user space handled it
110 * some other event was introduced which canceled existing 122 * some other event was introduced which canceled existing
111 * setup. If this state is set read/write on ep0 return 123 * setup. If this state is set read/write on ep0 return
112 * -EIDRM. This state is only set when adding event. */ 124 * -EIDRM. This state is only set when adding event.
125 */
113 FFS_SETUP_CANCELED 126 FFS_SETUP_CANCELED
114}; 127};
115 128
@@ -121,23 +134,29 @@ struct ffs_function;
121struct ffs_data { 134struct ffs_data {
122 struct usb_gadget *gadget; 135 struct usb_gadget *gadget;
123 136
124 /* Protect access read/write operations, only one read/write 137 /*
138 * Protect access read/write operations, only one read/write
125 * at a time. As a consequence protects ep0req and company. 139 * at a time. As a consequence protects ep0req and company.
126 * While setup request is being processed (queued) this is 140 * While setup request is being processed (queued) this is
127 * held. */ 141 * held.
142 */
128 struct mutex mutex; 143 struct mutex mutex;
129 144
130 /* Protect access to enpoint related structures (basically 145 /*
146 * Protect access to endpoint related structures (basically
131 * usb_ep_queue(), usb_ep_dequeue(), etc. calls) except for 147 * usb_ep_queue(), usb_ep_dequeue(), etc. calls) except for
132 * endpint zero. */ 148 * endpoint zero.
149 */
133 spinlock_t eps_lock; 150 spinlock_t eps_lock;
134 151
135 /* XXX REVISIT do we need our own request? Since we are not 152 /*
136 * handling setup requests immidiatelly user space may be so 153 * XXX REVISIT do we need our own request? Since we are not
154 * handling setup requests immediately user space may be so
137 * slow that another setup will be sent to the gadget but this 155 * slow that another setup will be sent to the gadget but this
138 * time not to us but another function and then there could be 156 * time not to us but another function and then there could be
139 * a race. Is that the case? Or maybe we can use cdev->req 157 * a race. Is that the case? Or maybe we can use cdev->req
140 * after all, maybe we just need some spinlock for that? */ 158 * after all, maybe we just need some spinlock for that?
159 */
141 struct usb_request *ep0req; /* P: mutex */ 160 struct usb_request *ep0req; /* P: mutex */
142 struct completion ep0req_completion; /* P: mutex */ 161 struct completion ep0req_completion; /* P: mutex */
143 int ep0req_status; /* P: mutex */ 162 int ep0req_status; /* P: mutex */
@@ -151,7 +170,7 @@ struct ffs_data {
151 enum ffs_state state; 170 enum ffs_state state;
152 171
153 /* 172 /*
154 * Possible transations: 173 * Possible transitions:
155 * + FFS_NO_SETUP -> FFS_SETUP_PENDING -- P: ev.waitq.lock 174 * + FFS_NO_SETUP -> FFS_SETUP_PENDING -- P: ev.waitq.lock
156 * happens only in ep0 read which is P: mutex 175 * happens only in ep0 read which is P: mutex
157 * + FFS_SETUP_PENDING -> FFS_NO_SETUP -- P: ev.waitq.lock 176 * + FFS_SETUP_PENDING -> FFS_NO_SETUP -- P: ev.waitq.lock
@@ -184,18 +203,21 @@ struct ffs_data {
184 /* Active function */ 203 /* Active function */
185 struct ffs_function *func; 204 struct ffs_function *func;
186 205
187 /* Device name, write once when file system is mounted. 206 /*
188 * Intendet for user to read if she wants. */ 207 * Device name, write once when file system is mounted.
208 * Intended for user to read if she wants.
209 */
189 const char *dev_name; 210 const char *dev_name;
190 /* Private data for our user (ie. gadget). Managed by 211 /* Private data for our user (ie. gadget). Managed by user. */
191 * user. */
192 void *private_data; 212 void *private_data;
193 213
194 /* filled by __ffs_data_got_descs() */ 214 /* filled by __ffs_data_got_descs() */
195 /* real descriptors are 16 bytes after raw_descs (so you need 215 /*
216 * Real descriptors are 16 bytes after raw_descs (so you need
196 * to skip 16 bytes (ie. ffs->raw_descs + 16) to get to the 217 * to skip 16 bytes (ie. ffs->raw_descs + 16) to get to the
197 * first full speed descriptor). raw_descs_length and 218 * first full speed descriptor). raw_descs_length and
198 * raw_fs_descs_length do not have those 16 bytes added. */ 219 * raw_fs_descs_length do not have those 16 bytes added.
220 */
199 const void *raw_descs; 221 const void *raw_descs;
200 unsigned raw_descs_length; 222 unsigned raw_descs_length;
201 unsigned raw_fs_descs_length; 223 unsigned raw_fs_descs_length;
@@ -212,18 +234,23 @@ struct ffs_data {
212 const void *raw_strings; 234 const void *raw_strings;
213 struct usb_gadget_strings **stringtabs; 235 struct usb_gadget_strings **stringtabs;
214 236
215 /* File system's super block, write once when file system is mounted. */ 237 /*
238 * File system's super block, write once when file system is
239 * mounted.
240 */
216 struct super_block *sb; 241 struct super_block *sb;
217 242
218 /* File permissions, written once when fs is mounted*/ 243 /* File permissions, written once when fs is mounted */
219 struct ffs_file_perms { 244 struct ffs_file_perms {
220 umode_t mode; 245 umode_t mode;
221 uid_t uid; 246 uid_t uid;
222 gid_t gid; 247 gid_t gid;
223 } file_perms; 248 } file_perms;
224 249
225 /* The endpoint files, filled by ffs_epfiles_create(), 250 /*
226 * destroyed by ffs_epfiles_destroy(). */ 251 * The endpoint files, filled by ffs_epfiles_create(),
252 * destroyed by ffs_epfiles_destroy().
253 */
227 struct ffs_epfile *epfiles; 254 struct ffs_epfile *epfiles;
228}; 255};
229 256
@@ -237,7 +264,7 @@ static struct ffs_data *__must_check ffs_data_new(void) __attribute__((malloc));
237static void ffs_data_opened(struct ffs_data *ffs); 264static void ffs_data_opened(struct ffs_data *ffs);
238static void ffs_data_closed(struct ffs_data *ffs); 265static void ffs_data_closed(struct ffs_data *ffs);
239 266
240/* Called with ffs->mutex held; take over ownerrship of data. */ 267/* Called with ffs->mutex held; take over ownership of data. */
241static int __must_check 268static int __must_check
242__ffs_data_got_descs(struct ffs_data *ffs, char *data, size_t len); 269__ffs_data_got_descs(struct ffs_data *ffs, char *data, size_t len);
243static int __must_check 270static int __must_check
@@ -268,11 +295,9 @@ static struct ffs_function *ffs_func_from_usb(struct usb_function *f)
268 295
269static void ffs_func_free(struct ffs_function *func); 296static void ffs_func_free(struct ffs_function *func);
270 297
271
272static void ffs_func_eps_disable(struct ffs_function *func); 298static void ffs_func_eps_disable(struct ffs_function *func);
273static int __must_check ffs_func_eps_enable(struct ffs_function *func); 299static int __must_check ffs_func_eps_enable(struct ffs_function *func);
274 300
275
276static int ffs_func_bind(struct usb_configuration *, 301static int ffs_func_bind(struct usb_configuration *,
277 struct usb_function *); 302 struct usb_function *);
278static void ffs_func_unbind(struct usb_configuration *, 303static void ffs_func_unbind(struct usb_configuration *,
@@ -289,7 +314,6 @@ static int ffs_func_revmap_ep(struct ffs_function *func, u8 num);
289static int ffs_func_revmap_intf(struct ffs_function *func, u8 intf); 314static int ffs_func_revmap_intf(struct ffs_function *func, u8 intf);
290 315
291 316
292
293/* The endpoints structures *************************************************/ 317/* The endpoints structures *************************************************/
294 318
295struct ffs_ep { 319struct ffs_ep {
@@ -322,7 +346,6 @@ struct ffs_epfile {
322 unsigned char _pad; 346 unsigned char _pad;
323}; 347};
324 348
325
326static int __must_check ffs_epfiles_create(struct ffs_data *ffs); 349static int __must_check ffs_epfiles_create(struct ffs_data *ffs);
327static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count); 350static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count);
328 351
@@ -349,7 +372,6 @@ static void ffs_ep0_complete(struct usb_ep *ep, struct usb_request *req)
349 complete_all(&ffs->ep0req_completion); 372 complete_all(&ffs->ep0req_completion);
350} 373}
351 374
352
353static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len) 375static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len)
354{ 376{
355 struct usb_request *req = ffs->ep0req; 377 struct usb_request *req = ffs->ep0req;
@@ -391,7 +413,6 @@ static int __ffs_ep0_stall(struct ffs_data *ffs)
391 } 413 }
392} 414}
393 415
394
395static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, 416static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
396 size_t len, loff_t *ptr) 417 size_t len, loff_t *ptr)
397{ 418{
@@ -410,7 +431,6 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
410 if (unlikely(ret < 0)) 431 if (unlikely(ret < 0))
411 return ret; 432 return ret;
412 433
413
414 /* Check state */ 434 /* Check state */
415 switch (ffs->state) { 435 switch (ffs->state) {
416 case FFS_READ_DESCRIPTORS: 436 case FFS_READ_DESCRIPTORS:
@@ -462,11 +482,12 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
462 } 482 }
463 break; 483 break;
464 484
465
466 case FFS_ACTIVE: 485 case FFS_ACTIVE:
467 data = NULL; 486 data = NULL;
468 /* We're called from user space, we can use _irq 487 /*
469 * rather then _irqsave */ 488 * We're called from user space, we can use _irq
489 * rather then _irqsave
490 */
470 spin_lock_irq(&ffs->ev.waitq.lock); 491 spin_lock_irq(&ffs->ev.waitq.lock);
471 switch (FFS_SETUP_STATE(ffs)) { 492 switch (FFS_SETUP_STATE(ffs)) {
472 case FFS_SETUP_CANCELED: 493 case FFS_SETUP_CANCELED:
@@ -501,16 +522,18 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
501 522
502 spin_lock_irq(&ffs->ev.waitq.lock); 523 spin_lock_irq(&ffs->ev.waitq.lock);
503 524
504 /* We are guaranteed to be still in FFS_ACTIVE state 525 /*
526 * We are guaranteed to be still in FFS_ACTIVE state
505 * but the state of setup could have changed from 527 * but the state of setup could have changed from
506 * FFS_SETUP_PENDING to FFS_SETUP_CANCELED so we need 528 * FFS_SETUP_PENDING to FFS_SETUP_CANCELED so we need
507 * to check for that. If that happened we copied data 529 * to check for that. If that happened we copied data
508 * from user space in vain but it's unlikely. */ 530 * from user space in vain but it's unlikely.
509 /* For sure we are not in FFS_NO_SETUP since this is 531 *
532 * For sure we are not in FFS_NO_SETUP since this is
510 * the only place FFS_SETUP_PENDING -> FFS_NO_SETUP 533 * the only place FFS_SETUP_PENDING -> FFS_NO_SETUP
511 * transition can be performed and it's protected by 534 * transition can be performed and it's protected by
512 * mutex. */ 535 * mutex.
513 536 */
514 if (FFS_SETUP_STATE(ffs) == FFS_SETUP_CANCELED) { 537 if (FFS_SETUP_STATE(ffs) == FFS_SETUP_CANCELED) {
515 ret = -EIDRM; 538 ret = -EIDRM;
516done_spin: 539done_spin:
@@ -522,25 +545,22 @@ done_spin:
522 kfree(data); 545 kfree(data);
523 break; 546 break;
524 547
525
526 default: 548 default:
527 ret = -EBADFD; 549 ret = -EBADFD;
528 break; 550 break;
529 } 551 }
530 552
531
532 mutex_unlock(&ffs->mutex); 553 mutex_unlock(&ffs->mutex);
533 return ret; 554 return ret;
534} 555}
535 556
536
537
538static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf, 557static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf,
539 size_t n) 558 size_t n)
540{ 559{
541 /* We are holding ffs->ev.waitq.lock and ffs->mutex and we need 560 /*
542 * to release them. */ 561 * We are holding ffs->ev.waitq.lock and ffs->mutex and we need
543 562 * to release them.
563 */
544 struct usb_functionfs_event events[n]; 564 struct usb_functionfs_event events[n];
545 unsigned i = 0; 565 unsigned i = 0;
546 566
@@ -569,7 +589,6 @@ static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf,
569 ? -EFAULT : sizeof events; 589 ? -EFAULT : sizeof events;
570} 590}
571 591
572
573static ssize_t ffs_ep0_read(struct file *file, char __user *buf, 592static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
574 size_t len, loff_t *ptr) 593 size_t len, loff_t *ptr)
575{ 594{
@@ -589,16 +608,16 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
589 if (unlikely(ret < 0)) 608 if (unlikely(ret < 0))
590 return ret; 609 return ret;
591 610
592
593 /* Check state */ 611 /* Check state */
594 if (ffs->state != FFS_ACTIVE) { 612 if (ffs->state != FFS_ACTIVE) {
595 ret = -EBADFD; 613 ret = -EBADFD;
596 goto done_mutex; 614 goto done_mutex;
597 } 615 }
598 616
599 617 /*
600 /* We're called from user space, we can use _irq rather then 618 * We're called from user space, we can use _irq rather then
601 * _irqsave */ 619 * _irqsave
620 */
602 spin_lock_irq(&ffs->ev.waitq.lock); 621 spin_lock_irq(&ffs->ev.waitq.lock);
603 622
604 switch (FFS_SETUP_STATE(ffs)) { 623 switch (FFS_SETUP_STATE(ffs)) {
@@ -618,7 +637,8 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
618 break; 637 break;
619 } 638 }
620 639
621 if (unlikely(wait_event_interruptible_exclusive_locked_irq(ffs->ev.waitq, ffs->ev.count))) { 640 if (wait_event_interruptible_exclusive_locked_irq(ffs->ev.waitq,
641 ffs->ev.count)) {
622 ret = -EINTR; 642 ret = -EINTR;
623 break; 643 break;
624 } 644 }
@@ -626,7 +646,6 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
626 return __ffs_ep0_read_events(ffs, buf, 646 return __ffs_ep0_read_events(ffs, buf,
627 min(n, (size_t)ffs->ev.count)); 647 min(n, (size_t)ffs->ev.count));
628 648
629
630 case FFS_SETUP_PENDING: 649 case FFS_SETUP_PENDING:
631 if (ffs->ev.setup.bRequestType & USB_DIR_IN) { 650 if (ffs->ev.setup.bRequestType & USB_DIR_IN) {
632 spin_unlock_irq(&ffs->ev.waitq.lock); 651 spin_unlock_irq(&ffs->ev.waitq.lock);
@@ -672,8 +691,6 @@ done_mutex:
672 return ret; 691 return ret;
673} 692}
674 693
675
676
677static int ffs_ep0_open(struct inode *inode, struct file *file) 694static int ffs_ep0_open(struct inode *inode, struct file *file)
678{ 695{
679 struct ffs_data *ffs = inode->i_private; 696 struct ffs_data *ffs = inode->i_private;
@@ -689,7 +706,6 @@ static int ffs_ep0_open(struct inode *inode, struct file *file)
689 return 0; 706 return 0;
690} 707}
691 708
692
693static int ffs_ep0_release(struct inode *inode, struct file *file) 709static int ffs_ep0_release(struct inode *inode, struct file *file)
694{ 710{
695 struct ffs_data *ffs = file->private_data; 711 struct ffs_data *ffs = file->private_data;
@@ -701,7 +717,6 @@ static int ffs_ep0_release(struct inode *inode, struct file *file)
701 return 0; 717 return 0;
702} 718}
703 719
704
705static long ffs_ep0_ioctl(struct file *file, unsigned code, unsigned long value) 720static long ffs_ep0_ioctl(struct file *file, unsigned code, unsigned long value)
706{ 721{
707 struct ffs_data *ffs = file->private_data; 722 struct ffs_data *ffs = file->private_data;
@@ -722,7 +737,6 @@ static long ffs_ep0_ioctl(struct file *file, unsigned code, unsigned long value)
722 return ret; 737 return ret;
723} 738}
724 739
725
726static const struct file_operations ffs_ep0_operations = { 740static const struct file_operations ffs_ep0_operations = {
727 .owner = THIS_MODULE, 741 .owner = THIS_MODULE,
728 .llseek = no_llseek, 742 .llseek = no_llseek,
@@ -737,7 +751,6 @@ static const struct file_operations ffs_ep0_operations = {
737 751
738/* "Normal" endpoints operations ********************************************/ 752/* "Normal" endpoints operations ********************************************/
739 753
740
741static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req) 754static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req)
742{ 755{
743 ENTER(); 756 ENTER();
@@ -748,7 +761,6 @@ static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req)
748 } 761 }
749} 762}
750 763
751
752static ssize_t ffs_epfile_io(struct file *file, 764static ssize_t ffs_epfile_io(struct file *file,
753 char __user *buf, size_t len, int read) 765 char __user *buf, size_t len, int read)
754{ 766{
@@ -778,8 +790,8 @@ first_try:
778 goto error; 790 goto error;
779 } 791 }
780 792
781 if (unlikely(wait_event_interruptible 793 if (wait_event_interruptible(epfile->wait,
782 (epfile->wait, (ep = epfile->ep)))) { 794 (ep = epfile->ep))) {
783 ret = -EINTR; 795 ret = -EINTR;
784 goto error; 796 goto error;
785 } 797 }
@@ -811,12 +823,16 @@ first_try:
811 if (unlikely(ret)) 823 if (unlikely(ret))
812 goto error; 824 goto error;
813 825
814 /* We're called from user space, we can use _irq rather then 826 /*
815 * _irqsave */ 827 * We're called from user space, we can use _irq rather then
828 * _irqsave
829 */
816 spin_lock_irq(&epfile->ffs->eps_lock); 830 spin_lock_irq(&epfile->ffs->eps_lock);
817 831
818 /* While we were acquiring mutex endpoint got disabled 832 /*
819 * or changed? */ 833 * While we were acquiring mutex endpoint got disabled
834 * or changed?
835 */
820 } while (unlikely(epfile->ep != ep)); 836 } while (unlikely(epfile->ep != ep));
821 837
822 /* Halt */ 838 /* Halt */
@@ -858,7 +874,6 @@ error:
858 return ret; 874 return ret;
859} 875}
860 876
861
862static ssize_t 877static ssize_t
863ffs_epfile_write(struct file *file, const char __user *buf, size_t len, 878ffs_epfile_write(struct file *file, const char __user *buf, size_t len,
864 loff_t *ptr) 879 loff_t *ptr)
@@ -904,7 +919,6 @@ ffs_epfile_release(struct inode *inode, struct file *file)
904 return 0; 919 return 0;
905} 920}
906 921
907
908static long ffs_epfile_ioctl(struct file *file, unsigned code, 922static long ffs_epfile_ioctl(struct file *file, unsigned code,
909 unsigned long value) 923 unsigned long value)
910{ 924{
@@ -943,7 +957,6 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code,
943 return ret; 957 return ret;
944} 958}
945 959
946
947static const struct file_operations ffs_epfile_operations = { 960static const struct file_operations ffs_epfile_operations = {
948 .owner = THIS_MODULE, 961 .owner = THIS_MODULE,
949 .llseek = no_llseek, 962 .llseek = no_llseek,
@@ -956,15 +969,13 @@ static const struct file_operations ffs_epfile_operations = {
956}; 969};
957 970
958 971
959
960/* File system and super block operations ***********************************/ 972/* File system and super block operations ***********************************/
961 973
962/* 974/*
963 * Mounting the filesystem creates a controller file, used first for 975 * Mounting the file system creates a controller file, used first for
964 * function configuration then later for event monitoring. 976 * function configuration then later for event monitoring.
965 */ 977 */
966 978
967
968static struct inode *__must_check 979static struct inode *__must_check
969ffs_sb_make_inode(struct super_block *sb, void *data, 980ffs_sb_make_inode(struct super_block *sb, void *data,
970 const struct file_operations *fops, 981 const struct file_operations *fops,
@@ -997,9 +1008,7 @@ ffs_sb_make_inode(struct super_block *sb, void *data,
997 return inode; 1008 return inode;
998} 1009}
999 1010
1000
1001/* Create "regular" file */ 1011/* Create "regular" file */
1002
1003static struct inode *ffs_sb_create_file(struct super_block *sb, 1012static struct inode *ffs_sb_create_file(struct super_block *sb,
1004 const char *name, void *data, 1013 const char *name, void *data,
1005 const struct file_operations *fops, 1014 const struct file_operations *fops,
@@ -1028,9 +1037,7 @@ static struct inode *ffs_sb_create_file(struct super_block *sb,
1028 return inode; 1037 return inode;
1029} 1038}
1030 1039
1031
1032/* Super block */ 1040/* Super block */
1033
1034static const struct super_operations ffs_sb_operations = { 1041static const struct super_operations ffs_sb_operations = {
1035 .statfs = simple_statfs, 1042 .statfs = simple_statfs,
1036 .drop_inode = generic_delete_inode, 1043 .drop_inode = generic_delete_inode,
@@ -1051,7 +1058,7 @@ static int ffs_sb_fill(struct super_block *sb, void *_data, int silent)
1051 1058
1052 ENTER(); 1059 ENTER();
1053 1060
1054 /* Initialize data */ 1061 /* Initialise data */
1055 ffs = ffs_data_new(); 1062 ffs = ffs_data_new();
1056 if (unlikely(!ffs)) 1063 if (unlikely(!ffs))
1057 goto enomem0; 1064 goto enomem0;
@@ -1097,7 +1104,6 @@ enomem0:
1097 return -ENOMEM; 1104 return -ENOMEM;
1098} 1105}
1099 1106
1100
1101static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts) 1107static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts)
1102{ 1108{
1103 ENTER(); 1109 ENTER();
@@ -1173,7 +1179,6 @@ invalid:
1173 return 0; 1179 return 0;
1174} 1180}
1175 1181
1176
1177/* "mount -t functionfs dev_name /dev/function" ends up here */ 1182/* "mount -t functionfs dev_name /dev/function" ends up here */
1178 1183
1179static struct dentry * 1184static struct dentry *
@@ -1225,10 +1230,8 @@ static struct file_system_type ffs_fs_type = {
1225}; 1230};
1226 1231
1227 1232
1228
1229/* Driver's main init/cleanup functions *************************************/ 1233/* Driver's main init/cleanup functions *************************************/
1230 1234
1231
1232static int functionfs_init(void) 1235static int functionfs_init(void)
1233{ 1236{
1234 int ret; 1237 int ret;
@@ -1253,13 +1256,11 @@ static void functionfs_cleanup(void)
1253} 1256}
1254 1257
1255 1258
1256
1257/* ffs_data and ffs_function construction and destruction code **************/ 1259/* ffs_data and ffs_function construction and destruction code **************/
1258 1260
1259static void ffs_data_clear(struct ffs_data *ffs); 1261static void ffs_data_clear(struct ffs_data *ffs);
1260static void ffs_data_reset(struct ffs_data *ffs); 1262static void ffs_data_reset(struct ffs_data *ffs);
1261 1263
1262
1263static void ffs_data_get(struct ffs_data *ffs) 1264static void ffs_data_get(struct ffs_data *ffs)
1264{ 1265{
1265 ENTER(); 1266 ENTER();
@@ -1290,8 +1291,6 @@ static void ffs_data_put(struct ffs_data *ffs)
1290 } 1291 }
1291} 1292}
1292 1293
1293
1294
1295static void ffs_data_closed(struct ffs_data *ffs) 1294static void ffs_data_closed(struct ffs_data *ffs)
1296{ 1295{
1297 ENTER(); 1296 ENTER();
@@ -1304,7 +1303,6 @@ static void ffs_data_closed(struct ffs_data *ffs)
1304 ffs_data_put(ffs); 1303 ffs_data_put(ffs);
1305} 1304}
1306 1305
1307
1308static struct ffs_data *ffs_data_new(void) 1306static struct ffs_data *ffs_data_new(void)
1309{ 1307{
1310 struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL); 1308 struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL);
@@ -1327,7 +1325,6 @@ static struct ffs_data *ffs_data_new(void)
1327 return ffs; 1325 return ffs;
1328} 1326}
1329 1327
1330
1331static void ffs_data_clear(struct ffs_data *ffs) 1328static void ffs_data_clear(struct ffs_data *ffs)
1332{ 1329{
1333 ENTER(); 1330 ENTER();
@@ -1345,7 +1342,6 @@ static void ffs_data_clear(struct ffs_data *ffs)
1345 kfree(ffs->stringtabs); 1342 kfree(ffs->stringtabs);
1346} 1343}
1347 1344
1348
1349static void ffs_data_reset(struct ffs_data *ffs) 1345static void ffs_data_reset(struct ffs_data *ffs)
1350{ 1346{
1351 ENTER(); 1347 ENTER();
@@ -1408,7 +1404,6 @@ static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev)
1408 return 0; 1404 return 0;
1409} 1405}
1410 1406
1411
1412static void functionfs_unbind(struct ffs_data *ffs) 1407static void functionfs_unbind(struct ffs_data *ffs)
1413{ 1408{
1414 ENTER(); 1409 ENTER();
@@ -1421,7 +1416,6 @@ static void functionfs_unbind(struct ffs_data *ffs)
1421 } 1416 }
1422} 1417}
1423 1418
1424
1425static int ffs_epfiles_create(struct ffs_data *ffs) 1419static int ffs_epfiles_create(struct ffs_data *ffs)
1426{ 1420{
1427 struct ffs_epfile *epfile, *epfiles; 1421 struct ffs_epfile *epfile, *epfiles;
@@ -1452,7 +1446,6 @@ static int ffs_epfiles_create(struct ffs_data *ffs)
1452 return 0; 1446 return 0;
1453} 1447}
1454 1448
1455
1456static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count) 1449static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count)
1457{ 1450{
1458 struct ffs_epfile *epfile = epfiles; 1451 struct ffs_epfile *epfile = epfiles;
@@ -1472,7 +1465,6 @@ static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count)
1472 kfree(epfiles); 1465 kfree(epfiles);
1473} 1466}
1474 1467
1475
1476static int functionfs_bind_config(struct usb_composite_dev *cdev, 1468static int functionfs_bind_config(struct usb_composite_dev *cdev,
1477 struct usb_configuration *c, 1469 struct usb_configuration *c,
1478 struct ffs_data *ffs) 1470 struct ffs_data *ffs)
@@ -1492,7 +1484,6 @@ static int functionfs_bind_config(struct usb_composite_dev *cdev,
1492 func->function.bind = ffs_func_bind; 1484 func->function.bind = ffs_func_bind;
1493 func->function.unbind = ffs_func_unbind; 1485 func->function.unbind = ffs_func_unbind;
1494 func->function.set_alt = ffs_func_set_alt; 1486 func->function.set_alt = ffs_func_set_alt;
1495 /*func->function.get_alt = ffs_func_get_alt;*/
1496 func->function.disable = ffs_func_disable; 1487 func->function.disable = ffs_func_disable;
1497 func->function.setup = ffs_func_setup; 1488 func->function.setup = ffs_func_setup;
1498 func->function.suspend = ffs_func_suspend; 1489 func->function.suspend = ffs_func_suspend;
@@ -1517,14 +1508,15 @@ static void ffs_func_free(struct ffs_function *func)
1517 ffs_data_put(func->ffs); 1508 ffs_data_put(func->ffs);
1518 1509
1519 kfree(func->eps); 1510 kfree(func->eps);
1520 /* eps and interfaces_nums are allocated in the same chunk so 1511 /*
1512 * eps and interfaces_nums are allocated in the same chunk so
1521 * only one free is required. Descriptors are also allocated 1513 * only one free is required. Descriptors are also allocated
1522 * in the same chunk. */ 1514 * in the same chunk.
1515 */
1523 1516
1524 kfree(func); 1517 kfree(func);
1525} 1518}
1526 1519
1527
1528static void ffs_func_eps_disable(struct ffs_function *func) 1520static void ffs_func_eps_disable(struct ffs_function *func)
1529{ 1521{
1530 struct ffs_ep *ep = func->eps; 1522 struct ffs_ep *ep = func->eps;
@@ -1582,11 +1574,12 @@ static int ffs_func_eps_enable(struct ffs_function *func)
1582 1574
1583/* Parsing and building descriptors and strings *****************************/ 1575/* Parsing and building descriptors and strings *****************************/
1584 1576
1585 1577/*
1586/* This validates if data pointed by data is a valid USB descriptor as 1578 * This validates if data pointed by data is a valid USB descriptor as
1587 * well as record how many interfaces, endpoints and strings are 1579 * well as record how many interfaces, endpoints and strings are
1588 * required by given configuration. Returns address afther the 1580 * required by given configuration. Returns address after the
1589 * descriptor or NULL if data is invalid. */ 1581 * descriptor or NULL if data is invalid.
1582 */
1590 1583
1591enum ffs_entity_type { 1584enum ffs_entity_type {
1592 FFS_DESCRIPTOR, FFS_INTERFACE, FFS_STRING, FFS_ENDPOINT 1585 FFS_DESCRIPTOR, FFS_INTERFACE, FFS_STRING, FFS_ENDPOINT
@@ -1643,7 +1636,8 @@ static int __must_check ffs_do_desc(char *data, unsigned len,
1643 case USB_DT_STRING: 1636 case USB_DT_STRING:
1644 case USB_DT_DEVICE_QUALIFIER: 1637 case USB_DT_DEVICE_QUALIFIER:
1645 /* function can't have any of those */ 1638 /* function can't have any of those */
1646 FVDBG("descriptor reserved for gadget: %d", _ds->bDescriptorType); 1639 FVDBG("descriptor reserved for gadget: %d",
1640 _ds->bDescriptorType);
1647 return -EINVAL; 1641 return -EINVAL;
1648 1642
1649 case USB_DT_INTERFACE: { 1643 case USB_DT_INTERFACE: {
@@ -1697,7 +1691,7 @@ static int __must_check ffs_do_desc(char *data, unsigned len,
1697 FVDBG("unknown descriptor: %d", _ds->bDescriptorType); 1691 FVDBG("unknown descriptor: %d", _ds->bDescriptorType);
1698 return -EINVAL; 1692 return -EINVAL;
1699 1693
1700 inv_length: 1694inv_length:
1701 FVDBG("invalid length: %d (descriptor %d)", 1695 FVDBG("invalid length: %d (descriptor %d)",
1702 _ds->bLength, _ds->bDescriptorType); 1696 _ds->bLength, _ds->bDescriptorType);
1703 return -EINVAL; 1697 return -EINVAL;
@@ -1712,7 +1706,6 @@ static int __must_check ffs_do_desc(char *data, unsigned len,
1712 return length; 1706 return length;
1713} 1707}
1714 1708
1715
1716static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len, 1709static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len,
1717 ffs_entity_callback entity, void *priv) 1710 ffs_entity_callback entity, void *priv)
1718{ 1711{
@@ -1727,7 +1720,7 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len,
1727 if (num == count) 1720 if (num == count)
1728 data = NULL; 1721 data = NULL;
1729 1722
1730 /* Record "descriptor" entitny */ 1723 /* Record "descriptor" entity */
1731 ret = entity(FFS_DESCRIPTOR, (u8 *)num, (void *)data, priv); 1724 ret = entity(FFS_DESCRIPTOR, (u8 *)num, (void *)data, priv);
1732 if (unlikely(ret < 0)) { 1725 if (unlikely(ret < 0)) {
1733 FDBG("entity DESCRIPTOR(%02lx); ret = %d", num, ret); 1726 FDBG("entity DESCRIPTOR(%02lx); ret = %d", num, ret);
@@ -1749,7 +1742,6 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len,
1749 } 1742 }
1750} 1743}
1751 1744
1752
1753static int __ffs_data_do_entity(enum ffs_entity_type type, 1745static int __ffs_data_do_entity(enum ffs_entity_type type,
1754 u8 *valuep, struct usb_descriptor_header *desc, 1746 u8 *valuep, struct usb_descriptor_header *desc,
1755 void *priv) 1747 void *priv)
@@ -1763,16 +1755,20 @@ static int __ffs_data_do_entity(enum ffs_entity_type type,
1763 break; 1755 break;
1764 1756
1765 case FFS_INTERFACE: 1757 case FFS_INTERFACE:
1766 /* Interfaces are indexed from zero so if we 1758 /*
1759 * Interfaces are indexed from zero so if we
1767 * encountered interface "n" then there are at least 1760 * encountered interface "n" then there are at least
1768 * "n+1" interfaces. */ 1761 * "n+1" interfaces.
1762 */
1769 if (*valuep >= ffs->interfaces_count) 1763 if (*valuep >= ffs->interfaces_count)
1770 ffs->interfaces_count = *valuep + 1; 1764 ffs->interfaces_count = *valuep + 1;
1771 break; 1765 break;
1772 1766
1773 case FFS_STRING: 1767 case FFS_STRING:
1774 /* Strings are indexed from 1 (0 is magic ;) reserved 1768 /*
1775 * for languages list or some such) */ 1769 * Strings are indexed from 1 (0 is magic ;) reserved
1770 * for languages list or some such)
1771 */
1776 if (*valuep > ffs->strings_count) 1772 if (*valuep > ffs->strings_count)
1777 ffs->strings_count = *valuep; 1773 ffs->strings_count = *valuep;
1778 break; 1774 break;
@@ -1787,7 +1783,6 @@ static int __ffs_data_do_entity(enum ffs_entity_type type,
1787 return 0; 1783 return 0;
1788} 1784}
1789 1785
1790
1791static int __ffs_data_got_descs(struct ffs_data *ffs, 1786static int __ffs_data_got_descs(struct ffs_data *ffs,
1792 char *const _data, size_t len) 1787 char *const _data, size_t len)
1793{ 1788{
@@ -1850,8 +1845,6 @@ error:
1850 return ret; 1845 return ret;
1851} 1846}
1852 1847
1853
1854
1855static int __ffs_data_got_strings(struct ffs_data *ffs, 1848static int __ffs_data_got_strings(struct ffs_data *ffs,
1856 char *const _data, size_t len) 1849 char *const _data, size_t len)
1857{ 1850{
@@ -1877,17 +1870,17 @@ static int __ffs_data_got_strings(struct ffs_data *ffs,
1877 if (unlikely(str_count < needed_count)) 1870 if (unlikely(str_count < needed_count))
1878 goto error; 1871 goto error;
1879 1872
1880 /* If we don't need any strings just return and free all 1873 /*
1881 * memory */ 1874 * If we don't need any strings just return and free all
1875 * memory.
1876 */
1882 if (!needed_count) { 1877 if (!needed_count) {
1883 kfree(_data); 1878 kfree(_data);
1884 return 0; 1879 return 0;
1885 } 1880 }
1886 1881
1887 /* Allocate */ 1882 /* Allocate everything in one chunk so there's less maintenance. */
1888 { 1883 {
1889 /* Allocate everything in one chunk so there's less
1890 * maintanance. */
1891 struct { 1884 struct {
1892 struct usb_gadget_strings *stringtabs[lang_count + 1]; 1885 struct usb_gadget_strings *stringtabs[lang_count + 1];
1893 struct usb_gadget_strings stringtab[lang_count]; 1886 struct usb_gadget_strings stringtab[lang_count];
@@ -1938,13 +1931,17 @@ static int __ffs_data_got_strings(struct ffs_data *ffs,
1938 if (unlikely(length == len)) 1931 if (unlikely(length == len))
1939 goto error_free; 1932 goto error_free;
1940 1933
1941 /* user may provide more strings then we need, 1934 /*
1942 * if that's the case we simply ingore the 1935 * User may provide more strings then we need,
1943 * rest */ 1936 * if that's the case we simply ignore the
1937 * rest
1938 */
1944 if (likely(needed)) { 1939 if (likely(needed)) {
1945 /* s->id will be set while adding 1940 /*
1941 * s->id will be set while adding
1946 * function to configuration so for 1942 * function to configuration so for
1947 * now just leave garbage here. */ 1943 * now just leave garbage here.
1944 */
1948 s->s = data; 1945 s->s = data;
1949 --needed; 1946 --needed;
1950 ++s; 1947 ++s;
@@ -1978,8 +1975,6 @@ error:
1978} 1975}
1979 1976
1980 1977
1981
1982
1983/* Events handling and management *******************************************/ 1978/* Events handling and management *******************************************/
1984 1979
1985static void __ffs_event_add(struct ffs_data *ffs, 1980static void __ffs_event_add(struct ffs_data *ffs,
@@ -1988,29 +1983,32 @@ static void __ffs_event_add(struct ffs_data *ffs,
1988 enum usb_functionfs_event_type rem_type1, rem_type2 = type; 1983 enum usb_functionfs_event_type rem_type1, rem_type2 = type;
1989 int neg = 0; 1984 int neg = 0;
1990 1985
1991 /* Abort any unhandled setup */ 1986 /*
1992 /* We do not need to worry about some cmpxchg() changing value 1987 * Abort any unhandled setup
1988 *
1989 * We do not need to worry about some cmpxchg() changing value
1993 * of ffs->setup_state without holding the lock because when 1990 * of ffs->setup_state without holding the lock because when
1994 * state is FFS_SETUP_PENDING cmpxchg() in several places in 1991 * state is FFS_SETUP_PENDING cmpxchg() in several places in
1995 * the source does nothing. */ 1992 * the source does nothing.
1993 */
1996 if (ffs->setup_state == FFS_SETUP_PENDING) 1994 if (ffs->setup_state == FFS_SETUP_PENDING)
1997 ffs->setup_state = FFS_SETUP_CANCELED; 1995 ffs->setup_state = FFS_SETUP_CANCELED;
1998 1996
1999 switch (type) { 1997 switch (type) {
2000 case FUNCTIONFS_RESUME: 1998 case FUNCTIONFS_RESUME:
2001 rem_type2 = FUNCTIONFS_SUSPEND; 1999 rem_type2 = FUNCTIONFS_SUSPEND;
2002 /* FALL THGOUTH */ 2000 /* FALL THROUGH */
2003 case FUNCTIONFS_SUSPEND: 2001 case FUNCTIONFS_SUSPEND:
2004 case FUNCTIONFS_SETUP: 2002 case FUNCTIONFS_SETUP:
2005 rem_type1 = type; 2003 rem_type1 = type;
2006 /* discard all similar events */ 2004 /* Discard all similar events */
2007 break; 2005 break;
2008 2006
2009 case FUNCTIONFS_BIND: 2007 case FUNCTIONFS_BIND:
2010 case FUNCTIONFS_UNBIND: 2008 case FUNCTIONFS_UNBIND:
2011 case FUNCTIONFS_DISABLE: 2009 case FUNCTIONFS_DISABLE:
2012 case FUNCTIONFS_ENABLE: 2010 case FUNCTIONFS_ENABLE:
2013 /* discard everything other then power management. */ 2011 /* Discard everything other then power management. */
2014 rem_type1 = FUNCTIONFS_SUSPEND; 2012 rem_type1 = FUNCTIONFS_SUSPEND;
2015 rem_type2 = FUNCTIONFS_RESUME; 2013 rem_type2 = FUNCTIONFS_RESUME;
2016 neg = 1; 2014 neg = 1;
@@ -2056,8 +2054,10 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep,
2056 struct ffs_function *func = priv; 2054 struct ffs_function *func = priv;
2057 struct ffs_ep *ffs_ep; 2055 struct ffs_ep *ffs_ep;
2058 2056
2059 /* If hs_descriptors is not NULL then we are reading hs 2057 /*
2060 * descriptors now */ 2058 * If hs_descriptors is not NULL then we are reading hs
2059 * descriptors now
2060 */
2061 const int isHS = func->function.hs_descriptors != NULL; 2061 const int isHS = func->function.hs_descriptors != NULL;
2062 unsigned idx; 2062 unsigned idx;
2063 2063
@@ -2112,7 +2112,6 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep,
2112 return 0; 2112 return 0;
2113} 2113}
2114 2114
2115
2116static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep, 2115static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep,
2117 struct usb_descriptor_header *desc, 2116 struct usb_descriptor_header *desc,
2118 void *priv) 2117 void *priv)
@@ -2144,8 +2143,10 @@ static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep,
2144 break; 2143 break;
2145 2144
2146 case FFS_ENDPOINT: 2145 case FFS_ENDPOINT:
2147 /* USB_DT_ENDPOINT are handled in 2146 /*
2148 * __ffs_func_bind_do_descs(). */ 2147 * USB_DT_ENDPOINT are handled in
2148 * __ffs_func_bind_do_descs().
2149 */
2149 if (desc->bDescriptorType == USB_DT_ENDPOINT) 2150 if (desc->bDescriptorType == USB_DT_ENDPOINT)
2150 return 0; 2151 return 0;
2151 2152
@@ -2212,9 +2213,11 @@ static int ffs_func_bind(struct usb_configuration *c,
2212 func->eps = data->eps; 2213 func->eps = data->eps;
2213 func->interfaces_nums = data->inums; 2214 func->interfaces_nums = data->inums;
2214 2215
2215 /* Go throught all the endpoint descriptors and allocate 2216 /*
2217 * Go through all the endpoint descriptors and allocate
2216 * endpoints first, so that later we can rewrite the endpoint 2218 * endpoints first, so that later we can rewrite the endpoint
2217 * numbers without worying that it may be described later on. */ 2219 * numbers without worrying that it may be described later on.
2220 */
2218 if (likely(full)) { 2221 if (likely(full)) {
2219 func->function.descriptors = data->fs_descs; 2222 func->function.descriptors = data->fs_descs;
2220 ret = ffs_do_descs(ffs->fs_descs_count, 2223 ret = ffs_do_descs(ffs->fs_descs_count,
@@ -2235,9 +2238,11 @@ static int ffs_func_bind(struct usb_configuration *c,
2235 __ffs_func_bind_do_descs, func); 2238 __ffs_func_bind_do_descs, func);
2236 } 2239 }
2237 2240
2238 /* Now handle interface numbers allocation and interface and 2241 /*
2239 * enpoint numbers rewritting. We can do that in one go 2242 * Now handle interface numbers allocation and interface and
2240 * now. */ 2243 * endpoint numbers rewriting. We can do that in one go
2244 * now.
2245 */
2241 ret = ffs_do_descs(ffs->fs_descs_count + 2246 ret = ffs_do_descs(ffs->fs_descs_count +
2242 (high ? ffs->hs_descs_count : 0), 2247 (high ? ffs->hs_descs_count : 0),
2243 data->raw_descs, sizeof data->raw_descs, 2248 data->raw_descs, sizeof data->raw_descs,
@@ -2275,7 +2280,6 @@ static void ffs_func_unbind(struct usb_configuration *c,
2275 ffs_func_free(func); 2280 ffs_func_free(func);
2276} 2281}
2277 2282
2278
2279static int ffs_func_set_alt(struct usb_function *f, 2283static int ffs_func_set_alt(struct usb_function *f,
2280 unsigned interface, unsigned alt) 2284 unsigned interface, unsigned alt)
2281{ 2285{
@@ -2329,14 +2333,15 @@ static int ffs_func_setup(struct usb_function *f,
2329 FVDBG("creq->wIndex = %04x", le16_to_cpu(creq->wIndex)); 2333 FVDBG("creq->wIndex = %04x", le16_to_cpu(creq->wIndex));
2330 FVDBG("creq->wLength = %04x", le16_to_cpu(creq->wLength)); 2334 FVDBG("creq->wLength = %04x", le16_to_cpu(creq->wLength));
2331 2335
2332 /* Most requests directed to interface go throught here 2336 /*
2337 * Most requests directed to interface go through here
2333 * (notable exceptions are set/get interface) so we need to 2338 * (notable exceptions are set/get interface) so we need to
2334 * handle them. All other either handled by composite or 2339 * handle them. All other either handled by composite or
2335 * passed to usb_configuration->setup() (if one is set). No 2340 * passed to usb_configuration->setup() (if one is set). No
2336 * matter, we will handle requests directed to endpoint here 2341 * matter, we will handle requests directed to endpoint here
2337 * as well (as it's straightforward) but what to do with any 2342 * as well (as it's straightforward) but what to do with any
2338 * other request? */ 2343 * other request?
2339 2344 */
2340 if (ffs->state != FFS_ACTIVE) 2345 if (ffs->state != FFS_ACTIVE)
2341 return -ENODEV; 2346 return -ENODEV;
2342 2347
@@ -2379,8 +2384,7 @@ static void ffs_func_resume(struct usb_function *f)
2379} 2384}
2380 2385
2381 2386
2382 2387/* Endpoint and interface numbers reverse mapping ***************************/
2383/* Enpoint and interface numbers reverse mapping ****************************/
2384 2388
2385static int ffs_func_revmap_ep(struct ffs_function *func, u8 num) 2389static int ffs_func_revmap_ep(struct ffs_function *func, u8 num)
2386{ 2390{
@@ -2411,7 +2415,6 @@ static int ffs_mutex_lock(struct mutex *mutex, unsigned nonblock)
2411 : mutex_lock_interruptible(mutex); 2415 : mutex_lock_interruptible(mutex);
2412} 2416}
2413 2417
2414
2415static char *ffs_prepare_buffer(const char * __user buf, size_t len) 2418static char *ffs_prepare_buffer(const char * __user buf, size_t len)
2416{ 2419{
2417 char *data; 2420 char *data;
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
index af75e3620849..3dc19892cfdc 100644
--- a/drivers/usb/gadget/g_ffs.c
+++ b/drivers/usb/gadget/g_ffs.c
@@ -1,7 +1,27 @@
1/*
2 * g_ffs.c -- user mode file system API for USB composite function controllers
3 *
4 * Copyright (C) 2010 Samsung Electronics
5 * Author: Michal Nazarewicz <m.nazarewicz@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
1#include <linux/module.h> 22#include <linux/module.h>
2#include <linux/utsname.h> 23#include <linux/utsname.h>
3 24
4
5/* 25/*
6 * kbuild is not very cooperative with respect to linking separately 26 * kbuild is not very cooperative with respect to linking separately
7 * compiled library objects into one module. So for now we won't use 27 * compiled library objects into one module. So for now we won't use
@@ -43,7 +63,6 @@ static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
43 63
44#include "f_fs.c" 64#include "f_fs.c"
45 65
46
47#define DRIVER_NAME "g_ffs" 66#define DRIVER_NAME "g_ffs"
48#define DRIVER_DESC "USB Function Filesystem" 67#define DRIVER_DESC "USB Function Filesystem"
49#define DRIVER_VERSION "24 Aug 2004" 68#define DRIVER_VERSION "24 Aug 2004"
@@ -73,8 +92,6 @@ MODULE_PARM_DESC(bDeviceSubClass, "USB Device subclass");
73module_param_named(bDeviceProtocol, gfs_dev_desc.bDeviceProtocol, byte, 0644); 92module_param_named(bDeviceProtocol, gfs_dev_desc.bDeviceProtocol, byte, 0644);
74MODULE_PARM_DESC(bDeviceProtocol, "USB Device protocol"); 93MODULE_PARM_DESC(bDeviceProtocol, "USB Device protocol");
75 94
76
77
78static const struct usb_descriptor_header *gfs_otg_desc[] = { 95static const struct usb_descriptor_header *gfs_otg_desc[] = {
79 (const struct usb_descriptor_header *) 96 (const struct usb_descriptor_header *)
80 &(const struct usb_otg_descriptor) { 97 &(const struct usb_otg_descriptor) {
@@ -91,8 +108,7 @@ static const struct usb_descriptor_header *gfs_otg_desc[] = {
91 NULL 108 NULL
92}; 109};
93 110
94/* string IDs are assigned dynamically */ 111/* String IDs are assigned dynamically */
95
96static struct usb_string gfs_strings[] = { 112static struct usb_string gfs_strings[] = {
97#ifdef CONFIG_USB_FUNCTIONFS_RNDIS 113#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
98 { .s = "FunctionFS + RNDIS" }, 114 { .s = "FunctionFS + RNDIS" },
@@ -114,8 +130,6 @@ static struct usb_gadget_strings *gfs_dev_strings[] = {
114 NULL, 130 NULL,
115}; 131};
116 132
117
118
119struct gfs_configuration { 133struct gfs_configuration {
120 struct usb_configuration c; 134 struct usb_configuration c;
121 int (*eth)(struct usb_configuration *c, u8 *ethaddr); 135 int (*eth)(struct usb_configuration *c, u8 *ethaddr);
@@ -138,7 +152,6 @@ struct gfs_configuration {
138#endif 152#endif
139}; 153};
140 154
141
142static int gfs_bind(struct usb_composite_dev *cdev); 155static int gfs_bind(struct usb_composite_dev *cdev);
143static int gfs_unbind(struct usb_composite_dev *cdev); 156static int gfs_unbind(struct usb_composite_dev *cdev);
144static int gfs_do_config(struct usb_configuration *c); 157static int gfs_do_config(struct usb_configuration *c);
@@ -151,11 +164,9 @@ static struct usb_composite_driver gfs_driver = {
151 .iProduct = DRIVER_DESC, 164 .iProduct = DRIVER_DESC,
152}; 165};
153 166
154
155static struct ffs_data *gfs_ffs_data; 167static struct ffs_data *gfs_ffs_data;
156static unsigned long gfs_registered; 168static unsigned long gfs_registered;
157 169
158
159static int gfs_init(void) 170static int gfs_init(void)
160{ 171{
161 ENTER(); 172 ENTER();
@@ -175,7 +186,6 @@ static void gfs_exit(void)
175} 186}
176module_exit(gfs_exit); 187module_exit(gfs_exit);
177 188
178
179static int functionfs_ready_callback(struct ffs_data *ffs) 189static int functionfs_ready_callback(struct ffs_data *ffs)
180{ 190{
181 int ret; 191 int ret;
@@ -200,14 +210,11 @@ static void functionfs_closed_callback(struct ffs_data *ffs)
200 usb_composite_unregister(&gfs_driver); 210 usb_composite_unregister(&gfs_driver);
201} 211}
202 212
203
204static int functionfs_check_dev_callback(const char *dev_name) 213static int functionfs_check_dev_callback(const char *dev_name)
205{ 214{
206 return 0; 215 return 0;
207} 216}
208 217
209
210
211static int gfs_bind(struct usb_composite_dev *cdev) 218static int gfs_bind(struct usb_composite_dev *cdev)
212{ 219{
213 int ret, i; 220 int ret, i;
@@ -274,7 +281,6 @@ static int gfs_unbind(struct usb_composite_dev *cdev)
274 return 0; 281 return 0;
275} 282}
276 283
277
278static int gfs_do_config(struct usb_configuration *c) 284static int gfs_do_config(struct usb_configuration *c)
279{ 285{
280 struct gfs_configuration *gc = 286 struct gfs_configuration *gc =
@@ -315,7 +321,6 @@ static int gfs_do_config(struct usb_configuration *c)
315 return 0; 321 return 0;
316} 322}
317 323
318
319#ifdef CONFIG_USB_FUNCTIONFS_ETH 324#ifdef CONFIG_USB_FUNCTIONFS_ETH
320 325
321static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) 326static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])