drm/bridge: anx7625: stop IRQ work before teardown
Subsystems (4)
PATCH 1/1 drm/bridge: anx7625: stop IRQ work before teardown
The HPD interrupt remains active until devres releases it after the driver's remove callback returns. Its handler queues work that accesses the Type-C port and DRM bridge, but remove unregisters those objects before destroying the workqueue. An interrupt can therefore race with teardown and queue work that accesses released objects.
Disable the interrupt first to synchronize with the handler, then destroy the workqueue to drain work queued before the interrupt was disabled. This ensures that no HPD work remains before unregistering its consumers.
--- drivers/gpu/drm/bridge/analogix/anx7625.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/bridge/analogix/anx7625.c +5 -3
@@ -2973,13 +2973,15 @@ static void anx7625_i2c_remove(struct i2c_client *client) {struct anx7625_data *platform =i2c_get_clientdata (client); +if (platform->pdata.intp_irq) { +disable_irq (platform->pdata.intp_irq); +destroy_workqueue (platform->workqueue); + } +anx7625_typec_unregister (platform);drm_bridge_remove (&platform->bridge); -if (platform->pdata.intp_irq) -destroy_workqueue (platform->workqueue); -if (platform->hdcp_workqueue) {cancel_delayed_work (&platform->hdcp_work);destroy_workqueue (platform->hdcp_workqueue);
Signature · 1 line
2.47.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] The teardown path uses cancel_delayed_work() instead of cancel_delayed_work_sync(), allowing the timer handler to race with destroy_workqueue() and lead to a use-after-free.
- [High] If driver initialization fails during or after anx7625_link_bridge(), the DRM bridge remains registered but its parent memory is freed by devres, leading to a Use-After-Free.
- [Medium] anx7625_bridge_atomic_disable() attempts to wait for hdcp_work using flush_workqueue(), but this does not cancel or wait for pending delayed work timers. --
--- Patch [1]: [PATCH] drm/bridge: anx7625: stop IRQ work before teardown --- commit f6280d9ebcac680a90e170320e540ca6f7ab4e30
Author: Myeonghun Pak <[email protected]>
drm/bridge: anx7625: stop IRQ work before teardown
This commit disables the HPD interrupt and destroys the workqueue first to synchronize with the handler and drain queued work. This prevents the interrupt from racing with teardown and queuing work that accesses released objects.
Quoted 6 lines
drivers/gpu/drm/bridge/analogix/anx7625.c +0
-0@@ -2973,13 +2973,15 @@ static void anx7625_i2c_remove(struct i2c_client *client) {
[ ... ]
drivers/gpu/drm/bridge/analogix/anx7625.c static void anx7625_i2c_remove(struct i2c_client *client) · line 2986
Quoted 7 lines
drivers/gpu/drm/bridge/analogix/anx7625.c +0
-3drm_bridge_remove (&platform->bridge); -if (platform->pdata.intp_irq) -destroy_workqueue (platform->workqueue); -if (platform->hdcp_workqueue) {cancel_delayed_work (&platform->hdcp_work);
[Severity: High]
This is a pre-existing issue, but does this non-synchronous cancel allow a race condition?
If cancel_delayed_work() is called while the timer callback is executing on another CPU, it returns immediately without waiting. When destroy_workqueue() then frees the workqueue, the timer callback could resume and attempt to queue work on the freed workqueue, leading to a use-after-free.
Should this use cancel_delayed_work_sync() instead?
drivers/gpu/drm/bridge/analogix/anx7625.c
Quoted 2 lines
drivers/gpu/drm/bridge/analogix/anx7625.c +0
-0destroy_workqueue (platform->hdcp_workqueue); }
[Severity: Medium]
This is a pre-existing issue, but does anx7625_bridge_atomic_disable() correctly handle the delayed work?
drivers/gpu/drm/bridge/analogix/anx7625.c:anx7625_bridge_atomic_disable() {
...
flush_workqueue(ctx->hdcp_workqueue);
...
}Calling flush_workqueue() doesn't actually cancel or wait for pending delayed work timers if they haven't expired yet, causing the work to run later. Should this use cancel_delayed_work_sync() to ensure the work is properly stopped?
[Severity: High]
This is a pre-existing issue, but does the probe function leak the DRM bridge registration on error paths?
drivers/gpu/drm/bridge/analogix/anx7625.c:anx7625_i2c_probe() {
...
ret = anx7625_typec_register(platform);
if (ret)
goto pm_suspend;
...
}Because anx7625_link_bridge() calls drm_bridge_add() earlier in the probe, if a subsequent step like anx7625_typec_register() fails, the probe function jumps to the error path and returns an error without calling drm_bridge_remove().
The devres framework then frees the platform structure, but the bridge remains globally registered in bridge_list. Any subsequent iteration of the bridge list by the DRM core would dereference the freed memory, leading to a use-after-free.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1