summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2019-01-28 22:55:44 -0800
committerSascha Hauer <s.hauer@pengutronix.de>2019-02-06 08:30:58 +0100
commit684a457ea462707380b9ef6cc5659835f62122ab (patch)
tree416e67fddbfae6c905c1aaf1a26327d1a700d3a2 /fs
parentd7c2384940bbeff6529e42d81a7f314c69833654 (diff)
downloadbarebox-684a457ea462707380b9ef6cc5659835f62122ab.tar.gz
barebox-684a457ea462707380b9ef6cc5659835f62122ab.tar.xz
fs: Avoid division in memcpy_sz()
Instead of dividing count by rwsize, use ALIGN_DOWN() and change the loop to decrement by "rwsize" bytes. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'fs')
-rw-r--r--fs/devfs-core.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 522ef91752..d703c06a0d 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -521,9 +521,9 @@ static void memcpy_sz(void *dst, const void *src, size_t count, int rwsize)
rwsize = rwsize >> O_RWSIZE_SHIFT;
- count /= rwsize;
+ count = ALIGN_DOWN(count, rwsize);
- while (count-- > 0) {
+ while (count) {
switch (rwsize) {
case 1:
*((u8 *)dst) = *((u8 *)src);
@@ -540,6 +540,7 @@ static void memcpy_sz(void *dst, const void *src, size_t count, int rwsize)
}
dst += rwsize;
src += rwsize;
+ count -= rwsize;
}
}