mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH akpm-next] random32: minor cleanups and kdoc fix
@ 2014-02-12 22:43 Daniel Borkmann
  2014-02-12 23:43 ` Joe Perches
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Borkmann @ 2014-02-12 22:43 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel

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. random_get_entropy() results mostly into get_cycles()
which returns unsigned long whereas seed is given in u32. Last
but not least for readability, add some newlines.

Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
---
 lib/random32.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/lib/random32.c b/lib/random32.c
index 1e5b2df..82e22a3 100644
--- a/lib/random32.c
+++ b/lib/random32.c
@@ -30,7 +30,6 @@
 
    This affects the seeding procedure by imposing the requirement
    s1 > 1, s2 > 7, s3 > 15, s4 > 127.
-
 */
 
 #include <linux/types.h>
@@ -75,15 +74,17 @@ EXPORT_SYMBOL(prandom_u32_state);
  */
 u32 prandom_u32(void)
 {
-	unsigned long r;
 	struct rnd_state *state = &get_cpu_var(net_rand_state);
-	r = prandom_u32_state(state);
+	u32 res;
+
+	res = prandom_u32_state(state);
 	put_cpu_var(state);
-	return r;
+
+	return res;
 }
 EXPORT_SYMBOL(prandom_u32);
 
-/*
+/**
  *	prandom_bytes_state - get the requested number of pseudo-random bytes
  *
  *	@state: pointer to state structure holding seeded state.
@@ -201,9 +202,10 @@ static int __init prandom_init(void)
 	for_each_possible_cpu(i) {
 		struct rnd_state *state = &per_cpu(net_rand_state,i);
 
-		prandom_seed_very_weak(state, (i + jiffies) ^ random_get_entropy());
+		prandom_seed_very_weak(state, (i + jiffies) ^ (u32)random_get_entropy());
 		prandom_warmup(state);
 	}
+
 	return 0;
 }
 core_initcall(prandom_init);
@@ -248,6 +250,7 @@ static void __prandom_reseed(bool late)
 	spin_lock_irqsave(&lock, flags);
 	if (latch && !late)
 		goto out;
+
 	latch = true;
 
 	for_each_possible_cpu(i) {
-- 
1.7.11.7


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH akpm-next] random32: minor cleanups and kdoc fix
  2014-02-12 22:43 [PATCH akpm-next] random32: minor cleanups and kdoc fix Daniel Borkmann
@ 2014-02-12 23:43 ` Joe Perches
  0 siblings, 0 replies; 2+ messages in thread
From: Joe Perches @ 2014-02-12 23:43 UTC (permalink / raw)
  To: Daniel Borkmann; +Cc: akpm, linux-kernel

On Wed, 2014-02-12 at 23:43 +0100, Daniel Borkmann wrote:
> These are just some very minor and misc cleanups in the PRNG.

trivia:

> diff --git a/lib/random32.c b/lib/random32.c
[]
> @@ -30,7 +30,6 @@
>  
>     This affects the seeding procedure by imposing the requirement
>     s1 > 1, s2 > 7, s3 > 15, s4 > 127.
> -
>  */

Using normal comment block style

	/*
	 *
	 */

might be nicer
 
>  #include <linux/types.h>
> @@ -75,15 +74,17 @@ EXPORT_SYMBOL(prandom_u32_state);
>   */
>  u32 prandom_u32(void)
>  {
> -	unsigned long r;
>  	struct rnd_state *state = &get_cpu_var(net_rand_state);
> -	r = prandom_u32_state(state);
> +	u32 res;
> +
> +	res = prandom_u32_state(state);

Maybe:

	u32 res = prandom_u32_state(state);

> @@ -201,9 +202,10 @@ static int __init prandom_init(void)
>  	for_each_possible_cpu(i) {
>  		struct rnd_state *state = &per_cpu(net_rand_state,i);
>  
> -		prandom_seed_very_weak(state, (i + jiffies) ^ random_get_entropy());
> +		prandom_seed_very_weak(state, (i + jiffies) ^ (u32)random_get_entropy());

This (u32) cast is not necessary.

On 64 bit machines, the high 32 bits of random_get_entropy
are unnecessarily dropped/masked.

The compiler will cast the unsigned long result of the xor
back to u32 anyway.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-02-12 23:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-12 22:43 [PATCH akpm-next] random32: minor cleanups and kdoc fix Daniel Borkmann
2014-02-12 23:43 ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®