aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi/cdev.c
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2009-01-16 12:08:43 -0500
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2009-01-18 07:27:44 -0500
commit3013ee31b6c5fd9a49a81816d6c13e1cdb7a1288 (patch)
tree96cb10bb6576c4cbeb9843831a56c371174b29dc /drivers/mtd/ubi/cdev.c
parentf429b2ea8eadb5a576542a70f7fd6f5c2a7455e1 (diff)
UBI: use nicer 64-bit math
Get rid of 'do_div()' and use more user-friendly primitives from 'linux/math64.h'. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'drivers/mtd/ubi/cdev.c')
-rw-r--r--drivers/mtd/ubi/cdev.c20
1 files changed, 5 insertions, 15 deletions
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index 0a2d835fec80..f9631eb3fef3 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -41,8 +41,8 @@
41#include <linux/capability.h> 41#include <linux/capability.h>
42#include <linux/uaccess.h> 42#include <linux/uaccess.h>
43#include <linux/compat.h> 43#include <linux/compat.h>
44#include <linux/math64.h>
44#include <mtd/ubi-user.h> 45#include <mtd/ubi-user.h>
45#include <asm/div64.h>
46#include "ubi.h" 46#include "ubi.h"
47 47
48/** 48/**
@@ -195,7 +195,6 @@ static ssize_t vol_cdev_read(struct file *file, __user char *buf, size_t count,
195 int err, lnum, off, len, tbuf_size; 195 int err, lnum, off, len, tbuf_size;
196 size_t count_save = count; 196 size_t count_save = count;
197 void *tbuf; 197 void *tbuf;
198 uint64_t tmp;
199 198
200 dbg_gen("read %zd bytes from offset %lld of volume %d", 199 dbg_gen("read %zd bytes from offset %lld of volume %d",
201 count, *offp, vol->vol_id); 200 count, *offp, vol->vol_id);
@@ -225,10 +224,7 @@ static ssize_t vol_cdev_read(struct file *file, __user char *buf, size_t count,
225 return -ENOMEM; 224 return -ENOMEM;
226 225
227 len = count > tbuf_size ? tbuf_size : count; 226 len = count > tbuf_size ? tbuf_size : count;
228 227 lnum = div_u64_rem(*offp, vol->usable_leb_size, &off);
229 tmp = *offp;
230 off = do_div(tmp, vol->usable_leb_size);
231 lnum = tmp;
232 228
233 do { 229 do {
234 cond_resched(); 230 cond_resched();
@@ -279,7 +275,6 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
279 int lnum, off, len, tbuf_size, err = 0; 275 int lnum, off, len, tbuf_size, err = 0;
280 size_t count_save = count; 276 size_t count_save = count;
281 char *tbuf; 277 char *tbuf;
282 uint64_t tmp;
283 278
284 dbg_gen("requested: write %zd bytes to offset %lld of volume %u", 279 dbg_gen("requested: write %zd bytes to offset %lld of volume %u",
285 count, *offp, vol->vol_id); 280 count, *offp, vol->vol_id);
@@ -287,10 +282,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
287 if (vol->vol_type == UBI_STATIC_VOLUME) 282 if (vol->vol_type == UBI_STATIC_VOLUME)
288 return -EROFS; 283 return -EROFS;
289 284
290 tmp = *offp; 285 lnum = div_u64_rem(*offp, vol->usable_leb_size, &off);
291 off = do_div(tmp, vol->usable_leb_size);
292 lnum = tmp;
293
294 if (off & (ubi->min_io_size - 1)) { 286 if (off & (ubi->min_io_size - 1)) {
295 dbg_err("unaligned position"); 287 dbg_err("unaligned position");
296 return -EINVAL; 288 return -EINVAL;
@@ -882,7 +874,6 @@ static long ubi_cdev_ioctl(struct file *file, unsigned int cmd,
882 case UBI_IOCRSVOL: 874 case UBI_IOCRSVOL:
883 { 875 {
884 int pebs; 876 int pebs;
885 uint64_t tmp;
886 struct ubi_rsvol_req req; 877 struct ubi_rsvol_req req;
887 878
888 dbg_gen("re-size volume"); 879 dbg_gen("re-size volume");
@@ -902,9 +893,8 @@ static long ubi_cdev_ioctl(struct file *file, unsigned int cmd,
902 break; 893 break;
903 } 894 }
904 895
905 tmp = req.bytes; 896 pebs = div_u64(req.bytes + desc->vol->usable_leb_size - 1,
906 pebs = !!do_div(tmp, desc->vol->usable_leb_size); 897 desc->vol->usable_leb_size);
907 pebs += tmp;
908 898
909 mutex_lock(&ubi->volumes_mutex); 899 mutex_lock(&ubi->volumes_mutex);
910 err = ubi_resize_volume(desc, pebs); 900 err = ubi_resize_volume(desc, pebs);