From patchwork Fri Oct 17 17:10:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 38912 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C631C202DB for ; Fri, 17 Oct 2014 17:10:48 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id gq15sf715406lab.3 for ; Fri, 17 Oct 2014 10:10:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=V7x9ztFwrzS3RNSEnJov+4S9dgKMmVr0jdsPz+WUyAU=; b=WI5MXg8rDoZtx0/Ck3AwLAQYpXiCB5vIBVBhVoIDjzwKHI0A/t/hqXoIgNsfRt7MZ3 DM76/zZ5JEf+YmsZ+2S2ziDJa1/n3qeX5tLbLL6lv9BwSru+0EEAoCof5uIPCIYF3Euc s8BTUlHi2i6OPqWdNwd5JoUd+Xe2zol6VQ+LGUCMLUCEFGNiZfk5vkhrE7/adJkV1v9q Oh792EONOaMQ3AE27sm2KULPligXYwRL7Qx6NRqvGzLSUqZiDzE+C1oa+asbY8852/C+ 0SWdaG+gvqW0UMphBxwGqg2iZt3URE0iFBMcauVUBkLLqujmpvUJWzudyYxpLSpgN0e8 j4CQ== X-Gm-Message-State: ALoCoQn0rvrB7AweN/CyTzWyg/6ry0z06hwSMXDE6DuhmGCOYV7WSmL26Z6G3qQ8AiWy0U24NyD3 X-Received: by 10.152.28.4 with SMTP id x4mr33160lag.7.1413565847575; Fri, 17 Oct 2014 10:10:47 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.4.7 with SMTP id g7ls280029lag.43.gmail; Fri, 17 Oct 2014 10:10:47 -0700 (PDT) X-Received: by 10.112.151.42 with SMTP id un10mr10064195lbb.21.1413565847112; Fri, 17 Oct 2014 10:10:47 -0700 (PDT) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id ks12si3021344lac.5.2014.10.17.10.10.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 17 Oct 2014 10:10:47 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by mail-la0-f51.google.com with SMTP id ge10so1049137lab.24 for ; Fri, 17 Oct 2014 10:10:47 -0700 (PDT) X-Received: by 10.152.29.8 with SMTP id f8mr10244929lah.56.1413565847025; Fri, 17 Oct 2014 10:10:47 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp266755lbz; Fri, 17 Oct 2014 10:10:46 -0700 (PDT) X-Received: by 10.66.182.200 with SMTP id eg8mr9838778pac.53.1413565845261; Fri, 17 Oct 2014 10:10:45 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id wq7si1512337pbc.257.2014.10.17.10.10.44 for ; Fri, 17 Oct 2014 10:10:45 -0700 (PDT) Received-SPF: none (google.com: linux-usb-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753572AbaJQRKm (ORCPT + 3 others); Fri, 17 Oct 2014 13:10:42 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:36010 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753562AbaJQRKk (ORCPT ); Fri, 17 Oct 2014 13:10:40 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id s9HHAdBB024917; Fri, 17 Oct 2014 12:10:39 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s9HHAdOV023258; Fri, 17 Oct 2014 12:10:39 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.174.1; Fri, 17 Oct 2014 12:10:39 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s9HHAcIQ022900; Fri, 17 Oct 2014 12:10:39 -0500 From: Felipe Balbi To: Linux USB Mailing List CC: David Cohen , , Qiuxu Zhuo , Felipe Balbi Subject: [PATCH 24/28] usb: ffs: fix regression when quirk_ep_out_aligned_size flag is set Date: Fri, 17 Oct 2014 12:10:00 -0500 Message-ID: <1413565804-13061-25-git-send-email-balbi@ti.com> X-Mailer: git-send-email 2.1.0.GIT In-Reply-To: <1413565804-13061-1-git-send-email-balbi@ti.com> References: <1413565804-13061-1-git-send-email-balbi@ti.com> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: balbi@ti.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: David Cohen 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: # v3.16+ Signed-off-by: David Cohen Signed-off-by: Qiuxu Zhuo Acked-by: Michal Nazarewicz Signed-off-by: Felipe Balbi --- drivers/usb/gadget/function/f_fs.c | 40 ++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index 12dbdaf..63314ed 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) if (io_data->read && ret > 0) { int i; size_t pos = 0; + + /* + * Since req->length may be bigger than io_data->len (after + * being rounded up to maxpacketsize), we may end up with more + * data then user space has space for. + */ + ret = min_t(int, ret, io_data->len); + use_mm(io_data->mm); for (i = 0; i < io_data->nr_segs; i++) { + size_t len = min_t(size_t, ret - pos, + io_data->iovec[i].iov_len); + if (!len) + break; if (unlikely(copy_to_user(io_data->iovec[i].iov_base, - &io_data->buf[pos], - io_data->iovec[i].iov_len))) { + &io_data->buf[pos], len))) { ret = -EFAULT; break; } - pos += io_data->iovec[i].iov_len; + pos += len; } unuse_mm(io_data->mm); } @@ -687,7 +698,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data) struct ffs_epfile *epfile = file->private_data; struct ffs_ep *ep; char *data = NULL; - ssize_t ret, data_len; + ssize_t ret, data_len = -EINVAL; int halt; /* Are we still active? */ @@ -787,13 +798,30 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data) /* Fire the request */ struct usb_request *req; + /* + * Sanity Check: even though data_len can't be used + * uninitialized at the time I write this comment, some + * compilers complain about this situation. + * In order to keep the code clean from warnings, data_len is + * being initialized to -EINVAL during its declaration, which + * means we can't rely on compiler anymore to warn no future + * changes won't result in data_len being used uninitialized. + * For such reason, we're adding this redundant sanity check + * here. + */ + if (unlikely(data_len == -EINVAL)) { + WARN(1, "%s: data_len == -EINVAL\n", __func__); + ret = -EINVAL; + goto error_lock; + } + if (io_data->aio) { req = usb_ep_alloc_request(ep->ep, GFP_KERNEL); if (unlikely(!req)) goto error_lock; req->buf = data; - req->length = io_data->len; + req->length = data_len; io_data->buf = data; io_data->ep = ep->ep; @@ -815,7 +843,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data) req = ep->req; req->buf = data; - req->length = io_data->len; + req->length = data_len; req->context = &done; req->complete = ffs_epfile_io_complete;