Re: [PATCH v2] random: make more consistent use of integer types

From: Eric Biggers
Date: Sun Feb 20 2022 - 22:54:02 EST


This looks good in general, but a few comments below.

On Wed, Feb 09, 2022 at 07:05:07PM +0100, Jason A. Donenfeld wrote:
> Cc: Theodore Ts'o <tytso@xxxxxxx>
> Cc: Dominik Brodowski <linux@xxxxxxxxxxxxxxxxxxxx>
> Reviewed-by: Jann Horn <jannh@xxxxxxxxxx>
> Signed-off-by: Jason A. Donenfeld <Jason@xxxxxxxxx>
> -static void _mix_pool_bytes(const void *in, int nbytes)
> +static void _mix_pool_bytes(const void *in, size_t nbytes)
> {
> blake2s_update(&input_pool.hash, in, nbytes);
> }
>
> -static void mix_pool_bytes(const void *in, int nbytes)
> +static void mix_pool_bytes(const void *in, size_t nbytes)

The committed version of this patch removes the __mix_pool_bytes() function as
well, and it's not clear how it is related to the rest of the patch. Perhaps
that part belongs in the patch that removes all the tracepoints?

> -static size_t crng_fast_load(const u8 *cp, size_t len)
> +static size_t crng_fast_load(const void *cp, size_t len)
> {
> unsigned long flags;
> - u8 *p;
> + u8 *src = (u8 *)cp;

This should use 'const u8 *'.

> int __init rand_initialize(void)
> {
> - int i;
> + size_t i;
> ktime_t now = ktime_get_real();

This introduces an assumption that BLAKE2S_BLOCK_SIZE % sizeof(unsigned long) ==
0. That happens to always be true, but it would be better to either not change
this, or rewrite the loop to 'i = 0; i < BLAKE2S_BLOCK_SIZE; i += sizeof(rv)'

- Eric