diff options
author | Greg Kroah-Hartman <gregkh@suse.de> | 2010-12-16 13:05:06 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-12-16 13:05:06 -0500 |
commit | 36facadd9ea98f8415d0dbb63e0763b7ee9d3911 (patch) | |
tree | 99dea00b332ed852f2b0a4923b581dd723f03634 /drivers/usb/gadget/f_fs.c | |
parent | 2faa83e2a519abea1055d156ce1b42b8fa57e87b (diff) | |
parent | 0b83ae960cd7d4a5ee02786ecf41ab45688999bf (diff) |
Merge branch 'usb-next' into musb-merge
* usb-next: (132 commits)
USB: uas: Use GFP_NOIO instead of GFP_KERNEL in I/O submission path
USB: uas: Ensure we only bind to a UAS interface
USB: uas: Rename sense pipe and sense urb to status pipe and status urb
USB: uas: Use kzalloc instead of kmalloc
USB: uas: Fix up the Sense IU
usb: musb: core: kill unneeded #include's
DA8xx: assign name to MUSB IRQ resource
usb: gadget: g_ncm added
usb: gadget: f_ncm.c added
usb: gadget: u_ether: prepare for NCM
usb: pch_udc: Fix setup transfers with data out
usb: pch_udc: Fix compile error, warnings and checkpatch warnings
usb: add ab8500 usb transceiver driver
USB: gadget: Implement runtime PM for MSM bus glue driver
USB: gadget: Implement runtime PM for ci13xxx gadget
USB: gadget: Add USB controller driver for MSM SoC
USB: gadget: Introduce ci13xxx_udc_driver struct
USB: gadget: Initialize ci13xxx gadget device's coherent DMA mask
USB: gadget: Fix "scheduling while atomic" bugs in ci13xxx_udc
USB: gadget: Separate out PCI bus code from ci13xxx_udc
...
Diffstat (limited to 'drivers/usb/gadget/f_fs.c')
-rw-r--r-- | drivers/usb/gadget/f_fs.c | 437 |
1 files changed, 213 insertions, 224 deletions
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c index 484c5ba5450e..1499f9e4afa8 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 | * |
@@ -38,62 +38,56 @@ | |||
38 | #define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */ | 38 | #define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */ |
39 | 39 | ||
40 | 40 | ||
41 | /* Debuging *****************************************************************/ | 41 | /* Debugging ****************************************************************/ |
42 | |||
43 | #define ffs_printk(level, fmt, args...) printk(level "f_fs: " fmt "\n", ## args) | ||
44 | |||
45 | #define FERR(...) ffs_printk(KERN_ERR, __VA_ARGS__) | ||
46 | #define FINFO(...) ffs_printk(KERN_INFO, __VA_ARGS__) | ||
47 | |||
48 | #ifdef DEBUG | ||
49 | # define FDBG(...) ffs_printk(KERN_DEBUG, __VA_ARGS__) | ||
50 | #else | ||
51 | # define FDBG(...) do { } while (0) | ||
52 | #endif /* DEBUG */ | ||
53 | |||
54 | #ifdef VERBOSE_DEBUG | ||
55 | # define FVDBG FDBG | ||
56 | #else | ||
57 | # define FVDBG(...) do { } while (0) | ||
58 | #endif /* VERBOSE_DEBUG */ | ||
59 | |||
60 | #define ENTER() FVDBG("%s()", __func__) | ||
61 | 42 | ||
62 | #ifdef VERBOSE_DEBUG | 43 | #ifdef VERBOSE_DEBUG |
44 | # define pr_vdebug pr_debug | ||
63 | # define ffs_dump_mem(prefix, ptr, len) \ | 45 | # define ffs_dump_mem(prefix, ptr, len) \ |
64 | print_hex_dump_bytes("f_fs" prefix ": ", DUMP_PREFIX_NONE, ptr, len) | 46 | print_hex_dump_bytes(pr_fmt(prefix ": "), DUMP_PREFIX_NONE, ptr, len) |
65 | #else | 47 | #else |
48 | # define pr_vdebug(...) do { } while (0) | ||
66 | # define ffs_dump_mem(prefix, ptr, len) do { } while (0) | 49 | # define ffs_dump_mem(prefix, ptr, len) do { } while (0) |
67 | #endif | 50 | #endif /* VERBOSE_DEBUG */ |
51 | |||
52 | #define ENTER() pr_vdebug("%s()\n", __func__) | ||
68 | 53 | ||
69 | 54 | ||
70 | /* The data structure and setup file ****************************************/ | 55 | /* The data structure and setup file ****************************************/ |
71 | 56 | ||
72 | enum ffs_state { | 57 | enum ffs_state { |
73 | /* Waiting for descriptors and strings. */ | 58 | /* |
74 | /* In this state no open(2), read(2) or write(2) on epfiles | 59 | * Waiting for descriptors and strings. |
60 | * | ||
61 | * In this state no open(2), read(2) or write(2) on epfiles | ||
75 | * may succeed (which should not be the problem as there | 62 | * may succeed (which should not be the problem as there |
76 | * should be no such files opened in the firts place). */ | 63 | * should be no such files opened in the first place). |
64 | */ | ||
77 | FFS_READ_DESCRIPTORS, | 65 | FFS_READ_DESCRIPTORS, |
78 | FFS_READ_STRINGS, | 66 | FFS_READ_STRINGS, |
79 | 67 | ||
80 | /* We've got descriptors and strings. We are or have called | 68 | /* |
69 | * We've got descriptors and strings. We are or have called | ||
81 | * functionfs_ready_callback(). functionfs_bind() may have | 70 | * functionfs_ready_callback(). functionfs_bind() may have |
82 | * been called but we don't know. */ | 71 | * been called but we don't know. |
83 | /* This is the only state in which operations on epfiles may | 72 | * |
84 | * succeed. */ | 73 | * This is the only state in which operations on epfiles may |
74 | * succeed. | ||
75 | */ | ||
85 | FFS_ACTIVE, | 76 | FFS_ACTIVE, |
86 | 77 | ||
87 | /* All endpoints have been closed. This state is also set if | 78 | /* |
79 | * All endpoints have been closed. This state is also set if | ||
88 | * we encounter an unrecoverable error. The only | 80 | * we encounter an unrecoverable error. The only |
89 | * unrecoverable error is situation when after reading strings | 81 | * unrecoverable error is situation when after reading strings |
90 | * from user space we fail to initialise EP files or | 82 | * from user space we fail to initialise epfiles or |
91 | * functionfs_ready_callback() returns with error (<0). */ | 83 | * functionfs_ready_callback() returns with error (<0). |
92 | /* In this state no open(2), read(2) or write(2) (both on ep0 | 84 | * |
85 | * In this state no open(2), read(2) or write(2) (both on ep0 | ||
93 | * as well as epfile) may succeed (at this point epfiles are | 86 | * as well as epfile) may succeed (at this point epfiles are |
94 | * unlinked and all closed so this is not a problem; ep0 is | 87 | * unlinked and all closed so this is not a problem; ep0 is |
95 | * also closed but ep0 file exists and so open(2) on ep0 must | 88 | * also closed but ep0 file exists and so open(2) on ep0 must |
96 | * fail). */ | 89 | * fail). |
90 | */ | ||
97 | FFS_CLOSING | 91 | FFS_CLOSING |
98 | }; | 92 | }; |
99 | 93 | ||
@@ -101,14 +95,18 @@ enum ffs_state { | |||
101 | enum ffs_setup_state { | 95 | enum ffs_setup_state { |
102 | /* There is no setup request pending. */ | 96 | /* There is no setup request pending. */ |
103 | FFS_NO_SETUP, | 97 | FFS_NO_SETUP, |
104 | /* User has read events and there was a setup request event | 98 | /* |
99 | * User has read events and there was a setup request event | ||
105 | * there. The next read/write on ep0 will handle the | 100 | * there. The next read/write on ep0 will handle the |
106 | * request. */ | 101 | * request. |
102 | */ | ||
107 | FFS_SETUP_PENDING, | 103 | FFS_SETUP_PENDING, |
108 | /* There was event pending but before user space handled it | 104 | /* |
105 | * There was event pending but before user space handled it | ||
109 | * some other event was introduced which canceled existing | 106 | * some other event was introduced which canceled existing |
110 | * setup. If this state is set read/write on ep0 return | 107 | * setup. If this state is set read/write on ep0 return |
111 | * -EIDRM. This state is only set when adding event. */ | 108 | * -EIDRM. This state is only set when adding event. |
109 | */ | ||
112 | FFS_SETUP_CANCELED | 110 | FFS_SETUP_CANCELED |
113 | }; | 111 | }; |
114 | 112 | ||
@@ -120,23 +118,29 @@ struct ffs_function; | |||
120 | struct ffs_data { | 118 | struct ffs_data { |
121 | struct usb_gadget *gadget; | 119 | struct usb_gadget *gadget; |
122 | 120 | ||
123 | /* Protect access read/write operations, only one read/write | 121 | /* |
122 | * Protect access read/write operations, only one read/write | ||
124 | * at a time. As a consequence protects ep0req and company. | 123 | * at a time. As a consequence protects ep0req and company. |
125 | * While setup request is being processed (queued) this is | 124 | * While setup request is being processed (queued) this is |
126 | * held. */ | 125 | * held. |
126 | */ | ||
127 | struct mutex mutex; | 127 | struct mutex mutex; |
128 | 128 | ||
129 | /* Protect access to enpoint related structures (basically | 129 | /* |
130 | * Protect access to endpoint related structures (basically | ||
130 | * usb_ep_queue(), usb_ep_dequeue(), etc. calls) except for | 131 | * usb_ep_queue(), usb_ep_dequeue(), etc. calls) except for |
131 | * endpint zero. */ | 132 | * endpoint zero. |
133 | */ | ||
132 | spinlock_t eps_lock; | 134 | spinlock_t eps_lock; |
133 | 135 | ||
134 | /* XXX REVISIT do we need our own request? Since we are not | 136 | /* |
135 | * handling setup requests immidiatelly user space may be so | 137 | * XXX REVISIT do we need our own request? Since we are not |
138 | * handling setup requests immediately user space may be so | ||
136 | * slow that another setup will be sent to the gadget but this | 139 | * slow that another setup will be sent to the gadget but this |
137 | * time not to us but another function and then there could be | 140 | * time not to us but another function and then there could be |
138 | * a race. Is that the case? Or maybe we can use cdev->req | 141 | * a race. Is that the case? Or maybe we can use cdev->req |
139 | * after all, maybe we just need some spinlock for that? */ | 142 | * after all, maybe we just need some spinlock for that? |
143 | */ | ||
140 | struct usb_request *ep0req; /* P: mutex */ | 144 | struct usb_request *ep0req; /* P: mutex */ |
141 | struct completion ep0req_completion; /* P: mutex */ | 145 | struct completion ep0req_completion; /* P: mutex */ |
142 | int ep0req_status; /* P: mutex */ | 146 | int ep0req_status; /* P: mutex */ |
@@ -150,7 +154,7 @@ struct ffs_data { | |||
150 | enum ffs_state state; | 154 | enum ffs_state state; |
151 | 155 | ||
152 | /* | 156 | /* |
153 | * Possible transations: | 157 | * Possible transitions: |
154 | * + FFS_NO_SETUP -> FFS_SETUP_PENDING -- P: ev.waitq.lock | 158 | * + FFS_NO_SETUP -> FFS_SETUP_PENDING -- P: ev.waitq.lock |
155 | * happens only in ep0 read which is P: mutex | 159 | * happens only in ep0 read which is P: mutex |
156 | * + FFS_SETUP_PENDING -> FFS_NO_SETUP -- P: ev.waitq.lock | 160 | * + FFS_SETUP_PENDING -> FFS_NO_SETUP -- P: ev.waitq.lock |
@@ -183,18 +187,21 @@ struct ffs_data { | |||
183 | /* Active function */ | 187 | /* Active function */ |
184 | struct ffs_function *func; | 188 | struct ffs_function *func; |
185 | 189 | ||
186 | /* Device name, write once when file system is mounted. | 190 | /* |
187 | * Intendet for user to read if she wants. */ | 191 | * Device name, write once when file system is mounted. |
192 | * Intended for user to read if she wants. | ||
193 | */ | ||
188 | const char *dev_name; | 194 | const char *dev_name; |
189 | /* Private data for our user (ie. gadget). Managed by | 195 | /* Private data for our user (ie. gadget). Managed by user. */ |
190 | * user. */ | ||
191 | void *private_data; | 196 | void *private_data; |
192 | 197 | ||
193 | /* filled by __ffs_data_got_descs() */ | 198 | /* filled by __ffs_data_got_descs() */ |
194 | /* real descriptors are 16 bytes after raw_descs (so you need | 199 | /* |
200 | * Real descriptors are 16 bytes after raw_descs (so you need | ||
195 | * to skip 16 bytes (ie. ffs->raw_descs + 16) to get to the | 201 | * to skip 16 bytes (ie. ffs->raw_descs + 16) to get to the |
196 | * first full speed descriptor). raw_descs_length and | 202 | * first full speed descriptor). raw_descs_length and |
197 | * raw_fs_descs_length do not have those 16 bytes added. */ | 203 | * raw_fs_descs_length do not have those 16 bytes added. |
204 | */ | ||
198 | const void *raw_descs; | 205 | const void *raw_descs; |
199 | unsigned raw_descs_length; | 206 | unsigned raw_descs_length; |
200 | unsigned raw_fs_descs_length; | 207 | unsigned raw_fs_descs_length; |
@@ -211,18 +218,23 @@ struct ffs_data { | |||
211 | const void *raw_strings; | 218 | const void *raw_strings; |
212 | struct usb_gadget_strings **stringtabs; | 219 | struct usb_gadget_strings **stringtabs; |
213 | 220 | ||
214 | /* File system's super block, write once when file system is mounted. */ | 221 | /* |
222 | * File system's super block, write once when file system is | ||
223 | * mounted. | ||
224 | */ | ||
215 | struct super_block *sb; | 225 | struct super_block *sb; |
216 | 226 | ||
217 | /* File permissions, written once when fs is mounted*/ | 227 | /* File permissions, written once when fs is mounted */ |
218 | struct ffs_file_perms { | 228 | struct ffs_file_perms { |
219 | umode_t mode; | 229 | umode_t mode; |
220 | uid_t uid; | 230 | uid_t uid; |
221 | gid_t gid; | 231 | gid_t gid; |
222 | } file_perms; | 232 | } file_perms; |
223 | 233 | ||
224 | /* The endpoint files, filled by ffs_epfiles_create(), | 234 | /* |
225 | * destroyed by ffs_epfiles_destroy(). */ | 235 | * The endpoint files, filled by ffs_epfiles_create(), |
236 | * destroyed by ffs_epfiles_destroy(). | ||
237 | */ | ||
226 | struct ffs_epfile *epfiles; | 238 | struct ffs_epfile *epfiles; |
227 | }; | 239 | }; |
228 | 240 | ||
@@ -236,7 +248,7 @@ static struct ffs_data *__must_check ffs_data_new(void) __attribute__((malloc)); | |||
236 | static void ffs_data_opened(struct ffs_data *ffs); | 248 | static void ffs_data_opened(struct ffs_data *ffs); |
237 | static void ffs_data_closed(struct ffs_data *ffs); | 249 | static void ffs_data_closed(struct ffs_data *ffs); |
238 | 250 | ||
239 | /* Called with ffs->mutex held; take over ownerrship of data. */ | 251 | /* Called with ffs->mutex held; take over ownership of data. */ |
240 | static int __must_check | 252 | static int __must_check |
241 | __ffs_data_got_descs(struct ffs_data *ffs, char *data, size_t len); | 253 | __ffs_data_got_descs(struct ffs_data *ffs, char *data, size_t len); |
242 | static int __must_check | 254 | static int __must_check |
@@ -267,11 +279,9 @@ static struct ffs_function *ffs_func_from_usb(struct usb_function *f) | |||
267 | 279 | ||
268 | static void ffs_func_free(struct ffs_function *func); | 280 | static void ffs_func_free(struct ffs_function *func); |
269 | 281 | ||
270 | |||
271 | static void ffs_func_eps_disable(struct ffs_function *func); | 282 | static void ffs_func_eps_disable(struct ffs_function *func); |
272 | static int __must_check ffs_func_eps_enable(struct ffs_function *func); | 283 | static int __must_check ffs_func_eps_enable(struct ffs_function *func); |
273 | 284 | ||
274 | |||
275 | static int ffs_func_bind(struct usb_configuration *, | 285 | static int ffs_func_bind(struct usb_configuration *, |
276 | struct usb_function *); | 286 | struct usb_function *); |
277 | static void ffs_func_unbind(struct usb_configuration *, | 287 | static void ffs_func_unbind(struct usb_configuration *, |
@@ -288,7 +298,6 @@ static int ffs_func_revmap_ep(struct ffs_function *func, u8 num); | |||
288 | static int ffs_func_revmap_intf(struct ffs_function *func, u8 intf); | 298 | static int ffs_func_revmap_intf(struct ffs_function *func, u8 intf); |
289 | 299 | ||
290 | 300 | ||
291 | |||
292 | /* The endpoints structures *************************************************/ | 301 | /* The endpoints structures *************************************************/ |
293 | 302 | ||
294 | struct ffs_ep { | 303 | struct ffs_ep { |
@@ -321,7 +330,6 @@ struct ffs_epfile { | |||
321 | unsigned char _pad; | 330 | unsigned char _pad; |
322 | }; | 331 | }; |
323 | 332 | ||
324 | |||
325 | static int __must_check ffs_epfiles_create(struct ffs_data *ffs); | 333 | static int __must_check ffs_epfiles_create(struct ffs_data *ffs); |
326 | static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count); | 334 | static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count); |
327 | 335 | ||
@@ -348,7 +356,6 @@ static void ffs_ep0_complete(struct usb_ep *ep, struct usb_request *req) | |||
348 | complete_all(&ffs->ep0req_completion); | 356 | complete_all(&ffs->ep0req_completion); |
349 | } | 357 | } |
350 | 358 | ||
351 | |||
352 | static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len) | 359 | static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len) |
353 | { | 360 | { |
354 | struct usb_request *req = ffs->ep0req; | 361 | struct usb_request *req = ffs->ep0req; |
@@ -380,17 +387,16 @@ static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len) | |||
380 | static int __ffs_ep0_stall(struct ffs_data *ffs) | 387 | static int __ffs_ep0_stall(struct ffs_data *ffs) |
381 | { | 388 | { |
382 | if (ffs->ev.can_stall) { | 389 | if (ffs->ev.can_stall) { |
383 | FVDBG("ep0 stall\n"); | 390 | pr_vdebug("ep0 stall\n"); |
384 | usb_ep_set_halt(ffs->gadget->ep0); | 391 | usb_ep_set_halt(ffs->gadget->ep0); |
385 | ffs->setup_state = FFS_NO_SETUP; | 392 | ffs->setup_state = FFS_NO_SETUP; |
386 | return -EL2HLT; | 393 | return -EL2HLT; |
387 | } else { | 394 | } else { |
388 | FDBG("bogus ep0 stall!\n"); | 395 | pr_debug("bogus ep0 stall!\n"); |
389 | return -ESRCH; | 396 | return -ESRCH; |
390 | } | 397 | } |
391 | } | 398 | } |
392 | 399 | ||
393 | |||
394 | static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, | 400 | static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, |
395 | size_t len, loff_t *ptr) | 401 | size_t len, loff_t *ptr) |
396 | { | 402 | { |
@@ -409,7 +415,6 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, | |||
409 | if (unlikely(ret < 0)) | 415 | if (unlikely(ret < 0)) |
410 | return ret; | 416 | return ret; |
411 | 417 | ||
412 | |||
413 | /* Check state */ | 418 | /* Check state */ |
414 | switch (ffs->state) { | 419 | switch (ffs->state) { |
415 | case FFS_READ_DESCRIPTORS: | 420 | case FFS_READ_DESCRIPTORS: |
@@ -421,14 +426,14 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, | |||
421 | } | 426 | } |
422 | 427 | ||
423 | data = ffs_prepare_buffer(buf, len); | 428 | data = ffs_prepare_buffer(buf, len); |
424 | if (unlikely(IS_ERR(data))) { | 429 | if (IS_ERR(data)) { |
425 | ret = PTR_ERR(data); | 430 | ret = PTR_ERR(data); |
426 | break; | 431 | break; |
427 | } | 432 | } |
428 | 433 | ||
429 | /* Handle data */ | 434 | /* Handle data */ |
430 | if (ffs->state == FFS_READ_DESCRIPTORS) { | 435 | if (ffs->state == FFS_READ_DESCRIPTORS) { |
431 | FINFO("read descriptors"); | 436 | pr_info("read descriptors\n"); |
432 | ret = __ffs_data_got_descs(ffs, data, len); | 437 | ret = __ffs_data_got_descs(ffs, data, len); |
433 | if (unlikely(ret < 0)) | 438 | if (unlikely(ret < 0)) |
434 | break; | 439 | break; |
@@ -436,7 +441,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, | |||
436 | ffs->state = FFS_READ_STRINGS; | 441 | ffs->state = FFS_READ_STRINGS; |
437 | ret = len; | 442 | ret = len; |
438 | } else { | 443 | } else { |
439 | FINFO("read strings"); | 444 | pr_info("read strings\n"); |
440 | ret = __ffs_data_got_strings(ffs, data, len); | 445 | ret = __ffs_data_got_strings(ffs, data, len); |
441 | if (unlikely(ret < 0)) | 446 | if (unlikely(ret < 0)) |
442 | break; | 447 | break; |
@@ -461,11 +466,12 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, | |||
461 | } | 466 | } |
462 | break; | 467 | break; |
463 | 468 | ||
464 | |||
465 | case FFS_ACTIVE: | 469 | case FFS_ACTIVE: |
466 | data = NULL; | 470 | data = NULL; |
467 | /* We're called from user space, we can use _irq | 471 | /* |
468 | * rather then _irqsave */ | 472 | * We're called from user space, we can use _irq |
473 | * rather then _irqsave | ||
474 | */ | ||
469 | spin_lock_irq(&ffs->ev.waitq.lock); | 475 | spin_lock_irq(&ffs->ev.waitq.lock); |
470 | switch (FFS_SETUP_STATE(ffs)) { | 476 | switch (FFS_SETUP_STATE(ffs)) { |
471 | case FFS_SETUP_CANCELED: | 477 | case FFS_SETUP_CANCELED: |
@@ -493,23 +499,25 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, | |||
493 | spin_unlock_irq(&ffs->ev.waitq.lock); | 499 | spin_unlock_irq(&ffs->ev.waitq.lock); |
494 | 500 | ||
495 | data = ffs_prepare_buffer(buf, len); | 501 | data = ffs_prepare_buffer(buf, len); |
496 | if (unlikely(IS_ERR(data))) { | 502 | if (IS_ERR(data)) { |
497 | ret = PTR_ERR(data); | 503 | ret = PTR_ERR(data); |
498 | break; | 504 | break; |
499 | } | 505 | } |
500 | 506 | ||
501 | spin_lock_irq(&ffs->ev.waitq.lock); | 507 | spin_lock_irq(&ffs->ev.waitq.lock); |
502 | 508 | ||
503 | /* We are guaranteed to be still in FFS_ACTIVE state | 509 | /* |
510 | * We are guaranteed to be still in FFS_ACTIVE state | ||
504 | * but the state of setup could have changed from | 511 | * but the state of setup could have changed from |
505 | * FFS_SETUP_PENDING to FFS_SETUP_CANCELED so we need | 512 | * FFS_SETUP_PENDING to FFS_SETUP_CANCELED so we need |
506 | * to check for that. If that happened we copied data | 513 | * to check for that. If that happened we copied data |
507 | * from user space in vain but it's unlikely. */ | 514 | * from user space in vain but it's unlikely. |
508 | /* For sure we are not in FFS_NO_SETUP since this is | 515 | * |
516 | * For sure we are not in FFS_NO_SETUP since this is | ||
509 | * the only place FFS_SETUP_PENDING -> FFS_NO_SETUP | 517 | * the only place FFS_SETUP_PENDING -> FFS_NO_SETUP |
510 | * transition can be performed and it's protected by | 518 | * transition can be performed and it's protected by |
511 | * mutex. */ | 519 | * mutex. |
512 | 520 | */ | |
513 | if (FFS_SETUP_STATE(ffs) == FFS_SETUP_CANCELED) { | 521 | if (FFS_SETUP_STATE(ffs) == FFS_SETUP_CANCELED) { |
514 | ret = -EIDRM; | 522 | ret = -EIDRM; |
515 | done_spin: | 523 | done_spin: |
@@ -521,25 +529,22 @@ done_spin: | |||
521 | kfree(data); | 529 | kfree(data); |
522 | break; | 530 | break; |
523 | 531 | ||
524 | |||
525 | default: | 532 | default: |
526 | ret = -EBADFD; | 533 | ret = -EBADFD; |
527 | break; | 534 | break; |
528 | } | 535 | } |
529 | 536 | ||
530 | |||
531 | mutex_unlock(&ffs->mutex); | 537 | mutex_unlock(&ffs->mutex); |
532 | return ret; | 538 | return ret; |
533 | } | 539 | } |
534 | 540 | ||
535 | |||
536 | |||
537 | static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf, | 541 | static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf, |
538 | size_t n) | 542 | size_t n) |
539 | { | 543 | { |
540 | /* We are holding ffs->ev.waitq.lock and ffs->mutex and we need | 544 | /* |
541 | * to release them. */ | 545 | * We are holding ffs->ev.waitq.lock and ffs->mutex and we need |
542 | 546 | * to release them. | |
547 | */ | ||
543 | struct usb_functionfs_event events[n]; | 548 | struct usb_functionfs_event events[n]; |
544 | unsigned i = 0; | 549 | unsigned i = 0; |
545 | 550 | ||
@@ -568,7 +573,6 @@ static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf, | |||
568 | ? -EFAULT : sizeof events; | 573 | ? -EFAULT : sizeof events; |
569 | } | 574 | } |
570 | 575 | ||
571 | |||
572 | static ssize_t ffs_ep0_read(struct file *file, char __user *buf, | 576 | static ssize_t ffs_ep0_read(struct file *file, char __user *buf, |
573 | size_t len, loff_t *ptr) | 577 | size_t len, loff_t *ptr) |
574 | { | 578 | { |
@@ -588,16 +592,16 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf, | |||
588 | if (unlikely(ret < 0)) | 592 | if (unlikely(ret < 0)) |
589 | return ret; | 593 | return ret; |
590 | 594 | ||
591 | |||
592 | /* Check state */ | 595 | /* Check state */ |
593 | if (ffs->state != FFS_ACTIVE) { | 596 | if (ffs->state != FFS_ACTIVE) { |
594 | ret = -EBADFD; | 597 | ret = -EBADFD; |
595 | goto done_mutex; | 598 | goto done_mutex; |
596 | } | 599 | } |
597 | 600 | ||
598 | 601 | /* | |
599 | /* We're called from user space, we can use _irq rather then | 602 | * We're called from user space, we can use _irq rather then |
600 | * _irqsave */ | 603 | * _irqsave |
604 | */ | ||
601 | spin_lock_irq(&ffs->ev.waitq.lock); | 605 | spin_lock_irq(&ffs->ev.waitq.lock); |
602 | 606 | ||
603 | switch (FFS_SETUP_STATE(ffs)) { | 607 | switch (FFS_SETUP_STATE(ffs)) { |
@@ -617,7 +621,8 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf, | |||
617 | break; | 621 | break; |
618 | } | 622 | } |
619 | 623 | ||
620 | if (unlikely(wait_event_interruptible_exclusive_locked_irq(ffs->ev.waitq, ffs->ev.count))) { | 624 | if (wait_event_interruptible_exclusive_locked_irq(ffs->ev.waitq, |
625 | ffs->ev.count)) { | ||
621 | ret = -EINTR; | 626 | ret = -EINTR; |
622 | break; | 627 | break; |
623 | } | 628 | } |
@@ -625,7 +630,6 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf, | |||
625 | return __ffs_ep0_read_events(ffs, buf, | 630 | return __ffs_ep0_read_events(ffs, buf, |
626 | min(n, (size_t)ffs->ev.count)); | 631 | min(n, (size_t)ffs->ev.count)); |
627 | 632 | ||
628 | |||
629 | case FFS_SETUP_PENDING: | 633 | case FFS_SETUP_PENDING: |
630 | if (ffs->ev.setup.bRequestType & USB_DIR_IN) { | 634 | if (ffs->ev.setup.bRequestType & USB_DIR_IN) { |
631 | spin_unlock_irq(&ffs->ev.waitq.lock); | 635 | spin_unlock_irq(&ffs->ev.waitq.lock); |
@@ -671,8 +675,6 @@ done_mutex: | |||
671 | return ret; | 675 | return ret; |
672 | } | 676 | } |
673 | 677 | ||
674 | |||
675 | |||
676 | static int ffs_ep0_open(struct inode *inode, struct file *file) | 678 | static int ffs_ep0_open(struct inode *inode, struct file *file) |
677 | { | 679 | { |
678 | struct ffs_data *ffs = inode->i_private; | 680 | struct ffs_data *ffs = inode->i_private; |
@@ -688,7 +690,6 @@ static int ffs_ep0_open(struct inode *inode, struct file *file) | |||
688 | return 0; | 690 | return 0; |
689 | } | 691 | } |
690 | 692 | ||
691 | |||
692 | static int ffs_ep0_release(struct inode *inode, struct file *file) | 693 | static int ffs_ep0_release(struct inode *inode, struct file *file) |
693 | { | 694 | { |
694 | struct ffs_data *ffs = file->private_data; | 695 | struct ffs_data *ffs = file->private_data; |
@@ -700,7 +701,6 @@ static int ffs_ep0_release(struct inode *inode, struct file *file) | |||
700 | return 0; | 701 | return 0; |
701 | } | 702 | } |
702 | 703 | ||
703 | |||
704 | static long ffs_ep0_ioctl(struct file *file, unsigned code, unsigned long value) | 704 | static long ffs_ep0_ioctl(struct file *file, unsigned code, unsigned long value) |
705 | { | 705 | { |
706 | struct ffs_data *ffs = file->private_data; | 706 | struct ffs_data *ffs = file->private_data; |
@@ -721,7 +721,6 @@ static long ffs_ep0_ioctl(struct file *file, unsigned code, unsigned long value) | |||
721 | return ret; | 721 | return ret; |
722 | } | 722 | } |
723 | 723 | ||
724 | |||
725 | static const struct file_operations ffs_ep0_operations = { | 724 | static const struct file_operations ffs_ep0_operations = { |
726 | .owner = THIS_MODULE, | 725 | .owner = THIS_MODULE, |
727 | .llseek = no_llseek, | 726 | .llseek = no_llseek, |
@@ -736,7 +735,6 @@ static const struct file_operations ffs_ep0_operations = { | |||
736 | 735 | ||
737 | /* "Normal" endpoints operations ********************************************/ | 736 | /* "Normal" endpoints operations ********************************************/ |
738 | 737 | ||
739 | |||
740 | static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req) | 738 | static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req) |
741 | { | 739 | { |
742 | ENTER(); | 740 | ENTER(); |
@@ -747,7 +745,6 @@ static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req) | |||
747 | } | 745 | } |
748 | } | 746 | } |
749 | 747 | ||
750 | |||
751 | static ssize_t ffs_epfile_io(struct file *file, | 748 | static ssize_t ffs_epfile_io(struct file *file, |
752 | char __user *buf, size_t len, int read) | 749 | char __user *buf, size_t len, int read) |
753 | { | 750 | { |
@@ -777,8 +774,8 @@ first_try: | |||
777 | goto error; | 774 | goto error; |
778 | } | 775 | } |
779 | 776 | ||
780 | if (unlikely(wait_event_interruptible | 777 | if (wait_event_interruptible(epfile->wait, |
781 | (epfile->wait, (ep = epfile->ep)))) { | 778 | (ep = epfile->ep))) { |
782 | ret = -EINTR; | 779 | ret = -EINTR; |
783 | goto error; | 780 | goto error; |
784 | } | 781 | } |
@@ -810,12 +807,16 @@ first_try: | |||
810 | if (unlikely(ret)) | 807 | if (unlikely(ret)) |
811 | goto error; | 808 | goto error; |
812 | 809 | ||
813 | /* We're called from user space, we can use _irq rather then | 810 | /* |
814 | * _irqsave */ | 811 | * We're called from user space, we can use _irq rather then |
812 | * _irqsave | ||
813 | */ | ||
815 | spin_lock_irq(&epfile->ffs->eps_lock); | 814 | spin_lock_irq(&epfile->ffs->eps_lock); |
816 | 815 | ||
817 | /* While we were acquiring mutex endpoint got disabled | 816 | /* |
818 | * or changed? */ | 817 | * While we were acquiring mutex endpoint got disabled |
818 | * or changed? | ||
819 | */ | ||
819 | } while (unlikely(epfile->ep != ep)); | 820 | } while (unlikely(epfile->ep != ep)); |
820 | 821 | ||
821 | /* Halt */ | 822 | /* Halt */ |
@@ -857,7 +858,6 @@ error: | |||
857 | return ret; | 858 | return ret; |
858 | } | 859 | } |
859 | 860 | ||
860 | |||
861 | static ssize_t | 861 | static ssize_t |
862 | ffs_epfile_write(struct file *file, const char __user *buf, size_t len, | 862 | ffs_epfile_write(struct file *file, const char __user *buf, size_t len, |
863 | loff_t *ptr) | 863 | loff_t *ptr) |
@@ -903,7 +903,6 @@ ffs_epfile_release(struct inode *inode, struct file *file) | |||
903 | return 0; | 903 | return 0; |
904 | } | 904 | } |
905 | 905 | ||
906 | |||
907 | static long ffs_epfile_ioctl(struct file *file, unsigned code, | 906 | static long ffs_epfile_ioctl(struct file *file, unsigned code, |
908 | unsigned long value) | 907 | unsigned long value) |
909 | { | 908 | { |
@@ -942,7 +941,6 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code, | |||
942 | return ret; | 941 | return ret; |
943 | } | 942 | } |
944 | 943 | ||
945 | |||
946 | static const struct file_operations ffs_epfile_operations = { | 944 | static const struct file_operations ffs_epfile_operations = { |
947 | .owner = THIS_MODULE, | 945 | .owner = THIS_MODULE, |
948 | .llseek = no_llseek, | 946 | .llseek = no_llseek, |
@@ -955,15 +953,13 @@ static const struct file_operations ffs_epfile_operations = { | |||
955 | }; | 953 | }; |
956 | 954 | ||
957 | 955 | ||
958 | |||
959 | /* File system and super block operations ***********************************/ | 956 | /* File system and super block operations ***********************************/ |
960 | 957 | ||
961 | /* | 958 | /* |
962 | * Mounting the filesystem creates a controller file, used first for | 959 | * Mounting the file system creates a controller file, used first for |
963 | * function configuration then later for event monitoring. | 960 | * function configuration then later for event monitoring. |
964 | */ | 961 | */ |
965 | 962 | ||
966 | |||
967 | static struct inode *__must_check | 963 | static struct inode *__must_check |
968 | ffs_sb_make_inode(struct super_block *sb, void *data, | 964 | ffs_sb_make_inode(struct super_block *sb, void *data, |
969 | const struct file_operations *fops, | 965 | const struct file_operations *fops, |
@@ -996,9 +992,7 @@ ffs_sb_make_inode(struct super_block *sb, void *data, | |||
996 | return inode; | 992 | return inode; |
997 | } | 993 | } |
998 | 994 | ||
999 | |||
1000 | /* Create "regular" file */ | 995 | /* Create "regular" file */ |
1001 | |||
1002 | static struct inode *ffs_sb_create_file(struct super_block *sb, | 996 | static struct inode *ffs_sb_create_file(struct super_block *sb, |
1003 | const char *name, void *data, | 997 | const char *name, void *data, |
1004 | const struct file_operations *fops, | 998 | const struct file_operations *fops, |
@@ -1027,9 +1021,7 @@ static struct inode *ffs_sb_create_file(struct super_block *sb, | |||
1027 | return inode; | 1021 | return inode; |
1028 | } | 1022 | } |
1029 | 1023 | ||
1030 | |||
1031 | /* Super block */ | 1024 | /* Super block */ |
1032 | |||
1033 | static const struct super_operations ffs_sb_operations = { | 1025 | static const struct super_operations ffs_sb_operations = { |
1034 | .statfs = simple_statfs, | 1026 | .statfs = simple_statfs, |
1035 | .drop_inode = generic_delete_inode, | 1027 | .drop_inode = generic_delete_inode, |
@@ -1050,7 +1042,7 @@ static int ffs_sb_fill(struct super_block *sb, void *_data, int silent) | |||
1050 | 1042 | ||
1051 | ENTER(); | 1043 | ENTER(); |
1052 | 1044 | ||
1053 | /* Initialize data */ | 1045 | /* Initialise data */ |
1054 | ffs = ffs_data_new(); | 1046 | ffs = ffs_data_new(); |
1055 | if (unlikely(!ffs)) | 1047 | if (unlikely(!ffs)) |
1056 | goto enomem0; | 1048 | goto enomem0; |
@@ -1096,7 +1088,6 @@ enomem0: | |||
1096 | return -ENOMEM; | 1088 | return -ENOMEM; |
1097 | } | 1089 | } |
1098 | 1090 | ||
1099 | |||
1100 | static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts) | 1091 | static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts) |
1101 | { | 1092 | { |
1102 | ENTER(); | 1093 | ENTER(); |
@@ -1116,7 +1107,7 @@ static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts) | |||
1116 | /* Value limit */ | 1107 | /* Value limit */ |
1117 | eq = strchr(opts, '='); | 1108 | eq = strchr(opts, '='); |
1118 | if (unlikely(!eq)) { | 1109 | if (unlikely(!eq)) { |
1119 | FERR("'=' missing in %s", opts); | 1110 | pr_err("'=' missing in %s\n", opts); |
1120 | return -EINVAL; | 1111 | return -EINVAL; |
1121 | } | 1112 | } |
1122 | *eq = 0; | 1113 | *eq = 0; |
@@ -1124,7 +1115,7 @@ static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts) | |||
1124 | /* Parse value */ | 1115 | /* Parse value */ |
1125 | value = simple_strtoul(eq + 1, &end, 0); | 1116 | value = simple_strtoul(eq + 1, &end, 0); |
1126 | if (unlikely(*end != ',' && *end != 0)) { | 1117 | if (unlikely(*end != ',' && *end != 0)) { |
1127 | FERR("%s: invalid value: %s", opts, eq + 1); | 1118 | pr_err("%s: invalid value: %s\n", opts, eq + 1); |
1128 | return -EINVAL; | 1119 | return -EINVAL; |
1129 | } | 1120 | } |
1130 | 1121 | ||
@@ -1159,7 +1150,7 @@ static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts) | |||
1159 | 1150 | ||
1160 | default: | 1151 | default: |
1161 | invalid: | 1152 | invalid: |
1162 | FERR("%s: invalid option", opts); | 1153 | pr_err("%s: invalid option\n", opts); |
1163 | return -EINVAL; | 1154 | return -EINVAL; |
1164 | } | 1155 | } |
1165 | 1156 | ||
@@ -1172,7 +1163,6 @@ invalid: | |||
1172 | return 0; | 1163 | return 0; |
1173 | } | 1164 | } |
1174 | 1165 | ||
1175 | |||
1176 | /* "mount -t functionfs dev_name /dev/function" ends up here */ | 1166 | /* "mount -t functionfs dev_name /dev/function" ends up here */ |
1177 | 1167 | ||
1178 | static struct dentry * | 1168 | static struct dentry * |
@@ -1224,10 +1214,8 @@ static struct file_system_type ffs_fs_type = { | |||
1224 | }; | 1214 | }; |
1225 | 1215 | ||
1226 | 1216 | ||
1227 | |||
1228 | /* Driver's main init/cleanup functions *************************************/ | 1217 | /* Driver's main init/cleanup functions *************************************/ |
1229 | 1218 | ||
1230 | |||
1231 | static int functionfs_init(void) | 1219 | static int functionfs_init(void) |
1232 | { | 1220 | { |
1233 | int ret; | 1221 | int ret; |
@@ -1236,9 +1224,9 @@ static int functionfs_init(void) | |||
1236 | 1224 | ||
1237 | ret = register_filesystem(&ffs_fs_type); | 1225 | ret = register_filesystem(&ffs_fs_type); |
1238 | if (likely(!ret)) | 1226 | if (likely(!ret)) |
1239 | FINFO("file system registered"); | 1227 | pr_info("file system registered\n"); |
1240 | else | 1228 | else |
1241 | FERR("failed registering file system (%d)", ret); | 1229 | pr_err("failed registering file system (%d)\n", ret); |
1242 | 1230 | ||
1243 | return ret; | 1231 | return ret; |
1244 | } | 1232 | } |
@@ -1247,18 +1235,16 @@ static void functionfs_cleanup(void) | |||
1247 | { | 1235 | { |
1248 | ENTER(); | 1236 | ENTER(); |
1249 | 1237 | ||
1250 | FINFO("unloading"); | 1238 | pr_info("unloading\n"); |
1251 | unregister_filesystem(&ffs_fs_type); | 1239 | unregister_filesystem(&ffs_fs_type); |
1252 | } | 1240 | } |
1253 | 1241 | ||
1254 | 1242 | ||
1255 | |||
1256 | /* ffs_data and ffs_function construction and destruction code **************/ | 1243 | /* ffs_data and ffs_function construction and destruction code **************/ |
1257 | 1244 | ||
1258 | static void ffs_data_clear(struct ffs_data *ffs); | 1245 | static void ffs_data_clear(struct ffs_data *ffs); |
1259 | static void ffs_data_reset(struct ffs_data *ffs); | 1246 | static void ffs_data_reset(struct ffs_data *ffs); |
1260 | 1247 | ||
1261 | |||
1262 | static void ffs_data_get(struct ffs_data *ffs) | 1248 | static void ffs_data_get(struct ffs_data *ffs) |
1263 | { | 1249 | { |
1264 | ENTER(); | 1250 | ENTER(); |
@@ -1279,7 +1265,7 @@ static void ffs_data_put(struct ffs_data *ffs) | |||
1279 | ENTER(); | 1265 | ENTER(); |
1280 | 1266 | ||
1281 | if (unlikely(atomic_dec_and_test(&ffs->ref))) { | 1267 | if (unlikely(atomic_dec_and_test(&ffs->ref))) { |
1282 | FINFO("%s(): freeing", __func__); | 1268 | pr_info("%s(): freeing\n", __func__); |
1283 | ffs_data_clear(ffs); | 1269 | ffs_data_clear(ffs); |
1284 | BUG_ON(mutex_is_locked(&ffs->mutex) || | 1270 | BUG_ON(mutex_is_locked(&ffs->mutex) || |
1285 | spin_is_locked(&ffs->ev.waitq.lock) || | 1271 | spin_is_locked(&ffs->ev.waitq.lock) || |
@@ -1289,8 +1275,6 @@ static void ffs_data_put(struct ffs_data *ffs) | |||
1289 | } | 1275 | } |
1290 | } | 1276 | } |
1291 | 1277 | ||
1292 | |||
1293 | |||
1294 | static void ffs_data_closed(struct ffs_data *ffs) | 1278 | static void ffs_data_closed(struct ffs_data *ffs) |
1295 | { | 1279 | { |
1296 | ENTER(); | 1280 | ENTER(); |
@@ -1303,7 +1287,6 @@ static void ffs_data_closed(struct ffs_data *ffs) | |||
1303 | ffs_data_put(ffs); | 1287 | ffs_data_put(ffs); |
1304 | } | 1288 | } |
1305 | 1289 | ||
1306 | |||
1307 | static struct ffs_data *ffs_data_new(void) | 1290 | static struct ffs_data *ffs_data_new(void) |
1308 | { | 1291 | { |
1309 | struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL); | 1292 | struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL); |
@@ -1326,7 +1309,6 @@ static struct ffs_data *ffs_data_new(void) | |||
1326 | return ffs; | 1309 | return ffs; |
1327 | } | 1310 | } |
1328 | 1311 | ||
1329 | |||
1330 | static void ffs_data_clear(struct ffs_data *ffs) | 1312 | static void ffs_data_clear(struct ffs_data *ffs) |
1331 | { | 1313 | { |
1332 | ENTER(); | 1314 | ENTER(); |
@@ -1344,7 +1326,6 @@ static void ffs_data_clear(struct ffs_data *ffs) | |||
1344 | kfree(ffs->stringtabs); | 1326 | kfree(ffs->stringtabs); |
1345 | } | 1327 | } |
1346 | 1328 | ||
1347 | |||
1348 | static void ffs_data_reset(struct ffs_data *ffs) | 1329 | static void ffs_data_reset(struct ffs_data *ffs) |
1349 | { | 1330 | { |
1350 | ENTER(); | 1331 | ENTER(); |
@@ -1407,7 +1388,6 @@ static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev) | |||
1407 | return 0; | 1388 | return 0; |
1408 | } | 1389 | } |
1409 | 1390 | ||
1410 | |||
1411 | static void functionfs_unbind(struct ffs_data *ffs) | 1391 | static void functionfs_unbind(struct ffs_data *ffs) |
1412 | { | 1392 | { |
1413 | ENTER(); | 1393 | ENTER(); |
@@ -1420,7 +1400,6 @@ static void functionfs_unbind(struct ffs_data *ffs) | |||
1420 | } | 1400 | } |
1421 | } | 1401 | } |
1422 | 1402 | ||
1423 | |||
1424 | static int ffs_epfiles_create(struct ffs_data *ffs) | 1403 | static int ffs_epfiles_create(struct ffs_data *ffs) |
1425 | { | 1404 | { |
1426 | struct ffs_epfile *epfile, *epfiles; | 1405 | struct ffs_epfile *epfile, *epfiles; |
@@ -1451,7 +1430,6 @@ static int ffs_epfiles_create(struct ffs_data *ffs) | |||
1451 | return 0; | 1430 | return 0; |
1452 | } | 1431 | } |
1453 | 1432 | ||
1454 | |||
1455 | static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count) | 1433 | static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count) |
1456 | { | 1434 | { |
1457 | struct ffs_epfile *epfile = epfiles; | 1435 | struct ffs_epfile *epfile = epfiles; |
@@ -1471,7 +1449,6 @@ static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count) | |||
1471 | kfree(epfiles); | 1449 | kfree(epfiles); |
1472 | } | 1450 | } |
1473 | 1451 | ||
1474 | |||
1475 | static int functionfs_bind_config(struct usb_composite_dev *cdev, | 1452 | static int functionfs_bind_config(struct usb_composite_dev *cdev, |
1476 | struct usb_configuration *c, | 1453 | struct usb_configuration *c, |
1477 | struct ffs_data *ffs) | 1454 | struct ffs_data *ffs) |
@@ -1491,7 +1468,6 @@ static int functionfs_bind_config(struct usb_composite_dev *cdev, | |||
1491 | func->function.bind = ffs_func_bind; | 1468 | func->function.bind = ffs_func_bind; |
1492 | func->function.unbind = ffs_func_unbind; | 1469 | func->function.unbind = ffs_func_unbind; |
1493 | func->function.set_alt = ffs_func_set_alt; | 1470 | func->function.set_alt = ffs_func_set_alt; |
1494 | /*func->function.get_alt = ffs_func_get_alt;*/ | ||
1495 | func->function.disable = ffs_func_disable; | 1471 | func->function.disable = ffs_func_disable; |
1496 | func->function.setup = ffs_func_setup; | 1472 | func->function.setup = ffs_func_setup; |
1497 | func->function.suspend = ffs_func_suspend; | 1473 | func->function.suspend = ffs_func_suspend; |
@@ -1516,14 +1492,15 @@ static void ffs_func_free(struct ffs_function *func) | |||
1516 | ffs_data_put(func->ffs); | 1492 | ffs_data_put(func->ffs); |
1517 | 1493 | ||
1518 | kfree(func->eps); | 1494 | kfree(func->eps); |
1519 | /* eps and interfaces_nums are allocated in the same chunk so | 1495 | /* |
1496 | * eps and interfaces_nums are allocated in the same chunk so | ||
1520 | * only one free is required. Descriptors are also allocated | 1497 | * only one free is required. Descriptors are also allocated |
1521 | * in the same chunk. */ | 1498 | * in the same chunk. |
1499 | */ | ||
1522 | 1500 | ||
1523 | kfree(func); | 1501 | kfree(func); |
1524 | } | 1502 | } |
1525 | 1503 | ||
1526 | |||
1527 | static void ffs_func_eps_disable(struct ffs_function *func) | 1504 | static void ffs_func_eps_disable(struct ffs_function *func) |
1528 | { | 1505 | { |
1529 | struct ffs_ep *ep = func->eps; | 1506 | struct ffs_ep *ep = func->eps; |
@@ -1581,11 +1558,12 @@ static int ffs_func_eps_enable(struct ffs_function *func) | |||
1581 | 1558 | ||
1582 | /* Parsing and building descriptors and strings *****************************/ | 1559 | /* Parsing and building descriptors and strings *****************************/ |
1583 | 1560 | ||
1584 | 1561 | /* | |
1585 | /* This validates if data pointed by data is a valid USB descriptor as | 1562 | * This validates if data pointed by data is a valid USB descriptor as |
1586 | * well as record how many interfaces, endpoints and strings are | 1563 | * well as record how many interfaces, endpoints and strings are |
1587 | * required by given configuration. Returns address afther the | 1564 | * required by given configuration. Returns address after the |
1588 | * descriptor or NULL if data is invalid. */ | 1565 | * descriptor or NULL if data is invalid. |
1566 | */ | ||
1589 | 1567 | ||
1590 | enum ffs_entity_type { | 1568 | enum ffs_entity_type { |
1591 | FFS_DESCRIPTOR, FFS_INTERFACE, FFS_STRING, FFS_ENDPOINT | 1569 | FFS_DESCRIPTOR, FFS_INTERFACE, FFS_STRING, FFS_ENDPOINT |
@@ -1607,14 +1585,14 @@ static int __must_check ffs_do_desc(char *data, unsigned len, | |||
1607 | 1585 | ||
1608 | /* At least two bytes are required: length and type */ | 1586 | /* At least two bytes are required: length and type */ |
1609 | if (len < 2) { | 1587 | if (len < 2) { |
1610 | FVDBG("descriptor too short"); | 1588 | pr_vdebug("descriptor too short\n"); |
1611 | return -EINVAL; | 1589 | return -EINVAL; |
1612 | } | 1590 | } |
1613 | 1591 | ||
1614 | /* If we have at least as many bytes as the descriptor takes? */ | 1592 | /* If we have at least as many bytes as the descriptor takes? */ |
1615 | length = _ds->bLength; | 1593 | length = _ds->bLength; |
1616 | if (len < length) { | 1594 | if (len < length) { |
1617 | FVDBG("descriptor longer then available data"); | 1595 | pr_vdebug("descriptor longer then available data\n"); |
1618 | return -EINVAL; | 1596 | return -EINVAL; |
1619 | } | 1597 | } |
1620 | 1598 | ||
@@ -1622,15 +1600,15 @@ static int __must_check ffs_do_desc(char *data, unsigned len, | |||
1622 | #define __entity_check_STRING(val) (val) | 1600 | #define __entity_check_STRING(val) (val) |
1623 | #define __entity_check_ENDPOINT(val) ((val) & USB_ENDPOINT_NUMBER_MASK) | 1601 | #define __entity_check_ENDPOINT(val) ((val) & USB_ENDPOINT_NUMBER_MASK) |
1624 | #define __entity(type, val) do { \ | 1602 | #define __entity(type, val) do { \ |
1625 | FVDBG("entity " #type "(%02x)", (val)); \ | 1603 | pr_vdebug("entity " #type "(%02x)\n", (val)); \ |
1626 | if (unlikely(!__entity_check_ ##type(val))) { \ | 1604 | if (unlikely(!__entity_check_ ##type(val))) { \ |
1627 | FVDBG("invalid entity's value"); \ | 1605 | pr_vdebug("invalid entity's value\n"); \ |
1628 | return -EINVAL; \ | 1606 | return -EINVAL; \ |
1629 | } \ | 1607 | } \ |
1630 | ret = entity(FFS_ ##type, &val, _ds, priv); \ | 1608 | ret = entity(FFS_ ##type, &val, _ds, priv); \ |
1631 | if (unlikely(ret < 0)) { \ | 1609 | if (unlikely(ret < 0)) { \ |
1632 | FDBG("entity " #type "(%02x); ret = %d", \ | 1610 | pr_debug("entity " #type "(%02x); ret = %d\n", \ |
1633 | (val), ret); \ | 1611 | (val), ret); \ |
1634 | return ret; \ | 1612 | return ret; \ |
1635 | } \ | 1613 | } \ |
1636 | } while (0) | 1614 | } while (0) |
@@ -1642,12 +1620,13 @@ static int __must_check ffs_do_desc(char *data, unsigned len, | |||
1642 | case USB_DT_STRING: | 1620 | case USB_DT_STRING: |
1643 | case USB_DT_DEVICE_QUALIFIER: | 1621 | case USB_DT_DEVICE_QUALIFIER: |
1644 | /* function can't have any of those */ | 1622 | /* function can't have any of those */ |
1645 | FVDBG("descriptor reserved for gadget: %d", _ds->bDescriptorType); | 1623 | pr_vdebug("descriptor reserved for gadget: %d\n", |
1624 | _ds->bDescriptorType); | ||
1646 | return -EINVAL; | 1625 | return -EINVAL; |
1647 | 1626 | ||
1648 | case USB_DT_INTERFACE: { | 1627 | case USB_DT_INTERFACE: { |
1649 | struct usb_interface_descriptor *ds = (void *)_ds; | 1628 | struct usb_interface_descriptor *ds = (void *)_ds; |
1650 | FVDBG("interface descriptor"); | 1629 | pr_vdebug("interface descriptor\n"); |
1651 | if (length != sizeof *ds) | 1630 | if (length != sizeof *ds) |
1652 | goto inv_length; | 1631 | goto inv_length; |
1653 | 1632 | ||
@@ -1659,7 +1638,7 @@ static int __must_check ffs_do_desc(char *data, unsigned len, | |||
1659 | 1638 | ||
1660 | case USB_DT_ENDPOINT: { | 1639 | case USB_DT_ENDPOINT: { |
1661 | struct usb_endpoint_descriptor *ds = (void *)_ds; | 1640 | struct usb_endpoint_descriptor *ds = (void *)_ds; |
1662 | FVDBG("endpoint descriptor"); | 1641 | pr_vdebug("endpoint descriptor\n"); |
1663 | if (length != USB_DT_ENDPOINT_SIZE && | 1642 | if (length != USB_DT_ENDPOINT_SIZE && |
1664 | length != USB_DT_ENDPOINT_AUDIO_SIZE) | 1643 | length != USB_DT_ENDPOINT_AUDIO_SIZE) |
1665 | goto inv_length; | 1644 | goto inv_length; |
@@ -1674,7 +1653,7 @@ static int __must_check ffs_do_desc(char *data, unsigned len, | |||
1674 | 1653 | ||
1675 | case USB_DT_INTERFACE_ASSOCIATION: { | 1654 | case USB_DT_INTERFACE_ASSOCIATION: { |
1676 | struct usb_interface_assoc_descriptor *ds = (void *)_ds; | 1655 | struct usb_interface_assoc_descriptor *ds = (void *)_ds; |
1677 | FVDBG("interface association descriptor"); | 1656 | pr_vdebug("interface association descriptor\n"); |
1678 | if (length != sizeof *ds) | 1657 | if (length != sizeof *ds) |
1679 | goto inv_length; | 1658 | goto inv_length; |
1680 | if (ds->iFunction) | 1659 | if (ds->iFunction) |
@@ -1688,17 +1667,17 @@ static int __must_check ffs_do_desc(char *data, unsigned len, | |||
1688 | case USB_DT_SECURITY: | 1667 | case USB_DT_SECURITY: |
1689 | case USB_DT_CS_RADIO_CONTROL: | 1668 | case USB_DT_CS_RADIO_CONTROL: |
1690 | /* TODO */ | 1669 | /* TODO */ |
1691 | FVDBG("unimplemented descriptor: %d", _ds->bDescriptorType); | 1670 | pr_vdebug("unimplemented descriptor: %d\n", _ds->bDescriptorType); |
1692 | return -EINVAL; | 1671 | return -EINVAL; |
1693 | 1672 | ||
1694 | default: | 1673 | default: |
1695 | /* We should never be here */ | 1674 | /* We should never be here */ |
1696 | FVDBG("unknown descriptor: %d", _ds->bDescriptorType); | 1675 | pr_vdebug("unknown descriptor: %d\n", _ds->bDescriptorType); |
1697 | return -EINVAL; | 1676 | return -EINVAL; |
1698 | 1677 | ||
1699 | inv_length: | 1678 | inv_length: |
1700 | FVDBG("invalid length: %d (descriptor %d)", | 1679 | pr_vdebug("invalid length: %d (descriptor %d)\n", |
1701 | _ds->bLength, _ds->bDescriptorType); | 1680 | _ds->bLength, _ds->bDescriptorType); |
1702 | return -EINVAL; | 1681 | return -EINVAL; |
1703 | } | 1682 | } |
1704 | 1683 | ||
@@ -1711,7 +1690,6 @@ static int __must_check ffs_do_desc(char *data, unsigned len, | |||
1711 | return length; | 1690 | return length; |
1712 | } | 1691 | } |
1713 | 1692 | ||
1714 | |||
1715 | static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len, | 1693 | static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len, |
1716 | ffs_entity_callback entity, void *priv) | 1694 | ffs_entity_callback entity, void *priv) |
1717 | { | 1695 | { |
@@ -1726,10 +1704,11 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len, | |||
1726 | if (num == count) | 1704 | if (num == count) |
1727 | data = NULL; | 1705 | data = NULL; |
1728 | 1706 | ||
1729 | /* Record "descriptor" entitny */ | 1707 | /* Record "descriptor" entity */ |
1730 | ret = entity(FFS_DESCRIPTOR, (u8 *)num, (void *)data, priv); | 1708 | ret = entity(FFS_DESCRIPTOR, (u8 *)num, (void *)data, priv); |
1731 | if (unlikely(ret < 0)) { | 1709 | if (unlikely(ret < 0)) { |
1732 | FDBG("entity DESCRIPTOR(%02lx); ret = %d", num, ret); | 1710 | pr_debug("entity DESCRIPTOR(%02lx); ret = %d\n", |
1711 | num, ret); | ||
1733 | return ret; | 1712 | return ret; |
1734 | } | 1713 | } |
1735 | 1714 | ||
@@ -1738,7 +1717,7 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len, | |||
1738 | 1717 | ||
1739 | ret = ffs_do_desc(data, len, entity, priv); | 1718 | ret = ffs_do_desc(data, len, entity, priv); |
1740 | if (unlikely(ret < 0)) { | 1719 | if (unlikely(ret < 0)) { |
1741 | FDBG("%s returns %d", __func__, ret); | 1720 | pr_debug("%s returns %d\n", __func__, ret); |
1742 | return ret; | 1721 | return ret; |
1743 | } | 1722 | } |
1744 | 1723 | ||
@@ -1748,7 +1727,6 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len, | |||
1748 | } | 1727 | } |
1749 | } | 1728 | } |
1750 | 1729 | ||
1751 | |||
1752 | static int __ffs_data_do_entity(enum ffs_entity_type type, | 1730 | static int __ffs_data_do_entity(enum ffs_entity_type type, |
1753 | u8 *valuep, struct usb_descriptor_header *desc, | 1731 | u8 *valuep, struct usb_descriptor_header *desc, |
1754 | void *priv) | 1732 | void *priv) |
@@ -1762,16 +1740,20 @@ static int __ffs_data_do_entity(enum ffs_entity_type type, | |||
1762 | break; | 1740 | break; |
1763 | 1741 | ||
1764 | case FFS_INTERFACE: | 1742 | case FFS_INTERFACE: |
1765 | /* Interfaces are indexed from zero so if we | 1743 | /* |
1744 | * Interfaces are indexed from zero so if we | ||
1766 | * encountered interface "n" then there are at least | 1745 | * encountered interface "n" then there are at least |
1767 | * "n+1" interfaces. */ | 1746 | * "n+1" interfaces. |
1747 | */ | ||
1768 | if (*valuep >= ffs->interfaces_count) | 1748 | if (*valuep >= ffs->interfaces_count) |
1769 | ffs->interfaces_count = *valuep + 1; | 1749 | ffs->interfaces_count = *valuep + 1; |
1770 | break; | 1750 | break; |
1771 | 1751 | ||
1772 | case FFS_STRING: | 1752 | case FFS_STRING: |
1773 | /* Strings are indexed from 1 (0 is magic ;) reserved | 1753 | /* |
1774 | * for languages list or some such) */ | 1754 | * Strings are indexed from 1 (0 is magic ;) reserved |
1755 | * for languages list or some such) | ||
1756 | */ | ||
1775 | if (*valuep > ffs->strings_count) | 1757 | if (*valuep > ffs->strings_count) |
1776 | ffs->strings_count = *valuep; | 1758 | ffs->strings_count = *valuep; |
1777 | break; | 1759 | break; |
@@ -1786,7 +1768,6 @@ static int __ffs_data_do_entity(enum ffs_entity_type type, | |||
1786 | return 0; | 1768 | return 0; |
1787 | } | 1769 | } |
1788 | 1770 | ||
1789 | |||
1790 | static int __ffs_data_got_descs(struct ffs_data *ffs, | 1771 | static int __ffs_data_got_descs(struct ffs_data *ffs, |
1791 | char *const _data, size_t len) | 1772 | char *const _data, size_t len) |
1792 | { | 1773 | { |
@@ -1849,8 +1830,6 @@ error: | |||
1849 | return ret; | 1830 | return ret; |
1850 | } | 1831 | } |
1851 | 1832 | ||
1852 | |||
1853 | |||
1854 | static int __ffs_data_got_strings(struct ffs_data *ffs, | 1833 | static int __ffs_data_got_strings(struct ffs_data *ffs, |
1855 | char *const _data, size_t len) | 1834 | char *const _data, size_t len) |
1856 | { | 1835 | { |
@@ -1876,17 +1855,17 @@ static int __ffs_data_got_strings(struct ffs_data *ffs, | |||
1876 | if (unlikely(str_count < needed_count)) | 1855 | if (unlikely(str_count < needed_count)) |
1877 | goto error; | 1856 | goto error; |
1878 | 1857 | ||
1879 | /* If we don't need any strings just return and free all | 1858 | /* |
1880 | * memory */ | 1859 | * If we don't need any strings just return and free all |
1860 | * memory. | ||
1861 | */ | ||
1881 | if (!needed_count) { | 1862 | if (!needed_count) { |
1882 | kfree(_data); | 1863 | kfree(_data); |
1883 | return 0; | 1864 | return 0; |
1884 | } | 1865 | } |
1885 | 1866 | ||
1886 | /* Allocate */ | 1867 | /* Allocate everything in one chunk so there's less maintenance. */ |
1887 | { | 1868 | { |
1888 | /* Allocate everything in one chunk so there's less | ||
1889 | * maintanance. */ | ||
1890 | struct { | 1869 | struct { |
1891 | struct usb_gadget_strings *stringtabs[lang_count + 1]; | 1870 | struct usb_gadget_strings *stringtabs[lang_count + 1]; |
1892 | struct usb_gadget_strings stringtab[lang_count]; | 1871 | struct usb_gadget_strings stringtab[lang_count]; |
@@ -1937,13 +1916,17 @@ static int __ffs_data_got_strings(struct ffs_data *ffs, | |||
1937 | if (unlikely(length == len)) | 1916 | if (unlikely(length == len)) |
1938 | goto error_free; | 1917 | goto error_free; |
1939 | 1918 | ||
1940 | /* user may provide more strings then we need, | 1919 | /* |
1941 | * if that's the case we simply ingore the | 1920 | * User may provide more strings then we need, |
1942 | * rest */ | 1921 | * if that's the case we simply ignore the |
1922 | * rest | ||
1923 | */ | ||
1943 | if (likely(needed)) { | 1924 | if (likely(needed)) { |
1944 | /* s->id will be set while adding | 1925 | /* |
1926 | * s->id will be set while adding | ||
1945 | * function to configuration so for | 1927 | * function to configuration so for |
1946 | * now just leave garbage here. */ | 1928 | * now just leave garbage here. |
1929 | */ | ||
1947 | s->s = data; | 1930 | s->s = data; |
1948 | --needed; | 1931 | --needed; |
1949 | ++s; | 1932 | ++s; |
@@ -1977,8 +1960,6 @@ error: | |||
1977 | } | 1960 | } |
1978 | 1961 | ||
1979 | 1962 | ||
1980 | |||
1981 | |||
1982 | /* Events handling and management *******************************************/ | 1963 | /* Events handling and management *******************************************/ |
1983 | 1964 | ||
1984 | static void __ffs_event_add(struct ffs_data *ffs, | 1965 | static void __ffs_event_add(struct ffs_data *ffs, |
@@ -1987,29 +1968,32 @@ static void __ffs_event_add(struct ffs_data *ffs, | |||
1987 | enum usb_functionfs_event_type rem_type1, rem_type2 = type; | 1968 | enum usb_functionfs_event_type rem_type1, rem_type2 = type; |
1988 | int neg = 0; | 1969 | int neg = 0; |
1989 | 1970 | ||
1990 | /* Abort any unhandled setup */ | 1971 | /* |
1991 | /* We do not need to worry about some cmpxchg() changing value | 1972 | * Abort any unhandled setup |
1973 | * | ||
1974 | * We do not need to worry about some cmpxchg() changing value | ||
1992 | * of ffs->setup_state without holding the lock because when | 1975 | * of ffs->setup_state without holding the lock because when |
1993 | * state is FFS_SETUP_PENDING cmpxchg() in several places in | 1976 | * state is FFS_SETUP_PENDING cmpxchg() in several places in |
1994 | * the source does nothing. */ | 1977 | * the source does nothing. |
1978 | */ | ||
1995 | if (ffs->setup_state == FFS_SETUP_PENDING) | 1979 | if (ffs->setup_state == FFS_SETUP_PENDING) |
1996 | ffs->setup_state = FFS_SETUP_CANCELED; | 1980 | ffs->setup_state = FFS_SETUP_CANCELED; |
1997 | 1981 | ||
1998 | switch (type) { | 1982 | switch (type) { |
1999 | case FUNCTIONFS_RESUME: | 1983 | case FUNCTIONFS_RESUME: |
2000 | rem_type2 = FUNCTIONFS_SUSPEND; | 1984 | rem_type2 = FUNCTIONFS_SUSPEND; |
2001 | /* FALL THGOUTH */ | 1985 | /* FALL THROUGH */ |
2002 | case FUNCTIONFS_SUSPEND: | 1986 | case FUNCTIONFS_SUSPEND: |
2003 | case FUNCTIONFS_SETUP: | 1987 | case FUNCTIONFS_SETUP: |
2004 | rem_type1 = type; | 1988 | rem_type1 = type; |
2005 | /* discard all similar events */ | 1989 | /* Discard all similar events */ |
2006 | break; | 1990 | break; |
2007 | 1991 | ||
2008 | case FUNCTIONFS_BIND: | 1992 | case FUNCTIONFS_BIND: |
2009 | case FUNCTIONFS_UNBIND: | 1993 | case FUNCTIONFS_UNBIND: |
2010 | case FUNCTIONFS_DISABLE: | 1994 | case FUNCTIONFS_DISABLE: |
2011 | case FUNCTIONFS_ENABLE: | 1995 | case FUNCTIONFS_ENABLE: |
2012 | /* discard everything other then power management. */ | 1996 | /* Discard everything other then power management. */ |
2013 | rem_type1 = FUNCTIONFS_SUSPEND; | 1997 | rem_type1 = FUNCTIONFS_SUSPEND; |
2014 | rem_type2 = FUNCTIONFS_RESUME; | 1998 | rem_type2 = FUNCTIONFS_RESUME; |
2015 | neg = 1; | 1999 | neg = 1; |
@@ -2026,11 +2010,11 @@ static void __ffs_event_add(struct ffs_data *ffs, | |||
2026 | if ((*ev == rem_type1 || *ev == rem_type2) == neg) | 2010 | if ((*ev == rem_type1 || *ev == rem_type2) == neg) |
2027 | *out++ = *ev; | 2011 | *out++ = *ev; |
2028 | else | 2012 | else |
2029 | FVDBG("purging event %d", *ev); | 2013 | pr_vdebug("purging event %d\n", *ev); |
2030 | ffs->ev.count = out - ffs->ev.types; | 2014 | ffs->ev.count = out - ffs->ev.types; |
2031 | } | 2015 | } |
2032 | 2016 | ||
2033 | FVDBG("adding event %d", type); | 2017 | pr_vdebug("adding event %d\n", type); |
2034 | ffs->ev.types[ffs->ev.count++] = type; | 2018 | ffs->ev.types[ffs->ev.count++] = type; |
2035 | wake_up_locked(&ffs->ev.waitq); | 2019 | wake_up_locked(&ffs->ev.waitq); |
2036 | } | 2020 | } |
@@ -2055,8 +2039,10 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep, | |||
2055 | struct ffs_function *func = priv; | 2039 | struct ffs_function *func = priv; |
2056 | struct ffs_ep *ffs_ep; | 2040 | struct ffs_ep *ffs_ep; |
2057 | 2041 | ||
2058 | /* If hs_descriptors is not NULL then we are reading hs | 2042 | /* |
2059 | * descriptors now */ | 2043 | * If hs_descriptors is not NULL then we are reading hs |
2044 | * descriptors now | ||
2045 | */ | ||
2060 | const int isHS = func->function.hs_descriptors != NULL; | 2046 | const int isHS = func->function.hs_descriptors != NULL; |
2061 | unsigned idx; | 2047 | unsigned idx; |
2062 | 2048 | ||
@@ -2075,9 +2061,9 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep, | |||
2075 | ffs_ep = func->eps + idx; | 2061 | ffs_ep = func->eps + idx; |
2076 | 2062 | ||
2077 | if (unlikely(ffs_ep->descs[isHS])) { | 2063 | if (unlikely(ffs_ep->descs[isHS])) { |
2078 | FVDBG("two %sspeed descriptors for EP %d", | 2064 | pr_vdebug("two %sspeed descriptors for EP %d\n", |
2079 | isHS ? "high" : "full", | 2065 | isHS ? "high" : "full", |
2080 | ds->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); | 2066 | ds->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); |
2081 | return -EINVAL; | 2067 | return -EINVAL; |
2082 | } | 2068 | } |
2083 | ffs_ep->descs[isHS] = ds; | 2069 | ffs_ep->descs[isHS] = ds; |
@@ -2091,11 +2077,11 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep, | |||
2091 | struct usb_request *req; | 2077 | struct usb_request *req; |
2092 | struct usb_ep *ep; | 2078 | struct usb_ep *ep; |
2093 | 2079 | ||
2094 | FVDBG("autoconfig"); | 2080 | pr_vdebug("autoconfig\n"); |
2095 | ep = usb_ep_autoconfig(func->gadget, ds); | 2081 | ep = usb_ep_autoconfig(func->gadget, ds); |
2096 | if (unlikely(!ep)) | 2082 | if (unlikely(!ep)) |
2097 | return -ENOTSUPP; | 2083 | return -ENOTSUPP; |
2098 | ep->driver_data = func->eps + idx;; | 2084 | ep->driver_data = func->eps + idx; |
2099 | 2085 | ||
2100 | req = usb_ep_alloc_request(ep, GFP_KERNEL); | 2086 | req = usb_ep_alloc_request(ep, GFP_KERNEL); |
2101 | if (unlikely(!req)) | 2087 | if (unlikely(!req)) |
@@ -2111,7 +2097,6 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep, | |||
2111 | return 0; | 2097 | return 0; |
2112 | } | 2098 | } |
2113 | 2099 | ||
2114 | |||
2115 | static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep, | 2100 | static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep, |
2116 | struct usb_descriptor_header *desc, | 2101 | struct usb_descriptor_header *desc, |
2117 | void *priv) | 2102 | void *priv) |
@@ -2143,8 +2128,10 @@ static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep, | |||
2143 | break; | 2128 | break; |
2144 | 2129 | ||
2145 | case FFS_ENDPOINT: | 2130 | case FFS_ENDPOINT: |
2146 | /* USB_DT_ENDPOINT are handled in | 2131 | /* |
2147 | * __ffs_func_bind_do_descs(). */ | 2132 | * USB_DT_ENDPOINT are handled in |
2133 | * __ffs_func_bind_do_descs(). | ||
2134 | */ | ||
2148 | if (desc->bDescriptorType == USB_DT_ENDPOINT) | 2135 | if (desc->bDescriptorType == USB_DT_ENDPOINT) |
2149 | return 0; | 2136 | return 0; |
2150 | 2137 | ||
@@ -2160,7 +2147,7 @@ static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep, | |||
2160 | break; | 2147 | break; |
2161 | } | 2148 | } |
2162 | 2149 | ||
2163 | FVDBG("%02x -> %02x", *valuep, newValue); | 2150 | pr_vdebug("%02x -> %02x\n", *valuep, newValue); |
2164 | *valuep = newValue; | 2151 | *valuep = newValue; |
2165 | return 0; | 2152 | return 0; |
2166 | } | 2153 | } |
@@ -2211,9 +2198,11 @@ static int ffs_func_bind(struct usb_configuration *c, | |||
2211 | func->eps = data->eps; | 2198 | func->eps = data->eps; |
2212 | func->interfaces_nums = data->inums; | 2199 | func->interfaces_nums = data->inums; |
2213 | 2200 | ||
2214 | /* Go throught all the endpoint descriptors and allocate | 2201 | /* |
2202 | * Go through all the endpoint descriptors and allocate | ||
2215 | * endpoints first, so that later we can rewrite the endpoint | 2203 | * endpoints first, so that later we can rewrite the endpoint |
2216 | * numbers without worying that it may be described later on. */ | 2204 | * numbers without worrying that it may be described later on. |
2205 | */ | ||
2217 | if (likely(full)) { | 2206 | if (likely(full)) { |
2218 | func->function.descriptors = data->fs_descs; | 2207 | func->function.descriptors = data->fs_descs; |
2219 | ret = ffs_do_descs(ffs->fs_descs_count, | 2208 | ret = ffs_do_descs(ffs->fs_descs_count, |
@@ -2234,9 +2223,11 @@ static int ffs_func_bind(struct usb_configuration *c, | |||
2234 | __ffs_func_bind_do_descs, func); | 2223 | __ffs_func_bind_do_descs, func); |
2235 | } | 2224 | } |
2236 | 2225 | ||
2237 | /* Now handle interface numbers allocation and interface and | 2226 | /* |
2238 | * enpoint numbers rewritting. We can do that in one go | 2227 | * Now handle interface numbers allocation and interface and |
2239 | * now. */ | 2228 | * endpoint numbers rewriting. We can do that in one go |
2229 | * now. | ||
2230 | */ | ||
2240 | ret = ffs_do_descs(ffs->fs_descs_count + | 2231 | ret = ffs_do_descs(ffs->fs_descs_count + |
2241 | (high ? ffs->hs_descs_count : 0), | 2232 | (high ? ffs->hs_descs_count : 0), |
2242 | data->raw_descs, sizeof data->raw_descs, | 2233 | data->raw_descs, sizeof data->raw_descs, |
@@ -2274,7 +2265,6 @@ static void ffs_func_unbind(struct usb_configuration *c, | |||
2274 | ffs_func_free(func); | 2265 | ffs_func_free(func); |
2275 | } | 2266 | } |
2276 | 2267 | ||
2277 | |||
2278 | static int ffs_func_set_alt(struct usb_function *f, | 2268 | static int ffs_func_set_alt(struct usb_function *f, |
2279 | unsigned interface, unsigned alt) | 2269 | unsigned interface, unsigned alt) |
2280 | { | 2270 | { |
@@ -2322,20 +2312,21 @@ static int ffs_func_setup(struct usb_function *f, | |||
2322 | 2312 | ||
2323 | ENTER(); | 2313 | ENTER(); |
2324 | 2314 | ||
2325 | FVDBG("creq->bRequestType = %02x", creq->bRequestType); | 2315 | pr_vdebug("creq->bRequestType = %02x\n", creq->bRequestType); |
2326 | FVDBG("creq->bRequest = %02x", creq->bRequest); | 2316 | pr_vdebug("creq->bRequest = %02x\n", creq->bRequest); |
2327 | FVDBG("creq->wValue = %04x", le16_to_cpu(creq->wValue)); | 2317 | pr_vdebug("creq->wValue = %04x\n", le16_to_cpu(creq->wValue)); |
2328 | FVDBG("creq->wIndex = %04x", le16_to_cpu(creq->wIndex)); | 2318 | pr_vdebug("creq->wIndex = %04x\n", le16_to_cpu(creq->wIndex)); |
2329 | FVDBG("creq->wLength = %04x", le16_to_cpu(creq->wLength)); | 2319 | pr_vdebug("creq->wLength = %04x\n", le16_to_cpu(creq->wLength)); |
2330 | 2320 | ||
2331 | /* Most requests directed to interface go throught here | 2321 | /* |
2322 | * Most requests directed to interface go through here | ||
2332 | * (notable exceptions are set/get interface) so we need to | 2323 | * (notable exceptions are set/get interface) so we need to |
2333 | * handle them. All other either handled by composite or | 2324 | * handle them. All other either handled by composite or |
2334 | * passed to usb_configuration->setup() (if one is set). No | 2325 | * passed to usb_configuration->setup() (if one is set). No |
2335 | * matter, we will handle requests directed to endpoint here | 2326 | * matter, we will handle requests directed to endpoint here |
2336 | * as well (as it's straightforward) but what to do with any | 2327 | * as well (as it's straightforward) but what to do with any |
2337 | * other request? */ | 2328 | * other request? |
2338 | 2329 | */ | |
2339 | if (ffs->state != FFS_ACTIVE) | 2330 | if (ffs->state != FFS_ACTIVE) |
2340 | return -ENODEV; | 2331 | return -ENODEV; |
2341 | 2332 | ||
@@ -2378,8 +2369,7 @@ static void ffs_func_resume(struct usb_function *f) | |||
2378 | } | 2369 | } |
2379 | 2370 | ||
2380 | 2371 | ||
2381 | 2372 | /* Endpoint and interface numbers reverse mapping ***************************/ | |
2382 | /* Enpoint and interface numbers reverse mapping ****************************/ | ||
2383 | 2373 | ||
2384 | static int ffs_func_revmap_ep(struct ffs_function *func, u8 num) | 2374 | static int ffs_func_revmap_ep(struct ffs_function *func, u8 num) |
2385 | { | 2375 | { |
@@ -2410,7 +2400,6 @@ static int ffs_mutex_lock(struct mutex *mutex, unsigned nonblock) | |||
2410 | : mutex_lock_interruptible(mutex); | 2400 | : mutex_lock_interruptible(mutex); |
2411 | } | 2401 | } |
2412 | 2402 | ||
2413 | |||
2414 | static char *ffs_prepare_buffer(const char * __user buf, size_t len) | 2403 | static char *ffs_prepare_buffer(const char * __user buf, size_t len) |
2415 | { | 2404 | { |
2416 | char *data; | 2405 | char *data; |
@@ -2427,7 +2416,7 @@ static char *ffs_prepare_buffer(const char * __user buf, size_t len) | |||
2427 | return ERR_PTR(-EFAULT); | 2416 | return ERR_PTR(-EFAULT); |
2428 | } | 2417 | } |
2429 | 2418 | ||
2430 | FVDBG("Buffer from user space:"); | 2419 | pr_vdebug("Buffer from user space:\n"); |
2431 | ffs_dump_mem("", data, len); | 2420 | ffs_dump_mem("", data, len); |
2432 | 2421 | ||
2433 | return data; | 2422 | return data; |