diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2015-04-17 09:04:38 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-04-17 09:04:38 -0400 |
commit | 54e514b91b95d6441c12a7955addfb9f9d2afc65 (patch) | |
tree | 8b73d901bd2a6ec5a31f34a8954e5ea92216dd6c /lib/find_last_bit.c | |
parent | 4fc8adcfec3da639da76e8314c9ccefe5bf9a045 (diff) | |
parent | 6c8c90319c0bb1c9e0b68e721359b89ae4f28465 (diff) |
Merge branch 'akpm' (patches from Andrew)
Merge third patchbomb from Andrew Morton:
- various misc things
- a couple of lib/ optimisations
- provide DIV_ROUND_CLOSEST_ULL()
- checkpatch updates
- rtc tree
- befs, nilfs2, hfs, hfsplus, fatfs, adfs, affs, bfs
- ptrace fixes
- fork() fixes
- seccomp cleanups
- more mmap_sem hold time reductions from Davidlohr
* emailed patches from Andrew Morton <akpm@linux-foundation.org>: (138 commits)
proc: show locks in /proc/pid/fdinfo/X
docs: add missing and new /proc/PID/status file entries, fix typos
drivers/rtc/rtc-at91rm9200.c: make IO endian agnostic
Documentation/spi/spidev_test.c: fix warning
drivers/rtc/rtc-s5m.c: allow usage on device type different than main MFD type
.gitignore: ignore *.tar
MAINTAINERS: add Mediatek SoC mailing list
tomoyo: reduce mmap_sem hold for mm->exe_file
powerpc/oprofile: reduce mmap_sem hold for exe_file
oprofile: reduce mmap_sem hold for mm->exe_file
mips: ip32: add platform data hooks to use DS1685 driver
lib/Kconfig: fix up HAVE_ARCH_BITREVERSE help text
x86: switch to using asm-generic for seccomp.h
sparc: switch to using asm-generic for seccomp.h
powerpc: switch to using asm-generic for seccomp.h
parisc: switch to using asm-generic for seccomp.h
mips: switch to using asm-generic for seccomp.h
microblaze: use asm-generic for seccomp.h
arm: use asm-generic for seccomp.h
seccomp: allow COMPAT sigreturn overrides
...
Diffstat (limited to 'lib/find_last_bit.c')
-rw-r--r-- | lib/find_last_bit.c | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/lib/find_last_bit.c b/lib/find_last_bit.c index 91ca09fbf6f9..3e3be40c6a6e 100644 --- a/lib/find_last_bit.c +++ b/lib/find_last_bit.c | |||
@@ -4,6 +4,9 @@ | |||
4 | * Written by Rusty Russell <rusty@rustcorp.com.au> | 4 | * Written by Rusty Russell <rusty@rustcorp.com.au> |
5 | * (Inspired by David Howell's find_next_bit implementation) | 5 | * (Inspired by David Howell's find_next_bit implementation) |
6 | * | 6 | * |
7 | * Rewritten by Yury Norov <yury.norov@gmail.com> to decrease | ||
8 | * size and improve performance, 2015. | ||
9 | * | ||
7 | * This program is free software; you can redistribute it and/or | 10 | * This program is free software; you can redistribute it and/or |
8 | * modify it under the terms of the GNU General Public License | 11 | * modify it under the terms of the GNU General Public License |
9 | * as published by the Free Software Foundation; either version | 12 | * as published by the Free Software Foundation; either version |
@@ -11,37 +14,26 @@ | |||
11 | */ | 14 | */ |
12 | 15 | ||
13 | #include <linux/bitops.h> | 16 | #include <linux/bitops.h> |
17 | #include <linux/bitmap.h> | ||
14 | #include <linux/export.h> | 18 | #include <linux/export.h> |
15 | #include <asm/types.h> | 19 | #include <linux/kernel.h> |
16 | #include <asm/byteorder.h> | ||
17 | 20 | ||
18 | #ifndef find_last_bit | 21 | #ifndef find_last_bit |
19 | 22 | ||
20 | unsigned long find_last_bit(const unsigned long *addr, unsigned long size) | 23 | unsigned long find_last_bit(const unsigned long *addr, unsigned long size) |
21 | { | 24 | { |
22 | unsigned long words; | 25 | if (size) { |
23 | unsigned long tmp; | 26 | unsigned long val = BITMAP_LAST_WORD_MASK(size); |
24 | 27 | unsigned long idx = (size-1) / BITS_PER_LONG; | |
25 | /* Start at final word. */ | ||
26 | words = size / BITS_PER_LONG; | ||
27 | 28 | ||
28 | /* Partial final word? */ | 29 | do { |
29 | if (size & (BITS_PER_LONG-1)) { | 30 | val &= addr[idx]; |
30 | tmp = (addr[words] & (~0UL >> (BITS_PER_LONG | 31 | if (val) |
31 | - (size & (BITS_PER_LONG-1))))); | 32 | return idx * BITS_PER_LONG + __fls(val); |
32 | if (tmp) | ||
33 | goto found; | ||
34 | } | ||
35 | 33 | ||
36 | while (words) { | 34 | val = ~0ul; |
37 | tmp = addr[--words]; | 35 | } while (idx--); |
38 | if (tmp) { | ||
39 | found: | ||
40 | return words * BITS_PER_LONG + __fls(tmp); | ||
41 | } | ||
42 | } | 36 | } |
43 | |||
44 | /* Not found */ | ||
45 | return size; | 37 | return size; |
46 | } | 38 | } |
47 | EXPORT_SYMBOL(find_last_bit); | 39 | EXPORT_SYMBOL(find_last_bit); |