[PATCH] [2.6.22] pasemi: hardware rng driver

Michael Buesch mb at bu3sch.de
Thu Apr 26 19:22:03 EST 2007


On Wednesday 25 April 2007 22:45:12 Olof Johansson wrote:
> +static int __devinit rng_probe(struct of_device *ofdev,
> +				     const struct of_device_id *match)
> +{
> +	struct device_node *rng_np;
> +	struct resource res;
> +	int err = 0;
> +
> +	rng_np = of_find_compatible_node(NULL, "rng", "1682m-rng");
> +	if (!rng_np)
> +		return -ENODEV;
> +
> +	err = of_address_to_resource(rng_np, 0, &res);
> +	of_node_put(rng_np);
> +
> +	if (err)
> +		return -EINVAL;

I think EINVAL is not the correct error code. I'd suggest ENODEV.

> +	if (!rng_regs)
> +		rng_regs = ioremap(res.start, 0x100);
> +
> +	if (!rng_regs)
> +		return -EPERM;

I think EPERM is not the correct error code. I'd suggest ENOMEM.

> +	printk(KERN_INFO "Registering PA Semi RNG\n");
> +
> +	return hwrng_register(&pasemi_rng);

Resource leak.
Please do something like

	err = hwrng_register(&pasemi_rng);
	if (err)
		iounmap(rng_regs);
	return err;

> +}
> +
> +static int rng_remove(struct of_device *dev)
> +{
> +	iounmap(rng_regs);
> +	hwrng_unregister(&pasemi_rng);

Swap these to prevent race conditions.

> +
> +	return 0;
> +}



-- 
Greetings Michael.



More information about the Linuxppc-dev mailing list