diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-12-17 23:58:12 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-12-17 23:58:12 -0500 |
commit | 848b81415c42ff3dc9a4204749087b015c37ef66 (patch) | |
tree | 391da3a73aea48632248220d2d6b8d45a88f7eae /lib | |
parent | 992956189de58cae9f2be40585bc25105cd7c5ad (diff) | |
parent | 6fd59a83b9261fa53eaf98fb5514abba504a3ea3 (diff) |
Merge branch 'akpm' (Andrew's patch-bomb)
Merge misc patches from Andrew Morton:
"Incoming:
- lots of misc stuff
- backlight tree updates
- lib/ updates
- Oleg's percpu-rwsem changes
- checkpatch
- rtc
- aoe
- more checkpoint/restart support
I still have a pile of MM stuff pending - Pekka should be merging
later today after which that is good to go. A number of other things
are twiddling thumbs awaiting maintainer merges."
* emailed patches from Andrew Morton <akpm@linux-foundation.org>: (180 commits)
scatterlist: don't BUG when we can trivially return a proper error.
docs: update documentation about /proc/<pid>/fdinfo/<fd> fanotify output
fs, fanotify: add @mflags field to fanotify output
docs: add documentation about /proc/<pid>/fdinfo/<fd> output
fs, notify: add procfs fdinfo helper
fs, exportfs: add exportfs_encode_inode_fh() helper
fs, exportfs: escape nil dereference if no s_export_op present
fs, epoll: add procfs fdinfo helper
fs, eventfd: add procfs fdinfo helper
procfs: add ability to plug in auxiliary fdinfo providers
tools/testing/selftests/kcmp/kcmp_test.c: print reason for failure in kcmp_test
breakpoint selftests: print failure status instead of cause make error
kcmp selftests: print fail status instead of cause make error
kcmp selftests: make run_tests fix
mem-hotplug selftests: print failure status instead of cause make error
cpu-hotplug selftests: print failure status instead of cause make error
mqueue selftests: print failure status instead of cause make error
vm selftests: print failure status instead of cause make error
ubifs: use prandom_bytes
mtd: nandsim: use prandom_bytes
...
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig | 3 | ||||
-rw-r--r-- | lib/Makefile | 1 | ||||
-rw-r--r-- | lib/dynamic_debug.c | 9 | ||||
-rw-r--r-- | lib/interval_tree_test_main.c | 7 | ||||
-rw-r--r-- | lib/kstrtox.c | 64 | ||||
-rw-r--r-- | lib/percpu-rwsem.c | 165 | ||||
-rw-r--r-- | lib/random32.c | 97 | ||||
-rw-r--r-- | lib/rbtree_test.c | 8 | ||||
-rw-r--r-- | lib/scatterlist.c | 3 | ||||
-rw-r--r-- | lib/vsprintf.c | 109 |
10 files changed, 382 insertions, 84 deletions
diff --git a/lib/Kconfig b/lib/Kconfig index 4b31a46fb307..75cdb77fa49d 100644 --- a/lib/Kconfig +++ b/lib/Kconfig | |||
@@ -42,6 +42,9 @@ config GENERIC_IO | |||
42 | config STMP_DEVICE | 42 | config STMP_DEVICE |
43 | bool | 43 | bool |
44 | 44 | ||
45 | config PERCPU_RWSEM | ||
46 | boolean | ||
47 | |||
45 | config CRC_CCITT | 48 | config CRC_CCITT |
46 | tristate "CRC-CCITT functions" | 49 | tristate "CRC-CCITT functions" |
47 | help | 50 | help |
diff --git a/lib/Makefile b/lib/Makefile index e2152fa7ff4d..5558e35170cd 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
@@ -40,6 +40,7 @@ obj-$(CONFIG_DEBUG_LOCKING_API_SELFTESTS) += locking-selftest.o | |||
40 | obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o | 40 | obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o |
41 | lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o | 41 | lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o |
42 | lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o | 42 | lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o |
43 | lib-$(CONFIG_PERCPU_RWSEM) += percpu-rwsem.o | ||
43 | 44 | ||
44 | CFLAGS_hweight.o = $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS)) | 45 | CFLAGS_hweight.o = $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS)) |
45 | obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o | 46 | obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o |
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index e7f7d993357a..1db1fc660538 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c | |||
@@ -62,13 +62,6 @@ static LIST_HEAD(ddebug_tables); | |||
62 | static int verbose = 0; | 62 | static int verbose = 0; |
63 | module_param(verbose, int, 0644); | 63 | module_param(verbose, int, 0644); |
64 | 64 | ||
65 | /* Return the last part of a pathname */ | ||
66 | static inline const char *basename(const char *path) | ||
67 | { | ||
68 | const char *tail = strrchr(path, '/'); | ||
69 | return tail ? tail+1 : path; | ||
70 | } | ||
71 | |||
72 | /* Return the path relative to source root */ | 65 | /* Return the path relative to source root */ |
73 | static inline const char *trim_prefix(const char *path) | 66 | static inline const char *trim_prefix(const char *path) |
74 | { | 67 | { |
@@ -154,7 +147,7 @@ static int ddebug_change(const struct ddebug_query *query, | |||
154 | /* match against the source filename */ | 147 | /* match against the source filename */ |
155 | if (query->filename && | 148 | if (query->filename && |
156 | strcmp(query->filename, dp->filename) && | 149 | strcmp(query->filename, dp->filename) && |
157 | strcmp(query->filename, basename(dp->filename)) && | 150 | strcmp(query->filename, kbasename(dp->filename)) && |
158 | strcmp(query->filename, trim_prefix(dp->filename))) | 151 | strcmp(query->filename, trim_prefix(dp->filename))) |
159 | continue; | 152 | continue; |
160 | 153 | ||
diff --git a/lib/interval_tree_test_main.c b/lib/interval_tree_test_main.c index b25903987f7a..245900b98c8e 100644 --- a/lib/interval_tree_test_main.c +++ b/lib/interval_tree_test_main.c | |||
@@ -30,7 +30,8 @@ static void init(void) | |||
30 | { | 30 | { |
31 | int i; | 31 | int i; |
32 | for (i = 0; i < NODES; i++) { | 32 | for (i = 0; i < NODES; i++) { |
33 | u32 a = prandom32(&rnd), b = prandom32(&rnd); | 33 | u32 a = prandom_u32_state(&rnd); |
34 | u32 b = prandom_u32_state(&rnd); | ||
34 | if (a <= b) { | 35 | if (a <= b) { |
35 | nodes[i].start = a; | 36 | nodes[i].start = a; |
36 | nodes[i].last = b; | 37 | nodes[i].last = b; |
@@ -40,7 +41,7 @@ static void init(void) | |||
40 | } | 41 | } |
41 | } | 42 | } |
42 | for (i = 0; i < SEARCHES; i++) | 43 | for (i = 0; i < SEARCHES; i++) |
43 | queries[i] = prandom32(&rnd); | 44 | queries[i] = prandom_u32_state(&rnd); |
44 | } | 45 | } |
45 | 46 | ||
46 | static int interval_tree_test_init(void) | 47 | static int interval_tree_test_init(void) |
@@ -51,7 +52,7 @@ static int interval_tree_test_init(void) | |||
51 | 52 | ||
52 | printk(KERN_ALERT "interval tree insert/remove"); | 53 | printk(KERN_ALERT "interval tree insert/remove"); |
53 | 54 | ||
54 | prandom32_seed(&rnd, 3141592653589793238ULL); | 55 | prandom_seed_state(&rnd, 3141592653589793238ULL); |
55 | init(); | 56 | init(); |
56 | 57 | ||
57 | time1 = get_cycles(); | 58 | time1 = get_cycles(); |
diff --git a/lib/kstrtox.c b/lib/kstrtox.c index c3615eab0cc3..f78ae0c0c4e2 100644 --- a/lib/kstrtox.c +++ b/lib/kstrtox.c | |||
@@ -104,6 +104,22 @@ static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res) | |||
104 | return 0; | 104 | return 0; |
105 | } | 105 | } |
106 | 106 | ||
107 | /** | ||
108 | * kstrtoull - convert a string to an unsigned long long | ||
109 | * @s: The start of the string. The string must be null-terminated, and may also | ||
110 | * include a single newline before its terminating null. The first character | ||
111 | * may also be a plus sign, but not a minus sign. | ||
112 | * @base: The number base to use. The maximum supported base is 16. If base is | ||
113 | * given as 0, then the base of the string is automatically detected with the | ||
114 | * conventional semantics - If it begins with 0x the number will be parsed as a | ||
115 | * hexadecimal (case insensitive), if it otherwise begins with 0, it will be | ||
116 | * parsed as an octal number. Otherwise it will be parsed as a decimal. | ||
117 | * @res: Where to write the result of the conversion on success. | ||
118 | * | ||
119 | * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. | ||
120 | * Used as a replacement for the obsolete simple_strtoull. Return code must | ||
121 | * be checked. | ||
122 | */ | ||
107 | int kstrtoull(const char *s, unsigned int base, unsigned long long *res) | 123 | int kstrtoull(const char *s, unsigned int base, unsigned long long *res) |
108 | { | 124 | { |
109 | if (s[0] == '+') | 125 | if (s[0] == '+') |
@@ -112,6 +128,22 @@ int kstrtoull(const char *s, unsigned int base, unsigned long long *res) | |||
112 | } | 128 | } |
113 | EXPORT_SYMBOL(kstrtoull); | 129 | EXPORT_SYMBOL(kstrtoull); |
114 | 130 | ||
131 | /** | ||
132 | * kstrtoll - convert a string to a long long | ||
133 | * @s: The start of the string. The string must be null-terminated, and may also | ||
134 | * include a single newline before its terminating null. The first character | ||
135 | * may also be a plus sign or a minus sign. | ||
136 | * @base: The number base to use. The maximum supported base is 16. If base is | ||
137 | * given as 0, then the base of the string is automatically detected with the | ||
138 | * conventional semantics - If it begins with 0x the number will be parsed as a | ||
139 | * hexadecimal (case insensitive), if it otherwise begins with 0, it will be | ||
140 | * parsed as an octal number. Otherwise it will be parsed as a decimal. | ||
141 | * @res: Where to write the result of the conversion on success. | ||
142 | * | ||
143 | * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. | ||
144 | * Used as a replacement for the obsolete simple_strtoull. Return code must | ||
145 | * be checked. | ||
146 | */ | ||
115 | int kstrtoll(const char *s, unsigned int base, long long *res) | 147 | int kstrtoll(const char *s, unsigned int base, long long *res) |
116 | { | 148 | { |
117 | unsigned long long tmp; | 149 | unsigned long long tmp; |
@@ -168,6 +200,22 @@ int _kstrtol(const char *s, unsigned int base, long *res) | |||
168 | } | 200 | } |
169 | EXPORT_SYMBOL(_kstrtol); | 201 | EXPORT_SYMBOL(_kstrtol); |
170 | 202 | ||
203 | /** | ||
204 | * kstrtouint - convert a string to an unsigned int | ||
205 | * @s: The start of the string. The string must be null-terminated, and may also | ||
206 | * include a single newline before its terminating null. The first character | ||
207 | * may also be a plus sign, but not a minus sign. | ||
208 | * @base: The number base to use. The maximum supported base is 16. If base is | ||
209 | * given as 0, then the base of the string is automatically detected with the | ||
210 | * conventional semantics - If it begins with 0x the number will be parsed as a | ||
211 | * hexadecimal (case insensitive), if it otherwise begins with 0, it will be | ||
212 | * parsed as an octal number. Otherwise it will be parsed as a decimal. | ||
213 | * @res: Where to write the result of the conversion on success. | ||
214 | * | ||
215 | * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. | ||
216 | * Used as a replacement for the obsolete simple_strtoull. Return code must | ||
217 | * be checked. | ||
218 | */ | ||
171 | int kstrtouint(const char *s, unsigned int base, unsigned int *res) | 219 | int kstrtouint(const char *s, unsigned int base, unsigned int *res) |
172 | { | 220 | { |
173 | unsigned long long tmp; | 221 | unsigned long long tmp; |
@@ -183,6 +231,22 @@ int kstrtouint(const char *s, unsigned int base, unsigned int *res) | |||
183 | } | 231 | } |
184 | EXPORT_SYMBOL(kstrtouint); | 232 | EXPORT_SYMBOL(kstrtouint); |
185 | 233 | ||
234 | /** | ||
235 | * kstrtoint - convert a string to an int | ||
236 | * @s: The start of the string. The string must be null-terminated, and may also | ||
237 | * include a single newline before its terminating null. The first character | ||
238 | * may also be a plus sign or a minus sign. | ||
239 | * @base: The number base to use. The maximum supported base is 16. If base is | ||
240 | * given as 0, then the base of the string is automatically detected with the | ||
241 | * conventional semantics - If it begins with 0x the number will be parsed as a | ||
242 | * hexadecimal (case insensitive), if it otherwise begins with 0, it will be | ||
243 | * parsed as an octal number. Otherwise it will be parsed as a decimal. | ||
244 | * @res: Where to write the result of the conversion on success. | ||
245 | * | ||
246 | * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. | ||
247 | * Used as a replacement for the obsolete simple_strtoull. Return code must | ||
248 | * be checked. | ||
249 | */ | ||
186 | int kstrtoint(const char *s, unsigned int base, int *res) | 250 | int kstrtoint(const char *s, unsigned int base, int *res) |
187 | { | 251 | { |
188 | long long tmp; | 252 | long long tmp; |
diff --git a/lib/percpu-rwsem.c b/lib/percpu-rwsem.c new file mode 100644 index 000000000000..652a8ee8efe9 --- /dev/null +++ b/lib/percpu-rwsem.c | |||
@@ -0,0 +1,165 @@ | |||
1 | #include <linux/atomic.h> | ||
2 | #include <linux/rwsem.h> | ||
3 | #include <linux/percpu.h> | ||
4 | #include <linux/wait.h> | ||
5 | #include <linux/lockdep.h> | ||
6 | #include <linux/percpu-rwsem.h> | ||
7 | #include <linux/rcupdate.h> | ||
8 | #include <linux/sched.h> | ||
9 | #include <linux/errno.h> | ||
10 | |||
11 | int __percpu_init_rwsem(struct percpu_rw_semaphore *brw, | ||
12 | const char *name, struct lock_class_key *rwsem_key) | ||
13 | { | ||
14 | brw->fast_read_ctr = alloc_percpu(int); | ||
15 | if (unlikely(!brw->fast_read_ctr)) | ||
16 | return -ENOMEM; | ||
17 | |||
18 | /* ->rw_sem represents the whole percpu_rw_semaphore for lockdep */ | ||
19 | __init_rwsem(&brw->rw_sem, name, rwsem_key); | ||
20 | atomic_set(&brw->write_ctr, 0); | ||
21 | atomic_set(&brw->slow_read_ctr, 0); | ||
22 | init_waitqueue_head(&brw->write_waitq); | ||
23 | return 0; | ||
24 | } | ||
25 | |||
26 | void percpu_free_rwsem(struct percpu_rw_semaphore *brw) | ||
27 | { | ||
28 | free_percpu(brw->fast_read_ctr); | ||
29 | brw->fast_read_ctr = NULL; /* catch use after free bugs */ | ||
30 | } | ||
31 | |||
32 | /* | ||
33 | * This is the fast-path for down_read/up_read, it only needs to ensure | ||
34 | * there is no pending writer (atomic_read(write_ctr) == 0) and inc/dec the | ||
35 | * fast per-cpu counter. The writer uses synchronize_sched_expedited() to | ||
36 | * serialize with the preempt-disabled section below. | ||
37 | * | ||
38 | * The nontrivial part is that we should guarantee acquire/release semantics | ||
39 | * in case when | ||
40 | * | ||
41 | * R_W: down_write() comes after up_read(), the writer should see all | ||
42 | * changes done by the reader | ||
43 | * or | ||
44 | * W_R: down_read() comes after up_write(), the reader should see all | ||
45 | * changes done by the writer | ||
46 | * | ||
47 | * If this helper fails the callers rely on the normal rw_semaphore and | ||
48 | * atomic_dec_and_test(), so in this case we have the necessary barriers. | ||
49 | * | ||
50 | * But if it succeeds we do not have any barriers, atomic_read(write_ctr) or | ||
51 | * __this_cpu_add() below can be reordered with any LOAD/STORE done by the | ||
52 | * reader inside the critical section. See the comments in down_write and | ||
53 | * up_write below. | ||
54 | */ | ||
55 | static bool update_fast_ctr(struct percpu_rw_semaphore *brw, unsigned int val) | ||
56 | { | ||
57 | bool success = false; | ||
58 | |||
59 | preempt_disable(); | ||
60 | if (likely(!atomic_read(&brw->write_ctr))) { | ||
61 | __this_cpu_add(*brw->fast_read_ctr, val); | ||
62 | success = true; | ||
63 | } | ||
64 | preempt_enable(); | ||
65 | |||
66 | return success; | ||
67 | } | ||
68 | |||
69 | /* | ||
70 | * Like the normal down_read() this is not recursive, the writer can | ||
71 | * come after the first percpu_down_read() and create the deadlock. | ||
72 | * | ||
73 | * Note: returns with lock_is_held(brw->rw_sem) == T for lockdep, | ||
74 | * percpu_up_read() does rwsem_release(). This pairs with the usage | ||
75 | * of ->rw_sem in percpu_down/up_write(). | ||
76 | */ | ||
77 | void percpu_down_read(struct percpu_rw_semaphore *brw) | ||
78 | { | ||
79 | might_sleep(); | ||
80 | if (likely(update_fast_ctr(brw, +1))) { | ||
81 | rwsem_acquire_read(&brw->rw_sem.dep_map, 0, 0, _RET_IP_); | ||
82 | return; | ||
83 | } | ||
84 | |||
85 | down_read(&brw->rw_sem); | ||
86 | atomic_inc(&brw->slow_read_ctr); | ||
87 | /* avoid up_read()->rwsem_release() */ | ||
88 | __up_read(&brw->rw_sem); | ||
89 | } | ||
90 | |||
91 | void percpu_up_read(struct percpu_rw_semaphore *brw) | ||
92 | { | ||
93 | rwsem_release(&brw->rw_sem.dep_map, 1, _RET_IP_); | ||
94 | |||
95 | if (likely(update_fast_ctr(brw, -1))) | ||
96 | return; | ||
97 | |||
98 | /* false-positive is possible but harmless */ | ||
99 | if (atomic_dec_and_test(&brw->slow_read_ctr)) | ||
100 | wake_up_all(&brw->write_waitq); | ||
101 | } | ||
102 | |||
103 | static int clear_fast_ctr(struct percpu_rw_semaphore *brw) | ||
104 | { | ||
105 | unsigned int sum = 0; | ||
106 | int cpu; | ||
107 | |||
108 | for_each_possible_cpu(cpu) { | ||
109 | sum += per_cpu(*brw->fast_read_ctr, cpu); | ||
110 | per_cpu(*brw->fast_read_ctr, cpu) = 0; | ||
111 | } | ||
112 | |||
113 | return sum; | ||
114 | } | ||
115 | |||
116 | /* | ||
117 | * A writer increments ->write_ctr to force the readers to switch to the | ||
118 | * slow mode, note the atomic_read() check in update_fast_ctr(). | ||
119 | * | ||
120 | * After that the readers can only inc/dec the slow ->slow_read_ctr counter, | ||
121 | * ->fast_read_ctr is stable. Once the writer moves its sum into the slow | ||
122 | * counter it represents the number of active readers. | ||
123 | * | ||
124 | * Finally the writer takes ->rw_sem for writing and blocks the new readers, | ||
125 | * then waits until the slow counter becomes zero. | ||
126 | */ | ||
127 | void percpu_down_write(struct percpu_rw_semaphore *brw) | ||
128 | { | ||
129 | /* tell update_fast_ctr() there is a pending writer */ | ||
130 | atomic_inc(&brw->write_ctr); | ||
131 | /* | ||
132 | * 1. Ensures that write_ctr != 0 is visible to any down_read/up_read | ||
133 | * so that update_fast_ctr() can't succeed. | ||
134 | * | ||
135 | * 2. Ensures we see the result of every previous this_cpu_add() in | ||
136 | * update_fast_ctr(). | ||
137 | * | ||
138 | * 3. Ensures that if any reader has exited its critical section via | ||
139 | * fast-path, it executes a full memory barrier before we return. | ||
140 | * See R_W case in the comment above update_fast_ctr(). | ||
141 | */ | ||
142 | synchronize_sched_expedited(); | ||
143 | |||
144 | /* exclude other writers, and block the new readers completely */ | ||
145 | down_write(&brw->rw_sem); | ||
146 | |||
147 | /* nobody can use fast_read_ctr, move its sum into slow_read_ctr */ | ||
148 | atomic_add(clear_fast_ctr(brw), &brw->slow_read_ctr); | ||
149 | |||
150 | /* wait for all readers to complete their percpu_up_read() */ | ||
151 | wait_event(brw->write_waitq, !atomic_read(&brw->slow_read_ctr)); | ||
152 | } | ||
153 | |||
154 | void percpu_up_write(struct percpu_rw_semaphore *brw) | ||
155 | { | ||
156 | /* release the lock, but the readers can't use the fast-path */ | ||
157 | up_write(&brw->rw_sem); | ||
158 | /* | ||
159 | * Insert the barrier before the next fast-path in down_read, | ||
160 | * see W_R case in the comment above update_fast_ctr(). | ||
161 | */ | ||
162 | synchronize_sched_expedited(); | ||
163 | /* the last writer unblocks update_fast_ctr() */ | ||
164 | atomic_dec(&brw->write_ctr); | ||
165 | } | ||
diff --git a/lib/random32.c b/lib/random32.c index 938bde5876ac..52280d5526be 100644 --- a/lib/random32.c +++ b/lib/random32.c | |||
@@ -42,13 +42,13 @@ | |||
42 | static DEFINE_PER_CPU(struct rnd_state, net_rand_state); | 42 | static DEFINE_PER_CPU(struct rnd_state, net_rand_state); |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * prandom32 - seeded pseudo-random number generator. | 45 | * prandom_u32_state - seeded pseudo-random number generator. |
46 | * @state: pointer to state structure holding seeded state. | 46 | * @state: pointer to state structure holding seeded state. |
47 | * | 47 | * |
48 | * This is used for pseudo-randomness with no outside seeding. | 48 | * This is used for pseudo-randomness with no outside seeding. |
49 | * For more random results, use random32(). | 49 | * For more random results, use prandom_u32(). |
50 | */ | 50 | */ |
51 | u32 prandom32(struct rnd_state *state) | 51 | u32 prandom_u32_state(struct rnd_state *state) |
52 | { | 52 | { |
53 | #define TAUSWORTHE(s,a,b,c,d) ((s&c)<<d) ^ (((s <<a) ^ s)>>b) | 53 | #define TAUSWORTHE(s,a,b,c,d) ((s&c)<<d) ^ (((s <<a) ^ s)>>b) |
54 | 54 | ||
@@ -58,32 +58,81 @@ u32 prandom32(struct rnd_state *state) | |||
58 | 58 | ||
59 | return (state->s1 ^ state->s2 ^ state->s3); | 59 | return (state->s1 ^ state->s2 ^ state->s3); |
60 | } | 60 | } |
61 | EXPORT_SYMBOL(prandom32); | 61 | EXPORT_SYMBOL(prandom_u32_state); |
62 | 62 | ||
63 | /** | 63 | /** |
64 | * random32 - pseudo random number generator | 64 | * prandom_u32 - pseudo random number generator |
65 | * | 65 | * |
66 | * A 32 bit pseudo-random number is generated using a fast | 66 | * A 32 bit pseudo-random number is generated using a fast |
67 | * algorithm suitable for simulation. This algorithm is NOT | 67 | * algorithm suitable for simulation. This algorithm is NOT |
68 | * considered safe for cryptographic use. | 68 | * considered safe for cryptographic use. |
69 | */ | 69 | */ |
70 | u32 random32(void) | 70 | u32 prandom_u32(void) |
71 | { | 71 | { |
72 | unsigned long r; | 72 | unsigned long r; |
73 | struct rnd_state *state = &get_cpu_var(net_rand_state); | 73 | struct rnd_state *state = &get_cpu_var(net_rand_state); |
74 | r = prandom32(state); | 74 | r = prandom_u32_state(state); |
75 | put_cpu_var(state); | 75 | put_cpu_var(state); |
76 | return r; | 76 | return r; |
77 | } | 77 | } |
78 | EXPORT_SYMBOL(random32); | 78 | EXPORT_SYMBOL(prandom_u32); |
79 | |||
80 | /* | ||
81 | * prandom_bytes_state - get the requested number of pseudo-random bytes | ||
82 | * | ||
83 | * @state: pointer to state structure holding seeded state. | ||
84 | * @buf: where to copy the pseudo-random bytes to | ||
85 | * @bytes: the requested number of bytes | ||
86 | * | ||
87 | * This is used for pseudo-randomness with no outside seeding. | ||
88 | * For more random results, use prandom_bytes(). | ||
89 | */ | ||
90 | void prandom_bytes_state(struct rnd_state *state, void *buf, int bytes) | ||
91 | { | ||
92 | unsigned char *p = buf; | ||
93 | int i; | ||
94 | |||
95 | for (i = 0; i < round_down(bytes, sizeof(u32)); i += sizeof(u32)) { | ||
96 | u32 random = prandom_u32_state(state); | ||
97 | int j; | ||
98 | |||
99 | for (j = 0; j < sizeof(u32); j++) { | ||
100 | p[i + j] = random; | ||
101 | random >>= BITS_PER_BYTE; | ||
102 | } | ||
103 | } | ||
104 | if (i < bytes) { | ||
105 | u32 random = prandom_u32_state(state); | ||
106 | |||
107 | for (; i < bytes; i++) { | ||
108 | p[i] = random; | ||
109 | random >>= BITS_PER_BYTE; | ||
110 | } | ||
111 | } | ||
112 | } | ||
113 | EXPORT_SYMBOL(prandom_bytes_state); | ||
114 | |||
115 | /** | ||
116 | * prandom_bytes - get the requested number of pseudo-random bytes | ||
117 | * @buf: where to copy the pseudo-random bytes to | ||
118 | * @bytes: the requested number of bytes | ||
119 | */ | ||
120 | void prandom_bytes(void *buf, int bytes) | ||
121 | { | ||
122 | struct rnd_state *state = &get_cpu_var(net_rand_state); | ||
123 | |||
124 | prandom_bytes_state(state, buf, bytes); | ||
125 | put_cpu_var(state); | ||
126 | } | ||
127 | EXPORT_SYMBOL(prandom_bytes); | ||
79 | 128 | ||
80 | /** | 129 | /** |
81 | * srandom32 - add entropy to pseudo random number generator | 130 | * prandom_seed - add entropy to pseudo random number generator |
82 | * @seed: seed value | 131 | * @seed: seed value |
83 | * | 132 | * |
84 | * Add some additional seeding to the random32() pool. | 133 | * Add some additional seeding to the prandom pool. |
85 | */ | 134 | */ |
86 | void srandom32(u32 entropy) | 135 | void prandom_seed(u32 entropy) |
87 | { | 136 | { |
88 | int i; | 137 | int i; |
89 | /* | 138 | /* |
@@ -95,13 +144,13 @@ void srandom32(u32 entropy) | |||
95 | state->s1 = __seed(state->s1 ^ entropy, 1); | 144 | state->s1 = __seed(state->s1 ^ entropy, 1); |
96 | } | 145 | } |
97 | } | 146 | } |
98 | EXPORT_SYMBOL(srandom32); | 147 | EXPORT_SYMBOL(prandom_seed); |
99 | 148 | ||
100 | /* | 149 | /* |
101 | * Generate some initially weak seeding values to allow | 150 | * Generate some initially weak seeding values to allow |
102 | * to start the random32() engine. | 151 | * to start the prandom_u32() engine. |
103 | */ | 152 | */ |
104 | static int __init random32_init(void) | 153 | static int __init prandom_init(void) |
105 | { | 154 | { |
106 | int i; | 155 | int i; |
107 | 156 | ||
@@ -114,22 +163,22 @@ static int __init random32_init(void) | |||
114 | state->s3 = __seed(LCG(state->s2), 15); | 163 | state->s3 = __seed(LCG(state->s2), 15); |
115 | 164 | ||
116 | /* "warm it up" */ | 165 | /* "warm it up" */ |
117 | prandom32(state); | 166 | prandom_u32_state(state); |
118 | prandom32(state); | 167 | prandom_u32_state(state); |
119 | prandom32(state); | 168 | prandom_u32_state(state); |
120 | prandom32(state); | 169 | prandom_u32_state(state); |
121 | prandom32(state); | 170 | prandom_u32_state(state); |
122 | prandom32(state); | 171 | prandom_u32_state(state); |
123 | } | 172 | } |
124 | return 0; | 173 | return 0; |
125 | } | 174 | } |
126 | core_initcall(random32_init); | 175 | core_initcall(prandom_init); |
127 | 176 | ||
128 | /* | 177 | /* |
129 | * Generate better values after random number generator | 178 | * Generate better values after random number generator |
130 | * is fully initialized. | 179 | * is fully initialized. |
131 | */ | 180 | */ |
132 | static int __init random32_reseed(void) | 181 | static int __init prandom_reseed(void) |
133 | { | 182 | { |
134 | int i; | 183 | int i; |
135 | 184 | ||
@@ -143,8 +192,8 @@ static int __init random32_reseed(void) | |||
143 | state->s3 = __seed(seeds[2], 15); | 192 | state->s3 = __seed(seeds[2], 15); |
144 | 193 | ||
145 | /* mix it in */ | 194 | /* mix it in */ |
146 | prandom32(state); | 195 | prandom_u32_state(state); |
147 | } | 196 | } |
148 | return 0; | 197 | return 0; |
149 | } | 198 | } |
150 | late_initcall(random32_reseed); | 199 | late_initcall(prandom_reseed); |
diff --git a/lib/rbtree_test.c b/lib/rbtree_test.c index 268b23951fec..af38aedbd874 100644 --- a/lib/rbtree_test.c +++ b/lib/rbtree_test.c | |||
@@ -96,8 +96,8 @@ static void init(void) | |||
96 | { | 96 | { |
97 | int i; | 97 | int i; |
98 | for (i = 0; i < NODES; i++) { | 98 | for (i = 0; i < NODES; i++) { |
99 | nodes[i].key = prandom32(&rnd); | 99 | nodes[i].key = prandom_u32_state(&rnd); |
100 | nodes[i].val = prandom32(&rnd); | 100 | nodes[i].val = prandom_u32_state(&rnd); |
101 | } | 101 | } |
102 | } | 102 | } |
103 | 103 | ||
@@ -118,7 +118,7 @@ static void check(int nr_nodes) | |||
118 | { | 118 | { |
119 | struct rb_node *rb; | 119 | struct rb_node *rb; |
120 | int count = 0; | 120 | int count = 0; |
121 | int blacks; | 121 | int blacks = 0; |
122 | u32 prev_key = 0; | 122 | u32 prev_key = 0; |
123 | 123 | ||
124 | for (rb = rb_first(&root); rb; rb = rb_next(rb)) { | 124 | for (rb = rb_first(&root); rb; rb = rb_next(rb)) { |
@@ -155,7 +155,7 @@ static int rbtree_test_init(void) | |||
155 | 155 | ||
156 | printk(KERN_ALERT "rbtree testing"); | 156 | printk(KERN_ALERT "rbtree testing"); |
157 | 157 | ||
158 | prandom32_seed(&rnd, 3141592653589793238ULL); | 158 | prandom_seed_state(&rnd, 3141592653589793238ULL); |
159 | init(); | 159 | init(); |
160 | 160 | ||
161 | time1 = get_cycles(); | 161 | time1 = get_cycles(); |
diff --git a/lib/scatterlist.c b/lib/scatterlist.c index 3675452b23ca..7874b01e816e 100644 --- a/lib/scatterlist.c +++ b/lib/scatterlist.c | |||
@@ -248,7 +248,8 @@ int __sg_alloc_table(struct sg_table *table, unsigned int nents, | |||
248 | unsigned int left; | 248 | unsigned int left; |
249 | 249 | ||
250 | #ifndef ARCH_HAS_SG_CHAIN | 250 | #ifndef ARCH_HAS_SG_CHAIN |
251 | BUG_ON(nents > max_ents); | 251 | if (WARN_ON_ONCE(nents > max_ents)) |
252 | return -EINVAL; | ||
252 | #endif | 253 | #endif |
253 | 254 | ||
254 | memset(table, 0, sizeof(*table)); | 255 | memset(table, 0, sizeof(*table)); |
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 39c99fea7c03..fab33a9c5318 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -23,12 +23,12 @@ | |||
23 | #include <linux/ctype.h> | 23 | #include <linux/ctype.h> |
24 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
25 | #include <linux/kallsyms.h> | 25 | #include <linux/kallsyms.h> |
26 | #include <linux/math64.h> | ||
26 | #include <linux/uaccess.h> | 27 | #include <linux/uaccess.h> |
27 | #include <linux/ioport.h> | 28 | #include <linux/ioport.h> |
28 | #include <net/addrconf.h> | 29 | #include <net/addrconf.h> |
29 | 30 | ||
30 | #include <asm/page.h> /* for PAGE_SIZE */ | 31 | #include <asm/page.h> /* for PAGE_SIZE */ |
31 | #include <asm/div64.h> | ||
32 | #include <asm/sections.h> /* for dereference_function_descriptor() */ | 32 | #include <asm/sections.h> /* for dereference_function_descriptor() */ |
33 | 33 | ||
34 | #include "kstrtox.h" | 34 | #include "kstrtox.h" |
@@ -38,6 +38,8 @@ | |||
38 | * @cp: The start of the string | 38 | * @cp: The start of the string |
39 | * @endp: A pointer to the end of the parsed string will be placed here | 39 | * @endp: A pointer to the end of the parsed string will be placed here |
40 | * @base: The number base to use | 40 | * @base: The number base to use |
41 | * | ||
42 | * This function is obsolete. Please use kstrtoull instead. | ||
41 | */ | 43 | */ |
42 | unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base) | 44 | unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base) |
43 | { | 45 | { |
@@ -61,6 +63,8 @@ EXPORT_SYMBOL(simple_strtoull); | |||
61 | * @cp: The start of the string | 63 | * @cp: The start of the string |
62 | * @endp: A pointer to the end of the parsed string will be placed here | 64 | * @endp: A pointer to the end of the parsed string will be placed here |
63 | * @base: The number base to use | 65 | * @base: The number base to use |
66 | * | ||
67 | * This function is obsolete. Please use kstrtoul instead. | ||
64 | */ | 68 | */ |
65 | unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base) | 69 | unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base) |
66 | { | 70 | { |
@@ -73,6 +77,8 @@ EXPORT_SYMBOL(simple_strtoul); | |||
73 | * @cp: The start of the string | 77 | * @cp: The start of the string |
74 | * @endp: A pointer to the end of the parsed string will be placed here | 78 | * @endp: A pointer to the end of the parsed string will be placed here |
75 | * @base: The number base to use | 79 | * @base: The number base to use |
80 | * | ||
81 | * This function is obsolete. Please use kstrtol instead. | ||
76 | */ | 82 | */ |
77 | long simple_strtol(const char *cp, char **endp, unsigned int base) | 83 | long simple_strtol(const char *cp, char **endp, unsigned int base) |
78 | { | 84 | { |
@@ -88,6 +94,8 @@ EXPORT_SYMBOL(simple_strtol); | |||
88 | * @cp: The start of the string | 94 | * @cp: The start of the string |
89 | * @endp: A pointer to the end of the parsed string will be placed here | 95 | * @endp: A pointer to the end of the parsed string will be placed here |
90 | * @base: The number base to use | 96 | * @base: The number base to use |
97 | * | ||
98 | * This function is obsolete. Please use kstrtoll instead. | ||
91 | */ | 99 | */ |
92 | long long simple_strtoll(const char *cp, char **endp, unsigned int base) | 100 | long long simple_strtoll(const char *cp, char **endp, unsigned int base) |
93 | { | 101 | { |
@@ -1485,7 +1493,10 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) | |||
1485 | num = va_arg(args, long); | 1493 | num = va_arg(args, long); |
1486 | break; | 1494 | break; |
1487 | case FORMAT_TYPE_SIZE_T: | 1495 | case FORMAT_TYPE_SIZE_T: |
1488 | num = va_arg(args, size_t); | 1496 | if (spec.flags & SIGN) |
1497 | num = va_arg(args, ssize_t); | ||
1498 | else | ||
1499 | num = va_arg(args, size_t); | ||
1489 | break; | 1500 | break; |
1490 | case FORMAT_TYPE_PTRDIFF: | 1501 | case FORMAT_TYPE_PTRDIFF: |
1491 | num = va_arg(args, ptrdiff_t); | 1502 | num = va_arg(args, ptrdiff_t); |
@@ -2013,7 +2024,11 @@ int vsscanf(const char *buf, const char *fmt, va_list args) | |||
2013 | char digit; | 2024 | char digit; |
2014 | int num = 0; | 2025 | int num = 0; |
2015 | u8 qualifier; | 2026 | u8 qualifier; |
2016 | u8 base; | 2027 | unsigned int base; |
2028 | union { | ||
2029 | long long s; | ||
2030 | unsigned long long u; | ||
2031 | } val; | ||
2017 | s16 field_width; | 2032 | s16 field_width; |
2018 | bool is_sign; | 2033 | bool is_sign; |
2019 | 2034 | ||
@@ -2053,8 +2068,11 @@ int vsscanf(const char *buf, const char *fmt, va_list args) | |||
2053 | 2068 | ||
2054 | /* get field width */ | 2069 | /* get field width */ |
2055 | field_width = -1; | 2070 | field_width = -1; |
2056 | if (isdigit(*fmt)) | 2071 | if (isdigit(*fmt)) { |
2057 | field_width = skip_atoi(&fmt); | 2072 | field_width = skip_atoi(&fmt); |
2073 | if (field_width <= 0) | ||
2074 | break; | ||
2075 | } | ||
2058 | 2076 | ||
2059 | /* get conversion qualifier */ | 2077 | /* get conversion qualifier */ |
2060 | qualifier = -1; | 2078 | qualifier = -1; |
@@ -2154,58 +2172,61 @@ int vsscanf(const char *buf, const char *fmt, va_list args) | |||
2154 | || (base == 0 && !isdigit(digit))) | 2172 | || (base == 0 && !isdigit(digit))) |
2155 | break; | 2173 | break; |
2156 | 2174 | ||
2175 | if (is_sign) | ||
2176 | val.s = qualifier != 'L' ? | ||
2177 | simple_strtol(str, &next, base) : | ||
2178 | simple_strtoll(str, &next, base); | ||
2179 | else | ||
2180 | val.u = qualifier != 'L' ? | ||
2181 | simple_strtoul(str, &next, base) : | ||
2182 | simple_strtoull(str, &next, base); | ||
2183 | |||
2184 | if (field_width > 0 && next - str > field_width) { | ||
2185 | if (base == 0) | ||
2186 | _parse_integer_fixup_radix(str, &base); | ||
2187 | while (next - str > field_width) { | ||
2188 | if (is_sign) | ||
2189 | val.s = div_s64(val.s, base); | ||
2190 | else | ||
2191 | val.u = div_u64(val.u, base); | ||
2192 | --next; | ||
2193 | } | ||
2194 | } | ||
2195 | |||
2157 | switch (qualifier) { | 2196 | switch (qualifier) { |
2158 | case 'H': /* that's 'hh' in format */ | 2197 | case 'H': /* that's 'hh' in format */ |
2159 | if (is_sign) { | 2198 | if (is_sign) |
2160 | signed char *s = (signed char *)va_arg(args, signed char *); | 2199 | *va_arg(args, signed char *) = val.s; |
2161 | *s = (signed char)simple_strtol(str, &next, base); | 2200 | else |
2162 | } else { | 2201 | *va_arg(args, unsigned char *) = val.u; |
2163 | unsigned char *s = (unsigned char *)va_arg(args, unsigned char *); | ||
2164 | *s = (unsigned char)simple_strtoul(str, &next, base); | ||
2165 | } | ||
2166 | break; | 2202 | break; |
2167 | case 'h': | 2203 | case 'h': |
2168 | if (is_sign) { | 2204 | if (is_sign) |
2169 | short *s = (short *)va_arg(args, short *); | 2205 | *va_arg(args, short *) = val.s; |
2170 | *s = (short)simple_strtol(str, &next, base); | 2206 | else |
2171 | } else { | 2207 | *va_arg(args, unsigned short *) = val.u; |
2172 | unsigned short *s = (unsigned short *)va_arg(args, unsigned short *); | ||
2173 | *s = (unsigned short)simple_strtoul(str, &next, base); | ||
2174 | } | ||
2175 | break; | 2208 | break; |
2176 | case 'l': | 2209 | case 'l': |
2177 | if (is_sign) { | 2210 | if (is_sign) |
2178 | long *l = (long *)va_arg(args, long *); | 2211 | *va_arg(args, long *) = val.s; |
2179 | *l = simple_strtol(str, &next, base); | 2212 | else |
2180 | } else { | 2213 | *va_arg(args, unsigned long *) = val.u; |
2181 | unsigned long *l = (unsigned long *)va_arg(args, unsigned long *); | ||
2182 | *l = simple_strtoul(str, &next, base); | ||
2183 | } | ||
2184 | break; | 2214 | break; |
2185 | case 'L': | 2215 | case 'L': |
2186 | if (is_sign) { | 2216 | if (is_sign) |
2187 | long long *l = (long long *)va_arg(args, long long *); | 2217 | *va_arg(args, long long *) = val.s; |
2188 | *l = simple_strtoll(str, &next, base); | 2218 | else |
2189 | } else { | 2219 | *va_arg(args, unsigned long long *) = val.u; |
2190 | unsigned long long *l = (unsigned long long *)va_arg(args, unsigned long long *); | ||
2191 | *l = simple_strtoull(str, &next, base); | ||
2192 | } | ||
2193 | break; | 2220 | break; |
2194 | case 'Z': | 2221 | case 'Z': |
2195 | case 'z': | 2222 | case 'z': |
2196 | { | 2223 | *va_arg(args, size_t *) = val.u; |
2197 | size_t *s = (size_t *)va_arg(args, size_t *); | 2224 | break; |
2198 | *s = (size_t)simple_strtoul(str, &next, base); | ||
2199 | } | ||
2200 | break; | ||
2201 | default: | 2225 | default: |
2202 | if (is_sign) { | 2226 | if (is_sign) |
2203 | int *i = (int *)va_arg(args, int *); | 2227 | *va_arg(args, int *) = val.s; |
2204 | *i = (int)simple_strtol(str, &next, base); | 2228 | else |
2205 | } else { | 2229 | *va_arg(args, unsigned int *) = val.u; |
2206 | unsigned int *i = (unsigned int *)va_arg(args, unsigned int*); | ||
2207 | *i = (unsigned int)simple_strtoul(str, &next, base); | ||
2208 | } | ||
2209 | break; | 2230 | break; |
2210 | } | 2231 | } |
2211 | num++; | 2232 | num++; |