UBI: avoid unnecessary division operations
UBI already checks that @min io size is the power of 2 at io_init. It is save to use bit operations then. Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
This commit is contained in:
committed by
Artem Bityutskiy
parent
a0fd1efd48
commit
cadb40ccc1
@@ -295,7 +295,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
|
||||
off = do_div(tmp, vol->usable_leb_size);
|
||||
lnum = tmp;
|
||||
|
||||
if (off % ubi->min_io_size) {
|
||||
if (off & (ubi->min_io_size - 1)) {
|
||||
dbg_err("unaligned position");
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -304,7 +304,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
|
||||
count_save = count = vol->used_bytes - *offp;
|
||||
|
||||
/* We can write only in fractions of the minimum I/O unit */
|
||||
if (count % ubi->min_io_size) {
|
||||
if (count & (ubi->min_io_size - 1)) {
|
||||
dbg_err("unaligned write length");
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -564,7 +564,7 @@ static int verify_mkvol_req(const struct ubi_device *ubi,
|
||||
if (req->alignment > ubi->leb_size)
|
||||
goto bad;
|
||||
|
||||
n = req->alignment % ubi->min_io_size;
|
||||
n = req->alignment & (ubi->min_io_size - 1);
|
||||
if (req->alignment != 1 && n)
|
||||
goto bad;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user