aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/file_storage.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget/file_storage.c')
-rw-r--r--drivers/usb/gadget/file_storage.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index c6f96a2b3110..4b9797d07a67 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -460,7 +460,6 @@ struct fsg_dev {
460 460
461 struct fsg_buffhd *next_buffhd_to_fill; 461 struct fsg_buffhd *next_buffhd_to_fill;
462 struct fsg_buffhd *next_buffhd_to_drain; 462 struct fsg_buffhd *next_buffhd_to_drain;
463 struct fsg_buffhd buffhds[FSG_NUM_BUFFERS];
464 463
465 int thread_wakeup_needed; 464 int thread_wakeup_needed;
466 struct completion thread_notifier; 465 struct completion thread_notifier;
@@ -487,6 +486,8 @@ struct fsg_dev {
487 unsigned int nluns; 486 unsigned int nluns;
488 struct fsg_lun *luns; 487 struct fsg_lun *luns;
489 struct fsg_lun *curlun; 488 struct fsg_lun *curlun;
489 /* Must be the last entry */
490 struct fsg_buffhd buffhds[];
490}; 491};
491 492
492typedef void (*fsg_routine_t)(struct fsg_dev *); 493typedef void (*fsg_routine_t)(struct fsg_dev *);
@@ -2737,7 +2738,7 @@ static int do_set_interface(struct fsg_dev *fsg, int altsetting)
2737 2738
2738reset: 2739reset:
2739 /* Deallocate the requests */ 2740 /* Deallocate the requests */
2740 for (i = 0; i < FSG_NUM_BUFFERS; ++i) { 2741 for (i = 0; i < fsg_num_buffers; ++i) {
2741 struct fsg_buffhd *bh = &fsg->buffhds[i]; 2742 struct fsg_buffhd *bh = &fsg->buffhds[i];
2742 2743
2743 if (bh->inreq) { 2744 if (bh->inreq) {
@@ -2798,7 +2799,7 @@ reset:
2798 } 2799 }
2799 2800
2800 /* Allocate the requests */ 2801 /* Allocate the requests */
2801 for (i = 0; i < FSG_NUM_BUFFERS; ++i) { 2802 for (i = 0; i < fsg_num_buffers; ++i) {
2802 struct fsg_buffhd *bh = &fsg->buffhds[i]; 2803 struct fsg_buffhd *bh = &fsg->buffhds[i];
2803 2804
2804 if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0) 2805 if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0)
@@ -2894,7 +2895,7 @@ static void handle_exception(struct fsg_dev *fsg)
2894 /* Cancel all the pending transfers */ 2895 /* Cancel all the pending transfers */
2895 if (fsg->intreq_busy) 2896 if (fsg->intreq_busy)
2896 usb_ep_dequeue(fsg->intr_in, fsg->intreq); 2897 usb_ep_dequeue(fsg->intr_in, fsg->intreq);
2897 for (i = 0; i < FSG_NUM_BUFFERS; ++i) { 2898 for (i = 0; i < fsg_num_buffers; ++i) {
2898 bh = &fsg->buffhds[i]; 2899 bh = &fsg->buffhds[i];
2899 if (bh->inreq_busy) 2900 if (bh->inreq_busy)
2900 usb_ep_dequeue(fsg->bulk_in, bh->inreq); 2901 usb_ep_dequeue(fsg->bulk_in, bh->inreq);
@@ -2905,7 +2906,7 @@ static void handle_exception(struct fsg_dev *fsg)
2905 /* Wait until everything is idle */ 2906 /* Wait until everything is idle */
2906 for (;;) { 2907 for (;;) {
2907 num_active = fsg->intreq_busy; 2908 num_active = fsg->intreq_busy;
2908 for (i = 0; i < FSG_NUM_BUFFERS; ++i) { 2909 for (i = 0; i < fsg_num_buffers; ++i) {
2909 bh = &fsg->buffhds[i]; 2910 bh = &fsg->buffhds[i];
2910 num_active += bh->inreq_busy + bh->outreq_busy; 2911 num_active += bh->inreq_busy + bh->outreq_busy;
2911 } 2912 }
@@ -2927,7 +2928,7 @@ static void handle_exception(struct fsg_dev *fsg)
2927 * state, and the exception. Then invoke the handler. */ 2928 * state, and the exception. Then invoke the handler. */
2928 spin_lock_irq(&fsg->lock); 2929 spin_lock_irq(&fsg->lock);
2929 2930
2930 for (i = 0; i < FSG_NUM_BUFFERS; ++i) { 2931 for (i = 0; i < fsg_num_buffers; ++i) {
2931 bh = &fsg->buffhds[i]; 2932 bh = &fsg->buffhds[i];
2932 bh->state = BUF_STATE_EMPTY; 2933 bh->state = BUF_STATE_EMPTY;
2933 } 2934 }
@@ -3157,7 +3158,7 @@ static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
3157 } 3158 }
3158 3159
3159 /* Free the data buffers */ 3160 /* Free the data buffers */
3160 for (i = 0; i < FSG_NUM_BUFFERS; ++i) 3161 for (i = 0; i < fsg_num_buffers; ++i)
3161 kfree(fsg->buffhds[i].buf); 3162 kfree(fsg->buffhds[i].buf);
3162 3163
3163 /* Free the request and buffer for endpoint 0 */ 3164 /* Free the request and buffer for endpoint 0 */
@@ -3445,7 +3446,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3445 req->complete = ep0_complete; 3446 req->complete = ep0_complete;
3446 3447
3447 /* Allocate the data buffers */ 3448 /* Allocate the data buffers */
3448 for (i = 0; i < FSG_NUM_BUFFERS; ++i) { 3449 for (i = 0; i < fsg_num_buffers; ++i) {
3449 struct fsg_buffhd *bh = &fsg->buffhds[i]; 3450 struct fsg_buffhd *bh = &fsg->buffhds[i];
3450 3451
3451 /* Allocate for the bulk-in endpoint. We assume that 3452 /* Allocate for the bulk-in endpoint. We assume that
@@ -3456,7 +3457,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3456 goto out; 3457 goto out;
3457 bh->next = bh + 1; 3458 bh->next = bh + 1;
3458 } 3459 }
3459 fsg->buffhds[FSG_NUM_BUFFERS - 1].next = &fsg->buffhds[0]; 3460 fsg->buffhds[fsg_num_buffers - 1].next = &fsg->buffhds[0];
3460 3461
3461 /* This should reflect the actual gadget power source */ 3462 /* This should reflect the actual gadget power source */
3462 usb_gadget_set_selfpowered(gadget); 3463 usb_gadget_set_selfpowered(gadget);
@@ -3572,7 +3573,9 @@ static int __init fsg_alloc(void)
3572{ 3573{
3573 struct fsg_dev *fsg; 3574 struct fsg_dev *fsg;
3574 3575
3575 fsg = kzalloc(sizeof *fsg, GFP_KERNEL); 3576 fsg = kzalloc(sizeof *fsg +
3577 fsg_num_buffers * sizeof *(fsg->buffhds), GFP_KERNEL);
3578
3576 if (!fsg) 3579 if (!fsg)
3577 return -ENOMEM; 3580 return -ENOMEM;
3578 spin_lock_init(&fsg->lock); 3581 spin_lock_init(&fsg->lock);
@@ -3590,6 +3593,10 @@ static int __init fsg_init(void)
3590 int rc; 3593 int rc;
3591 struct fsg_dev *fsg; 3594 struct fsg_dev *fsg;
3592 3595
3596 rc = fsg_num_buffers_validate();
3597 if (rc != 0)
3598 return rc;
3599
3593 if ((rc = fsg_alloc()) != 0) 3600 if ((rc = fsg_alloc()) != 0)
3594 return rc; 3601 return rc;
3595 fsg = the_fsg; 3602 fsg = the_fsg;