On Mon, May 07, 2012 at 09:26:07AM +0200, Samuel Iglesias Gonsalvez wrote:
> +int ipack_bus_register(struct ipack_bus_device *bus)
> +{
> + int bus_nr;
Blank line here between declaration and code.
> + bus_nr = ipack_assign_bus_number();
> + if (bus_nr < 0)
> + return -1;
> + bus->bus_nr = bus_nr;
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(ipack_bus_register);
[snip]
> +int ipack_driver_register(struct ipack_driver *edrv)
> +{
> + int ret;
> +
> + edrv->driver.bus = &ipack_bus_type;
> + ret = driver_register(&edrv->driver);
> + if (ret < 0)
> + goto exit_driver_register;
> +
> +exit_driver_register:
> + return ret;
> +}
Better to write it like this:
int ipack_driver_register(struct ipack_driver *edrv)
{
edrv->driver.bus = &ipack_bus_type;
return driver_register(&edrv->driver);
}
[snip]
> +int ipack_device_find_drv(struct device_driver *driver, void *param)
> +{
> + int ret;
> + struct ipack_device *dev = (struct ipack_device *)param;
> +
> + ret = ipack_bus_match(&dev->dev, driver);
> + if (ret)
> + return !ipack_bus_probe(&dev->dev);
Wouldn't probe() return zero or a negative error code?
> +
> + return ret;
return 0;
> +}
> +
> +int ipack_device_register(struct ipack_device *dev)
> +{
> + int ret;
> +
> + if (!bus_for_each_drv(&ipack_bus_type, NULL, dev, ipack_device_find_drv)) {
> + ret = -ENODEV;
> + goto exit_device_register;
Just return directly here. I was expecting a reason for a goto but
a nonsense goto is misleading.
> + }
> +
> + dev->dev.bus = &ipack_bus_type;
> + dev->dev.release = ipack_device_release;
> + dev_set_name(&dev->dev, "%s.%u.%u", dev->board_name, dev->bus_nr, dev->slot);
> + ret = device_register(&dev->dev);
> + if (ret < 0) {
> + printk(KERN_ERR "ipack: error registering the device.\n");
> + dev->driver->ops->remove(dev);
> + }
> +
> +exit_device_register:
> + return ret;
> +}
regards,
dan carpenter
On Mon, 2012-05-07 at 11:04 +0300, Dan Carpenter wrote:
>
> [snip]
>
> > +int ipack_device_find_drv(struct device_driver *driver, void *param)
> > +{
> > + int ret;
> > + struct ipack_device *dev = (struct ipack_device *)param;
> > +
> > + ret = ipack_bus_match(&dev->dev, driver);
> > + if (ret)
> > + return !ipack_bus_probe(&dev->dev);
>
> Wouldn't probe() return zero or a negative error code?
Yes. However, in case of the function called by bus_for_each_drv(), it
should return zero if you want to continue or nonzero value to stop the
iteration.
I considered that if the probe fails, we can try with the next driver in
the list. So, the returned value of probe() is negated.
I will fix the other things and send it again with other suggestions.
Thanks,
Sam
On Mon, 2012-05-07 at 10:24 +0200, Samuel Iglesias Gonsálvez wrote:
> On Mon, 2012-05-07 at 11:04 +0300, Dan Carpenter wrote:
> >
> > [snip]
> >
> > > +int ipack_device_find_drv(struct device_driver *driver, void *param)
> > > +{
> > > + int ret;
> > > + struct ipack_device *dev = (struct ipack_device *)param;
> > > +
> > > + ret = ipack_bus_match(&dev->dev, driver);
> > > + if (ret)
> > > + return !ipack_bus_probe(&dev->dev);
> >
> > Wouldn't probe() return zero or a negative error code?
>
> Yes. However, in case of the function called by bus_for_each_drv(), it
> should return zero if you want to continue or nonzero value to stop the
> iteration.
>
> I considered that if the probe fails, we can try with the next driver in
> the list. So, the returned value of probe() is negated.
Checking the device_register() function, it actually does the same I am
trying to do here: call the bus' match() function with each driver
registered on the bus searching which one can manage the device, and
then call the probe().
So I can delete this function safely and bus_for_each_drv() in
ipack_device_register().
Thanks,
Sam