aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorKyungmin Park <kyungmin.park@samsung.com>2008-05-21 21:32:18 -0400
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2008-07-24 06:32:54 -0400
commitcadb40ccc16a26a738f1cbc963e35b21edd93e79 (patch)
treeacd1d5d02ecda07634f1c49432ddb39cd9f5d7fd /drivers
parenta0fd1efd488092951f310fdb777b8a540cf84dcb (diff)
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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mtd/ubi/build.c8
-rw-r--r--drivers/mtd/ubi/cdev.c6
-rw-r--r--drivers/mtd/ubi/eba.c2
-rw-r--r--drivers/mtd/ubi/kapi.c6
-rw-r--r--drivers/mtd/ubi/misc.c2
-rw-r--r--drivers/mtd/ubi/vmt.c2
-rw-r--r--drivers/mtd/ubi/vtbl.c5
-rw-r--r--drivers/mtd/ubi/wl.c3
8 files changed, 18 insertions, 16 deletions
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 961416ac0616..ff4425de1527 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -530,7 +530,11 @@ static int io_init(struct ubi_device *ubi)
530 ubi->min_io_size = ubi->mtd->writesize; 530 ubi->min_io_size = ubi->mtd->writesize;
531 ubi->hdrs_min_io_size = ubi->mtd->writesize >> ubi->mtd->subpage_sft; 531 ubi->hdrs_min_io_size = ubi->mtd->writesize >> ubi->mtd->subpage_sft;
532 532
533 /* Make sure minimal I/O unit is power of 2 */ 533 /*
534 * Make sure minimal I/O unit is power of 2. Note, there is no
535 * fundamental reason for this assumption. It is just an optimization
536 * which allows us to avoid costly division operations.
537 */
534 if (!is_power_of_2(ubi->min_io_size)) { 538 if (!is_power_of_2(ubi->min_io_size)) {
535 ubi_err("min. I/O unit (%d) is not power of 2", 539 ubi_err("min. I/O unit (%d) is not power of 2",
536 ubi->min_io_size); 540 ubi->min_io_size);
@@ -581,7 +585,7 @@ static int io_init(struct ubi_device *ubi)
581 if (ubi->vid_hdr_offset < UBI_EC_HDR_SIZE || 585 if (ubi->vid_hdr_offset < UBI_EC_HDR_SIZE ||
582 ubi->leb_start < ubi->vid_hdr_offset + UBI_VID_HDR_SIZE || 586 ubi->leb_start < ubi->vid_hdr_offset + UBI_VID_HDR_SIZE ||
583 ubi->leb_start > ubi->peb_size - UBI_VID_HDR_SIZE || 587 ubi->leb_start > ubi->peb_size - UBI_VID_HDR_SIZE ||
584 ubi->leb_start % ubi->min_io_size) { 588 ubi->leb_start & (ubi->min_io_size - 1)) {
585 ubi_err("bad VID header (%d) or data offsets (%d)", 589 ubi_err("bad VID header (%d) or data offsets (%d)",
586 ubi->vid_hdr_offset, ubi->leb_start); 590 ubi->vid_hdr_offset, ubi->leb_start);
587 return -EINVAL; 591 return -EINVAL;
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index 89193ba9451e..0cdaf9fba7b0 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -295,7 +295,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
295 off = do_div(tmp, vol->usable_leb_size); 295 off = do_div(tmp, vol->usable_leb_size);
296 lnum = tmp; 296 lnum = tmp;
297 297
298 if (off % ubi->min_io_size) { 298 if (off & (ubi->min_io_size - 1)) {
299 dbg_err("unaligned position"); 299 dbg_err("unaligned position");
300 return -EINVAL; 300 return -EINVAL;
301 } 301 }
@@ -304,7 +304,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
304 count_save = count = vol->used_bytes - *offp; 304 count_save = count = vol->used_bytes - *offp;
305 305
306 /* We can write only in fractions of the minimum I/O unit */ 306 /* We can write only in fractions of the minimum I/O unit */
307 if (count % ubi->min_io_size) { 307 if (count & (ubi->min_io_size - 1)) {
308 dbg_err("unaligned write length"); 308 dbg_err("unaligned write length");
309 return -EINVAL; 309 return -EINVAL;
310 } 310 }
@@ -564,7 +564,7 @@ static int verify_mkvol_req(const struct ubi_device *ubi,
564 if (req->alignment > ubi->leb_size) 564 if (req->alignment > ubi->leb_size)
565 goto bad; 565 goto bad;
566 566
567 n = req->alignment % ubi->min_io_size; 567 n = req->alignment & (ubi->min_io_size - 1);
568 if (req->alignment != 1 && n) 568 if (req->alignment != 1 && n)
569 goto bad; 569 goto bad;
570 570
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index 7ce91ca742b1..37d778447943 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -752,7 +752,7 @@ int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol,
752 /* If this is the last LEB @len may be unaligned */ 752 /* If this is the last LEB @len may be unaligned */
753 len = ALIGN(data_size, ubi->min_io_size); 753 len = ALIGN(data_size, ubi->min_io_size);
754 else 754 else
755 ubi_assert(len % ubi->min_io_size == 0); 755 ubi_assert(!(len & (ubi->min_io_size - 1)));
756 756
757 vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS); 757 vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS);
758 if (!vid_hdr) 758 if (!vid_hdr)
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index a70d58823f8d..51508832566d 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -397,8 +397,8 @@ int ubi_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf,
397 return -EROFS; 397 return -EROFS;
398 398
399 if (lnum < 0 || lnum >= vol->reserved_pebs || offset < 0 || len < 0 || 399 if (lnum < 0 || lnum >= vol->reserved_pebs || offset < 0 || len < 0 ||
400 offset + len > vol->usable_leb_size || offset % ubi->min_io_size || 400 offset + len > vol->usable_leb_size ||
401 len % ubi->min_io_size) 401 offset & (ubi->min_io_size - 1) || len & (ubi->min_io_size - 1))
402 return -EINVAL; 402 return -EINVAL;
403 403
404 if (dtype != UBI_LONGTERM && dtype != UBI_SHORTTERM && 404 if (dtype != UBI_LONGTERM && dtype != UBI_SHORTTERM &&
@@ -447,7 +447,7 @@ int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf,
447 return -EROFS; 447 return -EROFS;
448 448
449 if (lnum < 0 || lnum >= vol->reserved_pebs || len < 0 || 449 if (lnum < 0 || lnum >= vol->reserved_pebs || len < 0 ||
450 len > vol->usable_leb_size || len % ubi->min_io_size) 450 len > vol->usable_leb_size || len & (ubi->min_io_size - 1))
451 return -EINVAL; 451 return -EINVAL;
452 452
453 if (dtype != UBI_LONGTERM && dtype != UBI_SHORTTERM && 453 if (dtype != UBI_LONGTERM && dtype != UBI_SHORTTERM &&
diff --git a/drivers/mtd/ubi/misc.c b/drivers/mtd/ubi/misc.c
index 93e052812012..22ad31402945 100644
--- a/drivers/mtd/ubi/misc.c
+++ b/drivers/mtd/ubi/misc.c
@@ -37,7 +37,7 @@ int ubi_calc_data_len(const struct ubi_device *ubi, const void *buf,
37{ 37{
38 int i; 38 int i;
39 39
40 ubi_assert(length % ubi->min_io_size == 0); 40 ubi_assert(!(length & (ubi->min_io_size - 1)));
41 41
42 for (i = length - 1; i >= 0; i--) 42 for (i = length - 1; i >= 0; i--)
43 if (((const uint8_t *)buf)[i] != 0xFF) 43 if (((const uint8_t *)buf)[i] != 0xFF)
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index 5be58d85c639..7402025ded94 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -727,7 +727,7 @@ static void paranoid_check_volume(struct ubi_device *ubi, int vol_id)
727 goto fail; 727 goto fail;
728 } 728 }
729 729
730 n = vol->alignment % ubi->min_io_size; 730 n = vol->alignment & (ubi->min_io_size - 1);
731 if (vol->alignment != 1 && n) { 731 if (vol->alignment != 1 && n) {
732 ubi_err("alignment is not multiple of min I/O unit"); 732 ubi_err("alignment is not multiple of min I/O unit");
733 goto fail; 733 goto fail;
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index 42a7815086b7..d9af11a8682b 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -170,7 +170,7 @@ static int vtbl_check(const struct ubi_device *ubi,
170 goto bad; 170 goto bad;
171 } 171 }
172 172
173 n = alignment % ubi->min_io_size; 173 n = alignment & (ubi->min_io_size - 1);
174 if (alignment != 1 && n) { 174 if (alignment != 1 && n) {
175 err = 5; 175 err = 5;
176 goto bad; 176 goto bad;
@@ -684,14 +684,13 @@ static int check_scanning_info(const struct ubi_device *ubi,
684 return -EINVAL; 684 return -EINVAL;
685 } 685 }
686 686
687 if (si->highest_vol_id >= ubi->vtbl_slots + UBI_INT_VOL_COUNT&& 687 if (si->highest_vol_id >= ubi->vtbl_slots + UBI_INT_VOL_COUNT &&
688 si->highest_vol_id < UBI_INTERNAL_VOL_START) { 688 si->highest_vol_id < UBI_INTERNAL_VOL_START) {
689 ubi_err("too large volume ID %d found by scanning", 689 ubi_err("too large volume ID %d found by scanning",
690 si->highest_vol_id); 690 si->highest_vol_id);
691 return -EINVAL; 691 return -EINVAL;
692 } 692 }
693 693
694
695 for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) { 694 for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {
696 cond_resched(); 695 cond_resched();
697 696
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index a471a491f0ab..cc8fe2934d2b 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -1368,7 +1368,7 @@ int ubi_thread(void *u)
1368 int err; 1368 int err;
1369 1369
1370 if (kthread_should_stop()) 1370 if (kthread_should_stop())
1371 goto out; 1371 break;
1372 1372
1373 if (try_to_freeze()) 1373 if (try_to_freeze())
1374 continue; 1374 continue;
@@ -1403,7 +1403,6 @@ int ubi_thread(void *u)
1403 cond_resched(); 1403 cond_resched();
1404 } 1404 }
1405 1405
1406out:
1407 dbg_wl("background thread \"%s\" is killed", ubi->bgt_name); 1406 dbg_wl("background thread \"%s\" is killed", ubi->bgt_name);
1408 return 0; 1407 return 0;
1409} 1408}