Re: [PATCH] hwrng: core - Allocate memory during module init

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Sep 04, 2016 at 01:59:38PM +0530, PrasannaKumar Muralidharan wrote:
>
> @@ -573,6 +557,17 @@ EXPORT_SYMBOL_GPL(devm_hwrng_unregister);
>  
>  static int __init hwrng_modinit(void)
>  {
> +	/* kmalloc makes this safe for virt_to_page() in virtio_rng.c */
> +	rng_buffer = kmalloc(rng_buffer_size(), GFP_KERNEL);
> +	if (!rng_buffer)
> +		return -ENOMEM;
> +
> +	rng_fillbuf = kmalloc(rng_buffer_size(), GFP_KERNEL);
> +	if (!rng_fillbuf) {
> +		kfree(rng_buffer);
> +		return -ENOMEM;
> +	}
> +
>  	return register_miscdev();

You're leaking memory if register_miscdev fails.

Cheers,
-- 
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]

  Powered by Linux