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

lib/random32.c: minor cleanups and kdoc fix

These are just some very minor and misc cleanups in the PRNG. In
prandom_u32() we store the result in an unsigned long which is
unnecessary as it should be u32 instead that we get from
prandom_u32_state(). prandom_bytes_state()'s comment is in kdoc format,
so change it into such as it's done everywhere else. Also, use the
normal comment style for the header comment. Last but not least for
readability, add some newlines.

Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Daniel Borkmann and committed by
Linus Torvalds
d3d47eb2 b104d6a5

+39 -37
+39 -37
lib/random32.c
··· 1 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 - lfsr113 version: 6 - 7 - x_n = (s1_n ^ s2_n ^ s3_n ^ s4_n) 8 - 9 - s1_{n+1} = (((s1_n & 4294967294) << 18) ^ (((s1_n << 6) ^ s1_n) >> 13)) 10 - s2_{n+1} = (((s2_n & 4294967288) << 2) ^ (((s2_n << 2) ^ s2_n) >> 27)) 11 - s3_{n+1} = (((s3_n & 4294967280) << 7) ^ (((s3_n << 13) ^ s3_n) >> 21)) 12 - s4_{n+1} = (((s4_n & 4294967168) << 13) ^ (((s4_n << 3) ^ s4_n) >> 12)) 13 - 14 - The period of this generator is about 2^113 (see erratum paper). 15 - 16 - From: P. L'Ecuyer, "Maximally Equidistributed Combined Tausworthe 17 - Generators", Mathematics of Computation, 65, 213 (1996), 203--213: 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, s4 > 127. 33 - 34 - */ 2 + * This is a maximally equidistributed combined Tausworthe generator 3 + * based on code from GNU Scientific Library 1.5 (30 Jun 2004) 4 + * 5 + * lfsr113 version: 6 + * 7 + * x_n = (s1_n ^ s2_n ^ s3_n ^ s4_n) 8 + * 9 + * s1_{n+1} = (((s1_n & 4294967294) << 18) ^ (((s1_n << 6) ^ s1_n) >> 13)) 10 + * s2_{n+1} = (((s2_n & 4294967288) << 2) ^ (((s2_n << 2) ^ s2_n) >> 27)) 11 + * s3_{n+1} = (((s3_n & 4294967280) << 7) ^ (((s3_n << 13) ^ s3_n) >> 21)) 12 + * s4_{n+1} = (((s4_n & 4294967168) << 13) ^ (((s4_n << 3) ^ s4_n) >> 12)) 13 + * 14 + * The period of this generator is about 2^113 (see erratum paper). 15 + * 16 + * From: P. L'Ecuyer, "Maximally Equidistributed Combined Tausworthe 17 + * Generators", Mathematics of Computation, 65, 213 (1996), 203--213: 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 Equidistributed 22 + * Combined LFSR Generators", Mathematics of Computation, 68, 225 (1999), 23 + * 261--269: http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme2.ps 24 + * 25 + * ... the k_j most significant bits of z_j must be non-zero, 26 + * for each j. (Note: this restriction also applies to the 27 + * computer code given in [4], but was mistakenly not mentioned 28 + * in that paper.) 29 + * 30 + * This affects the seeding procedure by imposing the requirement 31 + * s1 > 1, s2 > 7, s3 > 15, s4 > 127. 32 + */ 35 33 36 34 #include <linux/types.h> 37 35 #include <linux/percpu.h> ··· 73 75 */ 74 76 u32 prandom_u32(void) 75 77 { 76 - unsigned long r; 77 78 struct rnd_state *state = &get_cpu_var(net_rand_state); 78 - r = prandom_u32_state(state); 79 + u32 res; 80 + 81 + res = prandom_u32_state(state); 79 82 put_cpu_var(state); 80 - return r; 83 + 84 + return res; 81 85 } 82 86 EXPORT_SYMBOL(prandom_u32); 83 87 84 - /* 88 + /** 85 89 * prandom_bytes_state - get the requested number of pseudo-random bytes 86 90 * 87 91 * @state: pointer to state structure holding seeded state. ··· 204 204 prandom_seed_very_weak(state, (i + jiffies) ^ random_get_entropy()); 205 205 prandom_warmup(state); 206 206 } 207 + 207 208 return 0; 208 209 } 209 210 core_initcall(prandom_init); ··· 260 259 261 260 if (latch && !late) 262 261 goto out; 262 + 263 263 latch = true; 264 264 265 265 for_each_possible_cpu(i) {