Re: [PATCH] hwrng: core - allocate a one page buffer
From: Herbert Xu
Date: Thu Aug 20 2020 - 23:42:20 EST
On Thu, Aug 06, 2020 at 05:28:14PM +0200, Laurent Vivier wrote:
.
> +static size_t rng_max_buffer_size(struct hwrng *rng)
> +{
> + size_t size;
> +
> + size = max_t(size_t, rng->buffer_size, SMP_CACHE_BYTES);
> +
> + /* rng_buffer can store up to PAGE_SIZE */
> + return min(PAGE_SIZE, size);
> }
Rather than checking this on every read, just do it once at driver
registration time.
> @@ -614,11 +629,11 @@ static int __init hwrng_modinit(void)
> int ret;
>
> /* kmalloc makes this safe for virt_to_page() in virtio_rng.c */
> - rng_buffer = kmalloc(rng_buffer_size(), GFP_KERNEL);
> + rng_buffer = (u8 *)get_zeroed_page(GFP_KERNEL);
> if (!rng_buffer)
> return -ENOMEM;
Why a zeroed page? Also please fix the out-of-sync comment.
Thanks,
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt