Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Kyungmin Park and committed by
Artem Bityutskiy
cadb40cc a0fd1efd

+18 -16
+6 -2
drivers/mtd/ubi/build.c
··· 530 530 ubi->min_io_size = ubi->mtd->writesize; 531 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 538 if (!is_power_of_2(ubi->min_io_size)) { 535 539 ubi_err("min. I/O unit (%d) is not power of 2", 536 540 ubi->min_io_size); ··· 585 581 if (ubi->vid_hdr_offset < UBI_EC_HDR_SIZE || 586 582 ubi->leb_start < ubi->vid_hdr_offset + UBI_VID_HDR_SIZE || 587 583 ubi->leb_start > ubi->peb_size - UBI_VID_HDR_SIZE || 588 - ubi->leb_start % ubi->min_io_size) { 584 + ubi->leb_start & (ubi->min_io_size - 1)) { 589 585 ubi_err("bad VID header (%d) or data offsets (%d)", 590 586 ubi->vid_hdr_offset, ubi->leb_start); 591 587 return -EINVAL;
+3 -3
drivers/mtd/ubi/cdev.c
··· 295 295 off = do_div(tmp, vol->usable_leb_size); 296 296 lnum = tmp; 297 297 298 - if (off % ubi->min_io_size) { 298 + if (off & (ubi->min_io_size - 1)) { 299 299 dbg_err("unaligned position"); 300 300 return -EINVAL; 301 301 } ··· 304 304 count_save = count = vol->used_bytes - *offp; 305 305 306 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 308 dbg_err("unaligned write length"); 309 309 return -EINVAL; 310 310 } ··· 564 564 if (req->alignment > ubi->leb_size) 565 565 goto bad; 566 566 567 - n = req->alignment % ubi->min_io_size; 567 + n = req->alignment & (ubi->min_io_size - 1); 568 568 if (req->alignment != 1 && n) 569 569 goto bad; 570 570
+1 -1
drivers/mtd/ubi/eba.c
··· 752 752 /* If this is the last LEB @len may be unaligned */ 753 753 len = ALIGN(data_size, ubi->min_io_size); 754 754 else 755 - ubi_assert(len % ubi->min_io_size == 0); 755 + ubi_assert(!(len & (ubi->min_io_size - 1))); 756 756 757 757 vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS); 758 758 if (!vid_hdr)
+3 -3
drivers/mtd/ubi/kapi.c
··· 397 397 return -EROFS; 398 398 399 399 if (lnum < 0 || lnum >= vol->reserved_pebs || offset < 0 || len < 0 || 400 - offset + len > vol->usable_leb_size || offset % ubi->min_io_size || 401 - len % ubi->min_io_size) 400 + offset + len > vol->usable_leb_size || 401 + offset & (ubi->min_io_size - 1) || len & (ubi->min_io_size - 1)) 402 402 return -EINVAL; 403 403 404 404 if (dtype != UBI_LONGTERM && dtype != UBI_SHORTTERM && ··· 447 447 return -EROFS; 448 448 449 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 451 return -EINVAL; 452 452 453 453 if (dtype != UBI_LONGTERM && dtype != UBI_SHORTTERM &&
+1 -1
drivers/mtd/ubi/misc.c
··· 37 37 { 38 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 42 for (i = length - 1; i >= 0; i--) 43 43 if (((const uint8_t *)buf)[i] != 0xFF)
+1 -1
drivers/mtd/ubi/vmt.c
··· 727 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 731 if (vol->alignment != 1 && n) { 732 732 ubi_err("alignment is not multiple of min I/O unit"); 733 733 goto fail;
+2 -3
drivers/mtd/ubi/vtbl.c
··· 170 170 goto bad; 171 171 } 172 172 173 - n = alignment % ubi->min_io_size; 173 + n = alignment & (ubi->min_io_size - 1); 174 174 if (alignment != 1 && n) { 175 175 err = 5; 176 176 goto bad; ··· 684 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 688 si->highest_vol_id < UBI_INTERNAL_VOL_START) { 689 689 ubi_err("too large volume ID %d found by scanning", 690 690 si->highest_vol_id); 691 691 return -EINVAL; 692 692 } 693 - 694 693 695 694 for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) { 696 695 cond_resched();
+1 -2
drivers/mtd/ubi/wl.c
··· 1368 1368 int err; 1369 1369 1370 1370 if (kthread_should_stop()) 1371 - goto out; 1371 + break; 1372 1372 1373 1373 if (try_to_freeze()) 1374 1374 continue; ··· 1403 1403 cond_resched(); 1404 1404 } 1405 1405 1406 - out: 1407 1406 dbg_wl("background thread \"%s\" is killed", ubi->bgt_name); 1408 1407 return 0; 1409 1408 }