Re: [PATCH/RFC] core: add a function to safely try to get device driver owner

Greg KH
2010-11-30T21:05:13Z

On Tue, Nov 30, 2010 at 09:43:09PM +0100, Laurent Pinchart wrote:
> > > The way we deal with this is to try_module_get() on the OMAP3 ISP driver
> > > in the subdev open() handlers. I'm of course opened to alternatives.
> >
> > Do it like the rest of the kernel does it, lock the module in place with
> > the module pointer it passed to you before calling open in that module.
> > Nothing new here at all.
>
> That doesn't work in this case, because we have two modules. Module A is the
> master and instantiates an I2C device handled by module B. Module B creates a
> character device and sets itself as the owner. When the corresponding device
> node is opened, module B's refcount is incremented, but module A refcount
> isn't, even though module B can call to module A through board code using
> function pointers provided in the platform data.

Again, this is something we have been doing for years just fine. Look
at the usb-serial core. It "owns" the device node yet the child drivers
are the ones actually handling the data.

Just never call the function pointer unless the module is loaded, it's
that simple. If you need to add proper module ownership to the platform
data pointers, so be it.

thanks,

greg k-h