[PATCH v2 14/19] fs: Avoid division in mem_copy()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 fs/devfs-core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 37c4bd0ad..8d5ff71d6 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -548,9 +548,9 @@ static ssize_t mem_copy(struct device_d *dev, void *dst, const void *src,
 
 	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);
@@ -567,6 +567,7 @@ static ssize_t mem_copy(struct device_d *dev, void *dst, const void *src,
 		}
 		dst += rwsize;
 		src += rwsize;
+		count -= rwsize;
 	}
 out:
 	return size;
-- 
2.20.1


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



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux