Subject: Re: [PATCH] [2.6.22] pasemi: hardware rng driver

From: [email-masked] (Olof Johansson)
Date: Thu, 26 Apr 2007 15:46:34 -0500

Hi Michael,

All good points, fixed in v3 (posted shortly).

Thanks,

-Olof

On Thu, Apr 26, 2007 at 11:22:03AM +0200, Michael Buesch wrote:
> 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.