crypto: jitter - Use min() to simplify jent_read_entropy()
authorThorsten Blum <thorsten.blum@toblux.com>
Mon, 19 Aug 2024 14:18:44 +0000 (16:18 +0200)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 30 Aug 2024 10:22:30 +0000 (18:22 +0800)
Use the min() macro to simplify the jent_read_entropy() function and
improve its readability.

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/jitterentropy.c

index d7056de..3b390bd 100644 (file)
@@ -146,6 +146,7 @@ struct rand_data {
 #define JENT_ENTROPY_SAFETY_FACTOR     64
 
 #include <linux/fips.h>
+#include <linux/minmax.h>
 #include "jitterentropy.h"
 
 /***************************************************************************
@@ -638,10 +639,7 @@ int jent_read_entropy(struct rand_data *ec, unsigned char *data,
                        return -2;
                }
 
-               if ((DATA_SIZE_BITS / 8) < len)
-                       tocopy = (DATA_SIZE_BITS / 8);
-               else
-                       tocopy = len;
+               tocopy = min(DATA_SIZE_BITS / 8, len);
                if (jent_read_random_block(ec->hash_state, p, tocopy))
                        return -1;