Re: Incorrect uses of get_driver()/put_driver()

From: Alan Stern
Date: Mon Jan 09 2012 - 14:36:32 EST


On Mon, 9 Jan 2012, Dmitry Torokhov wrote:

> > > > > lib/dma-debug.c:173: drv = get_driver(dev->driver);
> > > > > lib/dma-debug.c:188: put_driver(drv);
> > > > >
> > > > > Joerg, these calls don't seem to do anything, as far as I can tell.
> > > > > Is there any reason to keep them?
> > > > >
> > > > > drivers/pci/xen-pcifront.c:596: if (get_driver(&pdrv->driver)) {
> > > > > drivers/pci/xen-pcifront.c:626: put_driver(&pdrv->driver);
> > > > >
> > > > > Konrad, these calls don't seem to do anything either.
> > > > >
> > > >
> > > > Looks like they should be replaced with the try_module_get() equivalant
> > > > for the 'struct pci_driver'? Is there such one?
> > >
> > > You seem to need stronger guarantees that the driver simply present in
> > > memory. You need to make sure that the driver you fetched is kept being
> > > bound to the device for entire duration of pcifront_common_process().
> >
> > OK, any suggestions?
>
> Nothing canned I'm afraid...

device_lock(&pcidev->dev) will block unbinding. If you take the lock
before looking at pcidev->driver, it should be okay.

The drawback is that pdrv->error_handler may end up doing something
that takes the same lock. If you can verify that won't happen, there
won't be any problem.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/