[questions] about usb_set_intfdata(intf, NULL) and if race is possible between ->disconnect() and ->suspend()

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

 



For instance, let's say we have simple usb driver with:

static struct usb_driver usb_some_driver = {
	.name		= DRIVER_NAME,
	.probe		= yet_another_probe,
	.disconnect	= yet_another_disconnect,
	.suspend	= yet_another_suspend,
	.resume		= yet_another_resume,
	.reset_resume	= yet_another_resume,
	.id_table	= yet_another_device_table,
};

1. Can ->suspend and ->disconnect methods race?

Documentation/driver-api/usb/power-management.rst says:
This implies that external suspend/resume events are mutually exclusive
with calls to ``probe``, ``disconnect``, ``pre_reset``, and
``post_reset``;


Comment for usb_suspend_both() says that:
 * ...	Usbcore will insure that
 * method calls do not arrive during bind, unbind, or reset operations.
and that:
 * However drivers must be prepared to handle suspend calls arriving at
 * unpredictable times.

Also I was asked couple of years back what I am going to do if
disconnect() and suspend() will race, so seems never hurts to double-
check.

2. Do I need to usb_set_intfdata(intf, NULL) in disconnect method and
in probe() function if registration with another subsystem fails?
Like:
static int usb_streamlabs_wdt_probe(struct usb_interface *intf,
                                        const struct usb_device_id *id)
{
	...
	usb_set_intfdata(intf, &data);
	...
	retval = devm_subsystem_register_device(&intf->dev, ...);
	if (retval) {
		dev_err(&intf->dev, "error message\n");
		usb_set_intfdata(intf, NULL)
		return retval;
	}
}

I saw some patches that clear stale dev->driver_data pointer in
disconnect but doesn't seem that all usb drivers do that hence the
question.

Thanks,
Alexey






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

  Powered by Linux