aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorDavid Cohen <david.a.cohen@linux.intel.com>2014-10-13 14:15:54 -0400
committerFelipe Balbi <balbi@ti.com>2014-10-23 10:55:42 -0400
commitc0d31b3c3d9a025b8d5a57c35671e60c5f388bf7 (patch)
tree523ffce944d21868f551f1a03771222f3d971cad /drivers/usb
parenta3058a5d82e296daaca07411c3738a9ddd79f302 (diff)
usb: ffs: fix regression when quirk_ep_out_aligned_size flag is set
The commit '2e4c7553cd usb: gadget: f_fs: add aio support' broke the quirk implemented to align buffer size to maxpacketsize on out endpoint. As result, functionfs does not work on Intel platforms using dwc3 driver (i.e. Bay Trail and Merrifield). This patch fixes the issue. This code is based on a previous Qiuxu's patch. Fixes: 2e4c7553cd (usb: gadget: f_fs: add aio support) Cc: <stable@vger.kernel.org> # v3.16+ Signed-off-by: David Cohen <david.a.cohen@linux.intel.com> Signed-off-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com> Acked-by: Michal Nazarewicz <mina86@mina86.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/gadget/function/f_fs.c40
1 files changed, 34 insertions, 6 deletions
diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index 12dbdafd78a8..63314ede7ba6 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -647,15 +647,26 @@ static void ffs_user_copy_worker(struct work_struct *work)
647 if (io_data->read && ret > 0) { 647 if (io_data->read && ret > 0) {
648 int i; 648 int i;
649 size_t pos = 0; 649 size_t pos = 0;
650
651 /*
652 * Since req->length may be bigger than io_data->len (after
653 * being rounded up to maxpacketsize), we may end up with more
654 * data then user space has space for.
655 */
656 ret = min_t(int, ret, io_data->len);
657
650 use_mm(io_data->mm); 658 use_mm(io_data->mm);
651 for (i = 0; i < io_data->nr_segs; i++) { 659 for (i = 0; i < io_data->nr_segs; i++) {
660 size_t len = min_t(size_t, ret - pos,
661 io_data->iovec[i].iov_len);
662 if (!len)
663 break;
652 if (unlikely(copy_to_user(io_data->iovec[i].iov_base, 664 if (unlikely(copy_to_user(io_data->iovec[i].iov_base,
653 &io_data->buf[pos], 665 &io_data->buf[pos], len))) {
654 io_data->iovec[i].iov_len))) {
655 ret = -EFAULT; 666 ret = -EFAULT;
656 break; 667 break;
657 } 668 }
658 pos += io_data->iovec[i].iov_len; 669 pos += len;
659 } 670 }
660 unuse_mm(io_data->mm); 671 unuse_mm(io_data->mm);
661 } 672 }
@@ -687,7 +698,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
687 struct ffs_epfile *epfile = file->private_data; 698 struct ffs_epfile *epfile = file->private_data;
688 struct ffs_ep *ep; 699 struct ffs_ep *ep;
689 char *data = NULL; 700 char *data = NULL;
690 ssize_t ret, data_len; 701 ssize_t ret, data_len = -EINVAL;
691 int halt; 702 int halt;
692 703
693 /* Are we still active? */ 704 /* Are we still active? */
@@ -787,13 +798,30 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
787 /* Fire the request */ 798 /* Fire the request */
788 struct usb_request *req; 799 struct usb_request *req;
789 800
801 /*
802 * Sanity Check: even though data_len can't be used
803 * uninitialized at the time I write this comment, some
804 * compilers complain about this situation.
805 * In order to keep the code clean from warnings, data_len is
806 * being initialized to -EINVAL during its declaration, which
807 * means we can't rely on compiler anymore to warn no future
808 * changes won't result in data_len being used uninitialized.
809 * For such reason, we're adding this redundant sanity check
810 * here.
811 */
812 if (unlikely(data_len == -EINVAL)) {
813 WARN(1, "%s: data_len == -EINVAL\n", __func__);
814 ret = -EINVAL;
815 goto error_lock;
816 }
817
790 if (io_data->aio) { 818 if (io_data->aio) {
791 req = usb_ep_alloc_request(ep->ep, GFP_KERNEL); 819 req = usb_ep_alloc_request(ep->ep, GFP_KERNEL);
792 if (unlikely(!req)) 820 if (unlikely(!req))
793 goto error_lock; 821 goto error_lock;
794 822
795 req->buf = data; 823 req->buf = data;
796 req->length = io_data->len; 824 req->length = data_len;
797 825
798 io_data->buf = data; 826 io_data->buf = data;
799 io_data->ep = ep->ep; 827 io_data->ep = ep->ep;
@@ -815,7 +843,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
815 843
816 req = ep->req; 844 req = ep->req;
817 req->buf = data; 845 req->buf = data;
818 req->length = io_data->len; 846 req->length = data_len;
819 847
820 req->context = &done; 848 req->context = &done;
821 req->complete = ffs_epfile_io_complete; 849 req->complete = ffs_epfile_io_complete;