stm class: drop the source link after the source device is gone
PATCH 1/1 stm class: drop the source link after the source device is gone
stm_source_unregister_device() drops the link of the source and only then unregisters its device. The stm_source_link sysfs attribute is still reachable in between, so a concurrent write to it re-links the
source: it ends up on the stm device's link list with src->link set and the source's link() callback armed, after which device_unregister() frees it and the source module is unloaded. The next unlink walk in stm_unregister_device() then touches the freed source, the stm device keeps a reference that is never dropped, and a source like stm_heartbeat has its hrtimer fire in freed module memory.
Delete the device first, which drains the sysfs attribute, then drop the link and release the device.
--- drivers/hwtracing/stm/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwtracing/stm/core.c +2 -2
@@ -1287,9 +1287,9 @@ void stm_source_unregister_device(struct stm_source_data *data) {struct stm_source_device *src = data->src; +device_del (&src->dev);stm_source_link_drop (src); - -device_unregister (&src->dev); +put_device (&src->dev); }EXPORT_SYMBOL_GPL (stm_source_unregister_device);
Signature · 1 line
2.43.0