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

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

 



Am Freitag, 4. Dezember 2009 21:57:50 schrieb Alan Stern:
> On Fri, 4 Dec 2009, Oliver Neukum wrote:
> > > > 1. am I supposed to get a reference just so that I can use dev_err?
> > >
> > > No, you should already have a reference on the device when doing the
> > > call, right?
> >
> > No, why? Consider this:
> >
> > int write(...)
> > {
> > 	...
> > 	mutex_lock(&instance->lock);
> > 	if (instance->disconnected) {
> > 		dev_dbg(instance->dev,"writing to disconnected device");
> > 		rv = -ENODEV;
> > 	} else {
> > 		res = usb_submit_urb(...);
> > 		rv = res < 0 ? -EIO : count;
> > 	}
> > 	mutex_unlock(&instance->lock);
> > 	return rv;
> > }
> >
> > void disconnect(...)
> > {
> > 	...
> > 	mutex_lock(&instance->lock);
> > 	instance->disconnected = 1;
> > 	usb_kill_urb(...);
> > 	usb_kill_urb(...);
> > 	mutex_unlock(&instance->lock);
> > }
> >
> > This would be perfectly valid code without any references taken save
> > for the pesky dev_dbg()
> 
> Whoever calls write() must possess a valid reference.  Otherwise
> instance might already be deallocated when write() starts, causing an
> oops well before the call to dev_dbg().

He needs a valid reference to "instance", not to the device. In fact
he may do IO to the device only if he knows it hasn't been disconnected.
 
> Typically the driver would take a reference during open() and drop it
> during close().

You can do that but then you must not do IO prior to open() or after
close(). That is you must actually wait for IO to finish in close() and
cannot prefill your buffers before open().

	Regards
		Oliver

--
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