git: 8553976d35dd - stable/12 - random/ivy: Trivial refactoring

From: David E. O'Brien <obrien_at_FreeBSD.org>
Date: Mon, 21 Feb 2022 08:07:46 UTC
The branch stable/12 has been updated by obrien:

URL: https://cgit.FreeBSD.org/src/commit/?id=8553976d35ddd877fc3193447a643dbf87ced827

commit 8553976d35ddd877fc3193447a643dbf87ced827
Author:     Conrad Meyer <cem@FreeBSD.org>
AuthorDate: 2019-11-20 19:55:43 +0000
Commit:     David E. O'Brien <obrien@FreeBSD.org>
CommitDate: 2022-02-21 05:56:43 +0000

    random/ivy: Trivial refactoring
    
    It is clearer to me to return success/error (true/false) instead of some
    retry count linked to the inline assembly implementation.
    
    No functional change.
    
    (cherry picked from commit c41faf5591bdda3556d7616913381e98109bff15)
---
 sys/dev/random/ivy.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/sys/dev/random/ivy.c b/sys/dev/random/ivy.c
index e45e6a2d1242..a33e6bb63327 100644
--- a/sys/dev/random/ivy.c
+++ b/sys/dev/random/ivy.c
@@ -59,7 +59,7 @@ static struct random_source random_ivy = {
 	.rs_read = random_ivy_read
 };
 
-static int
+static bool
 x86_rdrand_store(u_long *buf)
 {
 	u_long rndval;
@@ -75,10 +75,10 @@ x86_rdrand_store(u_long *buf)
 	    "2:"
 	    : "+r" (retry), "=r" (rndval) : : "cc");
 	*buf = rndval;
-	return (retry);
+	return (retry != 0);
 }
 
-static int
+static bool
 x86_rdseed_store(u_long *buf)
 {
 	u_long rndval;
@@ -94,17 +94,17 @@ x86_rdseed_store(u_long *buf)
 	    "2:"
 	    : "+r" (retry), "=r" (rndval) : : "cc");
 	*buf = rndval;
-	return (retry);
+	return (retry != 0);
 }
 
-static int
+static bool
 x86_unimpl_store(u_long *buf __unused)
 {
 
 	panic("%s called", __func__);
 }
 
-DEFINE_IFUNC(static, int, x86_rng_store, (u_long *buf), static)
+DEFINE_IFUNC(static, bool, x86_rng_store, (u_long *buf), static)
 {
 	has_rdrand = (cpu_feature2 & CPUID2_RDRAND);
 	has_rdseed = (cpu_stdext_feature & CPUID_STDEXT_RDSEED);
@@ -127,7 +127,7 @@ random_ivy_read(void *buf, u_int c)
 	KASSERT(c % sizeof(*b) == 0, ("partial read %d", c));
 	b = buf;
 	for (count = c; count > 0; count -= sizeof(*b)) {
-		if (x86_rng_store(&rndval) == 0)
+		if (!x86_rng_store(&rndval))
 			break;
 		*b++ = rndval;
 	}