mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
To: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Cc: barebox@lists.infradead.org
Subject: [PATCH] fs: Fix memcpy_sz for remaining count/rwsize
Date: Thu,  8 Oct 2015 23:19:45 +0200	[thread overview]
Message-ID: <1444339185-17508-1-git-send-email-sebastian.hesselbarth@gmail.com> (raw)

When using memcpy_sz with rwsize != 1 integer division of
count/rwsize may leave some bytes of the request uncopied if
count is not a multiple of rwsize.

Fix this behavior by decrementing count by rwsize instead of
integer division and use plain memcpy for the remaining bytes.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
 fs/fs.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index c041e41bb51b..ccbda22d2692 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1580,9 +1580,7 @@ static void memcpy_sz(void *dst, const void *src, size_t count, int rwsize)
 
 	rwsize = rwsize >> O_RWSIZE_SHIFT;
 
-	count /= rwsize;
-
-	while (count-- > 0) {
+	while (count > 0) {
 		switch (rwsize) {
 		case 1:
 			*((u8 *)dst) = *((u8 *)src);
@@ -1599,7 +1597,12 @@ static void memcpy_sz(void *dst, const void *src, size_t count, int rwsize)
 		}
 		dst += rwsize;
 		src += rwsize;
+		count -= rwsize;
 	}
+
+	/* copy remaining bytes with plain memcpy */
+	if (count)
+		memcpy(dst, src, count);
 }
 
 ssize_t mem_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags)
-- 
2.1.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2015-10-08 21:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-08 21:19 Sebastian Hesselbarth [this message]
2015-10-12  6:11 ` Sascha Hauer
2015-10-12  7:36   ` Sebastian Hesselbarth
2015-10-12 18:51     ` Sebastian Hesselbarth
2015-10-13  8:00       ` Sascha Hauer
2015-10-13  8:09         ` Sebastian Hesselbarth

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=1444339185-17508-1-git-send-email-sebastian.hesselbarth@gmail.com \
    --to=sebastian.hesselbarth@gmail.com \
    --cc=barebox@lists.infradead.org \
    /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