[PATCHv2] hw_random: add driver for atmel true hardware random number generator

Baruch Siach baruch at tkos.co.il
Thu Oct 6 16:30:23 EDT 2011


Hi Peter,

On Thu, Oct 06, 2011 at 07:56:30PM +0200, Peter Korsgaard wrote:
> For the IP block on 9g45/9g46/9m10/9m11.
> 
> Signed-off-by: Peter Korsgaard <jacmet at sunsite.dk>
> ---

[snip]

> +static int atmel_trng_read(struct hwrng *rng, void *buf, size_t max,
> +			   bool wait)
> +{
> +	struct atmel_trng *trng = container_of(rng, struct atmel_trng, rng);
> +	u32 *data = buf;
> +
> +	/* data ready? */
> +	if (readl(trng->base + TRNG_ODATA) & 1) {
> +		*data = readl(trng->base + TRNG_ODATA);
> +		return 4;

Shouldn't you check for max >= 4 before writing to *buf?

> +	} else
> +		return 0;
> +}

baruch

-- 
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -



More information about the linux-arm-kernel mailing list