Re: [PATCH] Driver core: fix race in dev_driver_string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Dec 04, 2009 at 06:50:35PM -0500, Alan Stern wrote:
> On Fri, 4 Dec 2009, Dmitry Torokhov wrote:
> 
> > > Maybe reference counting is inelegant; it depends on your point of
> > > view.  Can you think of a more elegant way to make sure that a pointer
> > > isn't stale?
> > 
> > Yes, just say "no" to device_create() and friends.
> 
> device_create() wasn't used in the case Oliver is discussing.

It was implied, as you had a pointer to the device, not the device
itself.

> >  Embed device structure in
> > yours,
> 
> You can't do that when the device structure wasn't created by your 
> driver.

But for USB devices, it is part of the device you are handed.  Same goes
for PCI devices, and most other types of drivers, right?

> >  be mindful of lifetime rules and only use "your" device (i.e device
> > bound to your driver).
> 
> What do you mean by "use"?  In Oliver's case he wasn't using the
> device, he was using the device structure.  (Maybe that's what you
> meant.)

I think that is what is meant here.

> And he wanted to use it at a time when it wasn't bound to his
> driver, because userspace still had an open file reference to it.  
> There isn't really any way around this.

But you still have a valid device, just not maybe a driver bound to it.

> > This way, as long as your refcount your instance you
> > can rest assured the device structure is there as well.
> 
> I rather think that a simple device_get() and device_put() is easier 
> than trying to follow a bunch of rules, especially in cases where they 
> don't apply!  :-)

Like here :)

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux