aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPaul Mackerras <paulus@samba.org>2006-12-03 23:59:07 -0500
committerPaul Mackerras <paulus@samba.org>2006-12-03 23:59:07 -0500
commit79acbb3ff2d8095b692e1502b9eb2ccec348de26 (patch)
tree6ab773e5a8f9de2cd6443362b21d0d6fffe3b35e /lib
parent19a79859e168640f8e16d7b216d211c1c52b687a (diff)
parent2b5f6dcce5bf94b9b119e9ed8d537098ec61c3d2 (diff)
Merge branch 'linux-2.6' into for-linus
Diffstat (limited to 'lib')
-rw-r--r--lib/Kconfig.debug2
-rw-r--r--lib/Makefile4
-rw-r--r--lib/carta_random32.c41
-rw-r--r--lib/cpumask.c16
-rw-r--r--lib/kobject.c51
-rw-r--r--lib/kobject_uevent.c28
-rw-r--r--lib/random32.c142
-rw-r--r--lib/rwsem-spinlock.c2
-rw-r--r--lib/rwsem.c2
-rw-r--r--lib/spinlock_debug.c4
-rw-r--r--lib/string.c2
-rw-r--r--lib/textsearch.c2
12 files changed, 226 insertions, 70 deletions
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 77491e311791..d3679103a8e4 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -341,7 +341,7 @@ config FRAME_POINTER
341 341
342config UNWIND_INFO 342config UNWIND_INFO
343 bool "Compile the kernel with frame unwind information" 343 bool "Compile the kernel with frame unwind information"
344 depends on !IA64 && !PARISC 344 depends on !IA64 && !PARISC && !ARM
345 depends on !MODULES || !(MIPS || PPC || SUPERH || V850) 345 depends on !MODULES || !(MIPS || PPC || SUPERH || V850)
346 help 346 help
347 If you say Y here the resulting kernel image will be slightly larger 347 If you say Y here the resulting kernel image will be slightly larger
diff --git a/lib/Makefile b/lib/Makefile
index 59070dbfbeb4..cf98fabaa549 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -5,14 +5,14 @@
5lib-y := ctype.o string.o vsprintf.o cmdline.o \ 5lib-y := ctype.o string.o vsprintf.o cmdline.o \
6 bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \ 6 bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \
7 idr.o div64.o int_sqrt.o bitmap.o extable.o prio_tree.o \ 7 idr.o div64.o int_sqrt.o bitmap.o extable.o prio_tree.o \
8 sha1.o irq_regs.o carta_random32.o 8 sha1.o irq_regs.o
9 9
10lib-$(CONFIG_MMU) += ioremap.o 10lib-$(CONFIG_MMU) += ioremap.o
11lib-$(CONFIG_SMP) += cpumask.o 11lib-$(CONFIG_SMP) += cpumask.o
12 12
13lib-y += kobject.o kref.o kobject_uevent.o klist.o 13lib-y += kobject.o kref.o kobject_uevent.o klist.o
14 14
15obj-y += sort.o parser.o halfmd4.o iomap_copy.o debug_locks.o 15obj-y += sort.o parser.o halfmd4.o iomap_copy.o debug_locks.o random32.o
16 16
17ifeq ($(CONFIG_DEBUG_KOBJECT),y) 17ifeq ($(CONFIG_DEBUG_KOBJECT),y)
18CFLAGS_kobject.o += -DDEBUG 18CFLAGS_kobject.o += -DDEBUG
diff --git a/lib/carta_random32.c b/lib/carta_random32.c
deleted file mode 100644
index ca82df70eee4..000000000000
--- a/lib/carta_random32.c
+++ /dev/null
@@ -1,41 +0,0 @@
1/*
2 * Copyright (c) 2002-2006 Hewlett-Packard Development Company, L.P.
3 * Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 * 02111-1307 USA
18 */
19#include <linux/types.h>
20#include <linux/module.h>
21
22/*
23 * Fast, simple, yet decent quality random number generator based on
24 * a paper by David G. Carta ("Two Fast Implementations of the
25 * `Minimal Standard' Random Number Generator," Communications of the
26 * ACM, January, 1990).
27 */
28u64 carta_random32 (u64 seed)
29{
30# define A 16807
31# define M ((u32) 1 << 31)
32 u64 s, prod = A * seed, p, q;
33
34 p = (prod >> 31) & (M - 1);
35 q = (prod >> 0) & (M - 1);
36 s = p + q;
37 if (s >= M)
38 s -= M - 1;
39 return s;
40}
41EXPORT_SYMBOL_GPL(carta_random32);
diff --git a/lib/cpumask.c b/lib/cpumask.c
index 7a2a73f88d59..3a67dc5ada7d 100644
--- a/lib/cpumask.c
+++ b/lib/cpumask.c
@@ -43,19 +43,3 @@ int __any_online_cpu(const cpumask_t *mask)
43 return cpu; 43 return cpu;
44} 44}
45EXPORT_SYMBOL(__any_online_cpu); 45EXPORT_SYMBOL(__any_online_cpu);
46
47#if MAX_NUMNODES > 1
48/*
49 * Find the highest possible node id.
50 */
51int highest_possible_node_id(void)
52{
53 unsigned int node;
54 unsigned int highest = 0;
55
56 for_each_node_mask(node, node_possible_map)
57 highest = node;
58 return highest;
59}
60EXPORT_SYMBOL(highest_possible_node_id);
61#endif
diff --git a/lib/kobject.c b/lib/kobject.c
index 1699eb9161f3..744a4b102c7f 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -119,6 +119,7 @@ char *kobject_get_path(struct kobject *kobj, gfp_t gfp_mask)
119 119
120 return path; 120 return path;
121} 121}
122EXPORT_SYMBOL_GPL(kobject_get_path);
122 123
123/** 124/**
124 * kobject_init - initialize object. 125 * kobject_init - initialize object.
@@ -310,6 +311,56 @@ int kobject_rename(struct kobject * kobj, const char *new_name)
310} 311}
311 312
312/** 313/**
314 * kobject_move - move object to another parent
315 * @kobj: object in question.
316 * @new_parent: object's new parent
317 */
318
319int kobject_move(struct kobject *kobj, struct kobject *new_parent)
320{
321 int error;
322 struct kobject *old_parent;
323 const char *devpath = NULL;
324 char *devpath_string = NULL;
325 char *envp[2];
326
327 kobj = kobject_get(kobj);
328 if (!kobj)
329 return -EINVAL;
330 new_parent = kobject_get(new_parent);
331 if (!new_parent) {
332 error = -EINVAL;
333 goto out;
334 }
335 /* old object path */
336 devpath = kobject_get_path(kobj, GFP_KERNEL);
337 if (!devpath) {
338 error = -ENOMEM;
339 goto out;
340 }
341 devpath_string = kmalloc(strlen(devpath) + 15, GFP_KERNEL);
342 if (!devpath_string) {
343 error = -ENOMEM;
344 goto out;
345 }
346 sprintf(devpath_string, "DEVPATH_OLD=%s", devpath);
347 envp[0] = devpath_string;
348 envp[1] = NULL;
349 error = sysfs_move_dir(kobj, new_parent);
350 if (error)
351 goto out;
352 old_parent = kobj->parent;
353 kobj->parent = new_parent;
354 kobject_put(old_parent);
355 kobject_uevent_env(kobj, KOBJ_MOVE, envp);
356out:
357 kobject_put(kobj);
358 kfree(devpath_string);
359 kfree(devpath);
360 return error;
361}
362
363/**
313 * kobject_del - unlink kobject from hierarchy. 364 * kobject_del - unlink kobject from hierarchy.
314 * @kobj: object. 365 * @kobj: object.
315 */ 366 */
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 7f20e7b857cb..a1922765ff31 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -50,18 +50,22 @@ static char *action_to_string(enum kobject_action action)
50 return "offline"; 50 return "offline";
51 case KOBJ_ONLINE: 51 case KOBJ_ONLINE:
52 return "online"; 52 return "online";
53 case KOBJ_MOVE:
54 return "move";
53 default: 55 default:
54 return NULL; 56 return NULL;
55 } 57 }
56} 58}
57 59
58/** 60/**
59 * kobject_uevent - notify userspace by ending an uevent 61 * kobject_uevent_env - send an uevent with environmental data
60 * 62 *
61 * @action: action that is happening (usually KOBJ_ADD and KOBJ_REMOVE) 63 * @action: action that is happening (usually KOBJ_MOVE)
62 * @kobj: struct kobject that the action is happening to 64 * @kobj: struct kobject that the action is happening to
65 * @envp_ext: pointer to environmental data
63 */ 66 */
64void kobject_uevent(struct kobject *kobj, enum kobject_action action) 67void kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
68 char *envp_ext[])
65{ 69{
66 char **envp; 70 char **envp;
67 char *buffer; 71 char *buffer;
@@ -76,6 +80,7 @@ void kobject_uevent(struct kobject *kobj, enum kobject_action action)
76 char *seq_buff; 80 char *seq_buff;
77 int i = 0; 81 int i = 0;
78 int retval; 82 int retval;
83 int j;
79 84
80 pr_debug("%s\n", __FUNCTION__); 85 pr_debug("%s\n", __FUNCTION__);
81 86
@@ -134,7 +139,8 @@ void kobject_uevent(struct kobject *kobj, enum kobject_action action)
134 scratch += sprintf (scratch, "DEVPATH=%s", devpath) + 1; 139 scratch += sprintf (scratch, "DEVPATH=%s", devpath) + 1;
135 envp [i++] = scratch; 140 envp [i++] = scratch;
136 scratch += sprintf(scratch, "SUBSYSTEM=%s", subsystem) + 1; 141 scratch += sprintf(scratch, "SUBSYSTEM=%s", subsystem) + 1;
137 142 for (j = 0; envp_ext && envp_ext[j]; j++)
143 envp[i++] = envp_ext[j];
138 /* just reserve the space, overwrite it after kset call has returned */ 144 /* just reserve the space, overwrite it after kset call has returned */
139 envp[i++] = seq_buff = scratch; 145 envp[i++] = seq_buff = scratch;
140 scratch += strlen("SEQNUM=18446744073709551616") + 1; 146 scratch += strlen("SEQNUM=18446744073709551616") + 1;
@@ -200,6 +206,20 @@ exit:
200 kfree(envp); 206 kfree(envp);
201 return; 207 return;
202} 208}
209
210EXPORT_SYMBOL_GPL(kobject_uevent_env);
211
212/**
213 * kobject_uevent - notify userspace by ending an uevent
214 *
215 * @action: action that is happening (usually KOBJ_ADD and KOBJ_REMOVE)
216 * @kobj: struct kobject that the action is happening to
217 */
218void kobject_uevent(struct kobject *kobj, enum kobject_action action)
219{
220 kobject_uevent_env(kobj, action, NULL);
221}
222
203EXPORT_SYMBOL_GPL(kobject_uevent); 223EXPORT_SYMBOL_GPL(kobject_uevent);
204 224
205/** 225/**
diff --git a/lib/random32.c b/lib/random32.c
new file mode 100644
index 000000000000..4a15ce51cea7
--- /dev/null
+++ b/lib/random32.c
@@ -0,0 +1,142 @@
1/*
2 This is a maximally equidistributed combined Tausworthe generator
3 based on code from GNU Scientific Library 1.5 (30 Jun 2004)
4
5 x_n = (s1_n ^ s2_n ^ s3_n)
6
7 s1_{n+1} = (((s1_n & 4294967294) <<12) ^ (((s1_n <<13) ^ s1_n) >>19))
8 s2_{n+1} = (((s2_n & 4294967288) << 4) ^ (((s2_n << 2) ^ s2_n) >>25))
9 s3_{n+1} = (((s3_n & 4294967280) <<17) ^ (((s3_n << 3) ^ s3_n) >>11))
10
11 The period of this generator is about 2^88.
12
13 From: P. L'Ecuyer, "Maximally Equidistributed Combined Tausworthe
14 Generators", Mathematics of Computation, 65, 213 (1996), 203--213.
15
16 This is available on the net from L'Ecuyer's home page,
17
18 http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme.ps
19 ftp://ftp.iro.umontreal.ca/pub/simulation/lecuyer/papers/tausme.ps
20
21 There is an erratum in the paper "Tables of Maximally
22 Equidistributed Combined LFSR Generators", Mathematics of
23 Computation, 68, 225 (1999), 261--269:
24 http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme2.ps
25
26 ... the k_j most significant bits of z_j must be non-
27 zero, for each j. (Note: this restriction also applies to the
28 computer code given in [4], but was mistakenly not mentioned in
29 that paper.)
30
31 This affects the seeding procedure by imposing the requirement
32 s1 > 1, s2 > 7, s3 > 15.
33
34*/
35
36#include <linux/types.h>
37#include <linux/percpu.h>
38#include <linux/module.h>
39#include <linux/random.h>
40
41struct rnd_state {
42 u32 s1, s2, s3;
43};
44
45static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
46
47static u32 __random32(struct rnd_state *state)
48{
49#define TAUSWORTHE(s,a,b,c,d) ((s&c)<<d) ^ (((s <<a) ^ s)>>b)
50
51 state->s1 = TAUSWORTHE(state->s1, 13, 19, 4294967294UL, 12);
52 state->s2 = TAUSWORTHE(state->s2, 2, 25, 4294967288UL, 4);
53 state->s3 = TAUSWORTHE(state->s3, 3, 11, 4294967280UL, 17);
54
55 return (state->s1 ^ state->s2 ^ state->s3);
56}
57
58static void __set_random32(struct rnd_state *state, unsigned long s)
59{
60 if (s == 0)
61 s = 1; /* default seed is 1 */
62
63#define LCG(n) (69069 * n)
64 state->s1 = LCG(s);
65 state->s2 = LCG(state->s1);
66 state->s3 = LCG(state->s2);
67
68 /* "warm it up" */
69 __random32(state);
70 __random32(state);
71 __random32(state);
72 __random32(state);
73 __random32(state);
74 __random32(state);
75}
76
77/**
78 * random32 - pseudo random number generator
79 *
80 * A 32 bit pseudo-random number is generated using a fast
81 * algorithm suitable for simulation. This algorithm is NOT
82 * considered safe for cryptographic use.
83 */
84u32 random32(void)
85{
86 unsigned long r;
87 struct rnd_state *state = &get_cpu_var(net_rand_state);
88 r = __random32(state);
89 put_cpu_var(state);
90 return r;
91}
92EXPORT_SYMBOL(random32);
93
94/**
95 * srandom32 - add entropy to pseudo random number generator
96 * @seed: seed value
97 *
98 * Add some additional seeding to the random32() pool.
99 * Note: this pool is per cpu so it only affects current CPU.
100 */
101void srandom32(u32 entropy)
102{
103 struct rnd_state *state = &get_cpu_var(net_rand_state);
104 __set_random32(state, state->s1 ^ entropy);
105 put_cpu_var(state);
106}
107EXPORT_SYMBOL(srandom32);
108
109/*
110 * Generate some initially weak seeding values to allow
111 * to start the random32() engine.
112 */
113static int __init random32_init(void)
114{
115 int i;
116
117 for_each_possible_cpu(i) {
118 struct rnd_state *state = &per_cpu(net_rand_state,i);
119 __set_random32(state, i + jiffies);
120 }
121 return 0;
122}
123core_initcall(random32_init);
124
125/*
126 * Generate better values after random number generator
127 * is fully initalized.
128 */
129static int __init random32_reseed(void)
130{
131 int i;
132 unsigned long seed;
133
134 for_each_possible_cpu(i) {
135 struct rnd_state *state = &per_cpu(net_rand_state,i);
136
137 get_random_bytes(&seed, sizeof(seed));
138 __set_random32(state, seed);
139 }
140 return 0;
141}
142late_initcall(random32_reseed);
diff --git a/lib/rwsem-spinlock.c b/lib/rwsem-spinlock.c
index db4fed74b940..c4cfd6c0342f 100644
--- a/lib/rwsem-spinlock.c
+++ b/lib/rwsem-spinlock.c
@@ -28,7 +28,7 @@ void __init_rwsem(struct rw_semaphore *sem, const char *name,
28 * Make sure we are not reinitializing a held semaphore: 28 * Make sure we are not reinitializing a held semaphore:
29 */ 29 */
30 debug_check_no_locks_freed((void *)sem, sizeof(*sem)); 30 debug_check_no_locks_freed((void *)sem, sizeof(*sem));
31 lockdep_init_map(&sem->dep_map, name, key); 31 lockdep_init_map(&sem->dep_map, name, key, 0);
32#endif 32#endif
33 sem->activity = 0; 33 sem->activity = 0;
34 spin_lock_init(&sem->wait_lock); 34 spin_lock_init(&sem->wait_lock);
diff --git a/lib/rwsem.c b/lib/rwsem.c
index 901d0e7da892..cdb4e3d05607 100644
--- a/lib/rwsem.c
+++ b/lib/rwsem.c
@@ -19,7 +19,7 @@ void __init_rwsem(struct rw_semaphore *sem, const char *name,
19 * Make sure we are not reinitializing a held semaphore: 19 * Make sure we are not reinitializing a held semaphore:
20 */ 20 */
21 debug_check_no_locks_freed((void *)sem, sizeof(*sem)); 21 debug_check_no_locks_freed((void *)sem, sizeof(*sem));
22 lockdep_init_map(&sem->dep_map, name, key); 22 lockdep_init_map(&sem->dep_map, name, key, 0);
23#endif 23#endif
24 sem->count = RWSEM_UNLOCKED_VALUE; 24 sem->count = RWSEM_UNLOCKED_VALUE;
25 spin_lock_init(&sem->wait_lock); 25 spin_lock_init(&sem->wait_lock);
diff --git a/lib/spinlock_debug.c b/lib/spinlock_debug.c
index dafaf1de2491..b6c4f898197c 100644
--- a/lib/spinlock_debug.c
+++ b/lib/spinlock_debug.c
@@ -20,7 +20,7 @@ void __spin_lock_init(spinlock_t *lock, const char *name,
20 * Make sure we are not reinitializing a held lock: 20 * Make sure we are not reinitializing a held lock:
21 */ 21 */
22 debug_check_no_locks_freed((void *)lock, sizeof(*lock)); 22 debug_check_no_locks_freed((void *)lock, sizeof(*lock));
23 lockdep_init_map(&lock->dep_map, name, key); 23 lockdep_init_map(&lock->dep_map, name, key, 0);
24#endif 24#endif
25 lock->raw_lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; 25 lock->raw_lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
26 lock->magic = SPINLOCK_MAGIC; 26 lock->magic = SPINLOCK_MAGIC;
@@ -38,7 +38,7 @@ void __rwlock_init(rwlock_t *lock, const char *name,
38 * Make sure we are not reinitializing a held lock: 38 * Make sure we are not reinitializing a held lock:
39 */ 39 */
40 debug_check_no_locks_freed((void *)lock, sizeof(*lock)); 40 debug_check_no_locks_freed((void *)lock, sizeof(*lock));
41 lockdep_init_map(&lock->dep_map, name, key); 41 lockdep_init_map(&lock->dep_map, name, key, 0);
42#endif 42#endif
43 lock->raw_lock = (raw_rwlock_t) __RAW_RW_LOCK_UNLOCKED; 43 lock->raw_lock = (raw_rwlock_t) __RAW_RW_LOCK_UNLOCKED;
44 lock->magic = RWLOCK_MAGIC; 44 lock->magic = RWLOCK_MAGIC;
diff --git a/lib/string.c b/lib/string.c
index 63077267367e..a485d75962af 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -320,7 +320,7 @@ char *strstrip(char *s)
320 return s; 320 return s;
321 321
322 end = s + size - 1; 322 end = s + size - 1;
323 while (end != s && isspace(*end)) 323 while (end >= s && isspace(*end))
324 end--; 324 end--;
325 *(end + 1) = '\0'; 325 *(end + 1) = '\0';
326 326
diff --git a/lib/textsearch.c b/lib/textsearch.c
index 2cb4a437942e..98bcadc01185 100644
--- a/lib/textsearch.c
+++ b/lib/textsearch.c
@@ -40,7 +40,7 @@
40 * configuration according to the specified parameters. 40 * configuration according to the specified parameters.
41 * (3) User starts the search(es) by calling _find() or _next() to 41 * (3) User starts the search(es) by calling _find() or _next() to
42 * fetch subsequent occurrences. A state variable is provided 42 * fetch subsequent occurrences. A state variable is provided
43 * to the algorihtm to store persistant variables. 43 * to the algorihtm to store persistent variables.
44 * (4) Core eventually resets the search offset and forwards the find() 44 * (4) Core eventually resets the search offset and forwards the find()
45 * request to the algorithm. 45 * request to the algorithm.
46 * (5) Algorithm calls get_next_block() provided by the user continously 46 * (5) Algorithm calls get_next_block() provided by the user continously