mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chuansheng Liu <chuansheng.liu@intel.com>
To: balbi@ti.com, gregkh@linuxfoundation.org, mina86@mina86.com
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	david.a.cohen@intel.com, jin.can.zhuang@intel.com,
	yu.y.wang@intel.com, Chuansheng Liu <chuansheng.liu@intel.com>
Subject: [PATCH] usb: gadget: return the right length in ffs_epfile_io()
Date: Thu, 27 Feb 2014 14:49:31 +0800	[thread overview]
Message-ID: <1393483771-24623-1-git-send-email-chuansheng.liu@intel.com> (raw)
In-Reply-To: <n>

When the request length is aligned to maxpacketsize, sometimes
the return length ret > the user space requested len.

At that time, we will use min_t(size_t, ret, len) to limit the
size in case of user data buffer overflow.

But we need return the min_t(size_t, ret, len) to tell the user
space rightly also.

Signed-off-by: Chuansheng Liu <chuansheng.liu@intel.com>
---
 drivers/usb/gadget/f_fs.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index 2b43343..31ee7af 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -687,10 +687,12 @@ static ssize_t ffs_epfile_io(struct file *file,
 			 * space for.
 			 */
 			ret = ep->status;
-			if (read && ret > 0 &&
-			    unlikely(copy_to_user(buf, data,
-						  min_t(size_t, ret, len))))
-				ret = -EFAULT;
+			if (read && ret > 0) {
+				ret = min_t(size_t, ret, len);
+
+				if (unlikely(copy_to_user(buf, data, ret)))
+					ret = -EFAULT;
+			}
 		}
 	}
 
-- 
1.9.rc0


             reply	other threads:[~2014-02-27  6:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-27  6:49 Chuansheng Liu [this message]
2014-02-27 12:15 ` Michal Nazarewicz
2014-02-27 23:45   ` David Cohen
2014-03-03 16:30 ` Felipe Balbi
2014-03-04  7:47   ` Liu, Chuansheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1393483771-24623-1-git-send-email-chuansheng.liu@intel.com \
    --to=chuansheng.liu@intel.com \
    --cc=balbi@ti.com \
    --cc=david.a.cohen@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jin.can.zhuang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mina86@mina86.com \
    --cc=yu.y.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®