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

From: Greg KH
Date: Tue Nov 30 2010 - 11:56:48 EST


On Tue, Nov 30, 2010 at 12:11:42AM +0100, Guennadi Liakhovetski wrote:
> On Mon, 29 Nov 2010, Greg KH wrote:
>
> > On Mon, Nov 29, 2010 at 11:10:50PM +0100, Guennadi Liakhovetski wrote:
> > > On Mon, 29 Nov 2010, Greg KH wrote:
> > >
> > > > On Mon, Nov 29, 2010 at 09:54:10PM +0100, Guennadi Liakhovetski wrote:
> > > > > Hi Jon
> > > > >
> > > > > On Mon, 29 Nov 2010, Jonathan Corbet wrote:
> > > > >
> > > > > > On Mon, 29 Nov 2010 20:43:28 +0100 (CET)
> > > > > > Guennadi Liakhovetski <g.liakhovetski@xxxxxx> wrote:
> > > > > >
> > > > > > > When two drivers interoperate without an explicit dependency, it is often
> > > > > > > required to prevent one of them from being unloaded safely by dereferencing
> > > > > > > dev->driver->owner. This patch provides a generic function to do this in a
> > > > > > > race-free way.
> > > > > >
> > > > > > I must ask: why not, instead, make the dependency explicit? In
> > > > > > particular, this looks like an application for the proposed media
> > > > > > controller code, which is meant to model the connections between otherwise
> > > > > > independent devices. The fact that your example comes from V4L2 (which is
> > > > > > the current domain of the media controller) also argues that way.
> > > > >
> > > > > Sorry, don't see a good way to do this. This function is for a general
> > > > > dependency, where you don't have that driver, we are checking for register
> > > > > with us, so, the only way to get to it is via dev->driver->owner.
> > > >
> > > > Wait, what? The device is already bound to a driver, right, so why
> > > > would you care about "locking" the module into memory? What could this
> > > > possibly be used for?
> > >
> > > To protect against rmmod -> driver_unregister -> dev->driver = NULL?
> >
> > But again, why would some other driver ever care about what some random
> > dev->driver would be?
>
> It's not a random one, call it a "companion device."

Ok, but again go back to Jon's original proposal to just call the
functions in that driver from yours, causing the implicit module
ordering issue to be automatically resolved.

thanks,

greg k-h
--
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/