From nobody@FreeBSD.org  Mon Nov  7 05:46:38 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id D331E106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  7 Nov 2011 05:46:38 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id C34F38FC14
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  7 Nov 2011 05:46:38 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id pA75kcZw093308
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 7 Nov 2011 05:46:38 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id pA75kcDd093307;
	Mon, 7 Nov 2011 05:46:38 GMT
	(envelope-from nobody)
Message-Id: <201111070546.pA75kcDd093307@red.freebsd.org>
Date: Mon, 7 Nov 2011 05:46:38 GMT
From: Ivan Klymenko <fidaj@ukr.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] remove the extra variable in /sys/libkern/random.c
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         162347
>Category:       kern
>Synopsis:       [kernel] [patch] remove the extra variable in /sys/libkern/random.c
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    stas
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Nov 07 05:50:12 UTC 2011
>Closed-Date:    
>Last-Modified:  Fri Aug 02 06:46:52 UTC 2013
>Originator:     Ivan Klymenko
>Release:        FreeBSD 10.0-CURRENT amd64
>Organization:
individual
>Environment:
FreeBSD nonamehost 9.9-CURRENT FreeBSD 9.9-CURRENT #0 r227075M: Sat Nov  5 16:13:18 EET 2011     ivan@nonamehost:/usr/obj/usr/src/sys/mk9  amd64
>Description:
remove the extra variable.
variable "x" is not needed.
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

--- ./sys/libkern/random.c.orig	2011-11-05 15:36:23.000000000 +0200
+++ ./sys/libkern/random.c	2011-11-05 15:40:18.000000000 +0200
@@ -57,19 +57,19 @@
 u_long
 random()
 {
-	register long x, hi, lo, t;
+	register long hi, lo, t;
 
 	/*
-	 * Compute x[n + 1] = (7^5 * x[n]) mod (2^31 - 1).
+	 * Compute randseed[n + 1] = (7^5 * randseed[n]) mod (2^31 - 1).
 	 * From "Random number generators: good ones are hard to find",
 	 * Park and Miller, Communications of the ACM, vol. 31, no. 10,
 	 * October 1988, p. 1195.
 	 */
 	/* Can't be initialized with 0, so use another value. */
-	if ((x = randseed) == 0)
-		x = 123459876;
-	hi = x / 127773;
-	lo = x % 127773;
+	if (randseed == 0)
+		randseed = 123459876;
+	hi = randseed / 127773;
+	lo = randseed % 127773;
 	t = 16807 * lo - 2836 * hi;
 	if (t < 0)
 		t += 0x7fffffff;


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->secteam 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Tue Nov 15 01:48:34 UTC 2011 
Responsible-Changed-Why:  
secteam needs to approve changes to random 

http://www.freebsd.org/cgi/query-pr.cgi?pr=162347 

From: Stanislav Sedov <stas@FreeBSD.org>
To: Ivan Klymenko <fidaj@ukr.net>
Cc: FreeBSD PR followup <bug-followup@FreeBSD.org>
Subject: Re: kern/162347: [kernel] [patch] remove the extra variable in
 /sys/libkern/random.c
Date: Mon, 14 Nov 2011 18:59:28 -0800

 Hi!
 
 I'm not sure this change is entirely a no-op.
 In the old code the x is a signed variable, while the randseed is unsigned
 so the calculation that follows may give a different result under different
 conditions.  Also, in the old code the randseed is being updated only at the
 end of the function thus making it behave differently when being used in a
 multithreaded code (though I'm not sure there're any parts of the kernel that
 can call this functions from the other threads).
 
 We need to make sure that the change won't break the random generator in some
 unexpected way.
 
 As a side note, I think that the "register" modifier can be dropped.
 
 -- 
 Stanislav Sedov
 ST4096-RIPE
 
 ()  ascii ribbon campaign - against html e-mail 
 /\  www.asciiribbon.org   - against proprietary attachments
Responsible-Changed-From-To: secteam->stats 
Responsible-Changed-By: remko 
Responsible-Changed-When: Thu Aug 1 20:23:41 UTC 2013 
Responsible-Changed-Why:  
Hi Stanislav, can you look into this once more and decide whether we 
should keep the PR open or close it if needed? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=162347 
Responsible-Changed-From-To: stats->stas 
Responsible-Changed-By: remko 
Responsible-Changed-When: Fri Aug 2 06:46:40 UTC 2013 
Responsible-Changed-Why:  
stats != stas 

http://www.freebsd.org/cgi/query-pr.cgi?pr=162347 
>Unformatted:
