drm/nouveau: cancel irq_work before freeing connector
Subsystems (4)
PATCH 1/1 drm/nouveau: cancel irq_work before freeing connector
nouveau_connector_irq() schedules irq_work on the system workqueue. nouveau_connector_destroy() calls nvif_event_dtor() which unregisters the interrupt event source so no new callbacks will fire, but it does not drain the system workqueue. If a work item was already queued, nouveau_dp_irq() can run after kfree(connector) and dereference freed memory.
Add cancel_work_sync() after nvif_event_dtor() so any in-flight or pending irq_work completes before the connector is freed.
--- drivers/gpu/drm/nouveau/nouveau_connector.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/nouveau/nouveau_connector.c +1 -0
@@ -395,6 +395,7 @@ nouveau_connector_destroy(struct drm_connector *connector)struct nouveau_connector *nv_connector =nouveau_connector (connector);nvif_event_dtor (&nv_connector->irq);nvif_event_dtor (&nv_connector->hpd); +cancel_work_sync (&nv_connector->irq_work);kfree (nv_connector->edid);drm_connector_unregister (connector);drm_connector_cleanup (connector);
Hi Danilo, Dave,
Following up on this connector teardown fix sent September 25.
Would any additional validation or changes help with the review? I'm happy to investigate further or revise the patch if needed.
Thanks,
Aldo
Quoted 10 lines · Aldo Ariel Panzardo
nouveau_connector_irq()schedulesirq_workon the system workqueue.nouveau_connector_destroy()callsnvif_event_dtor()which unregisters the interrupt event source so no new callbacks will fire, but it does not drain the system workqueue. If a work item was already queued,nouveau_dp_irq()can run after kfree(connector) and dereference freed memory.Add
cancel_work_sync()afternvif_event_dtor()so any in-flight or pendingirq_workcompletes before the connector is freed.
Review
Quoted 7 lines
Signed-off-by Aldo Ariel Panzardo <[email protected]>--- drivers/gpu/drm/nouveau/nouveau_connector.c | 1 + 1 file changed, 1 insertion(+)(quoted diff) +0
-0
b/drivers/gpu/drm/nouveau/nouveau_connector.c
drivers/gpu/drm/nouveau/nouveau_connector.c nouveau_connector_destroy(struct drm_connector
Quoted 4 lines
index XXXXXXX..YYYYYYY 100644
drivers/gpu/drm/nouveau/nouveau_connector.c +0
-0@@ -395,6 +395,7 @@ nouveau_connector_destroy(struct drm_connector
*connector)
drivers/gpu/drm/nouveau/nouveau_connector.c nouveau_connector_destroy(struct drm_connector · line 395
Quoted 1 line
drivers/gpu/drm/nouveau/nouveau_connector.c +0
-0struct nouveau_connector *nv_connector =
nouveau_connector(connector);
Quoted 6 lines
drivers/gpu/drm/nouveau/nouveau_connector.c +1
-0nvif_event_dtor (&nv_connector->irq);nvif_event_dtor (&nv_connector->hpd); +cancel_work_sync (&nv_connector->irq_work);kfree (nv_connector->edid);drm_connector_unregister (connector);drm_connector_cleanup (connector);