usb: dwc3: of-simple: fix use-after-free on remove
Quoted 12 lines · Rafael J. Wysocki
Quoted 11 lines · Felipe Balbi
Hi,
Quoted 7 lines · Tony Lindgren
Quoted 6 lines · Felipe Balbi
This is a direct consequence of not paying attention to the order of things. If driver were to assume that
pm_domain->activate()would do the right thing for the device -- meaning that probe would run with an active device --, then we wouldn't need thatpm_runtime_get()call on probe at all. Rather we would follow the sequence:
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
pm_runtime_forbid()Why do you need the
_forbid()thing?Does the default user space control setting need to be changed?
wouldn't that race with a udev rule writing "auto" power/control as soon as device is added?
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
(If you need to know why the
pm_runtime_put_noidle(), remember thatpm_runtime_set_active()increments the usage counter, sopm_runtime_put_noidleis basically allowingpm_runtimeto happen as soon as userspace writes "auto" to/sys/..../power/control)I wonder if we could also remove the need for drivers to call
pm_runtime_putnoidle()at the end of the probe? If we hadpm_runtime_init_enabled()implemented.
Quoted 6 lines
Quoted 3 lines
probably not. We want to block runtime pm during probe, until the device is fully initialized, the only way to do that is to increment rpm usage counter.
That or enable it only at the end. But I guess you want to runtime-resume it earlier, don't you?
well, if arch implements pm_domain->activate() and guarantees that device is already running, with clocks stable during probe, then enabling runtime pm at the end is probably the best idea.