Thank you for your contribution! Sashiko AI review found 2 potential issue(s) 
to consider:

New issues:
- [Critical] Replacing `pm_runtime_put()` with `pm_runtime_put_sync()` 
synchronously powers off the hardware before tearing down child devices, DRM 
bridges, and IRQs, causing system crashes when they access unpowered registers.

Pre-existing issues:
- [High] Using `timer_delete_sync()` instead of `timer_shutdown_sync()` in the 
remove path allows the timer to be re-armed by the concurrently active IRQ 
thread, leading to a use-after-free.
--

--- Patch [3]: [PATCH v4 03/12] drm/mediatek: mtk_dp: Call 
pm_runtime_put_sync() in removal path ---
commit f976047da5b8089ab1d0475df94302360f23d7f2
Author: AngeloGioacchino Del Regno <[email protected]>

drm/mediatek: mtk_dp: Call pm_runtime_put_sync() in removal path

Since pm_runtime_put() queues an asynchronous suspend, calling
pm_runtime_disable() right after will cancel the pending suspend
work.

Call pm_runtime_put_sync() instead during mtk_dp_remove() to
overcome to this issue, making sure that the suspend ops execute
and that the hardware correctly powers off before module unload.

> diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c 
> b/drivers/gpu/drm/mediatek/mtk_dp.c
> index f656b85b84212..0d0507890d993 100644
> --- a/drivers/gpu/drm/mediatek/mtk_dp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_dp.c
> @@ -2866,7 +2866,7 @@ static void mtk_dp_remove(struct platform_device *pdev)
>  {
>       struct mtk_dp *mtk_dp = platform_get_drvdata(pdev);
>  
> -     pm_runtime_put(&pdev->dev);
> +     pm_runtime_put_sync(&pdev->dev);

[Severity: Critical]
Does changing this to a synchronous put cause a regression where the
hardware is powered off before child devices and IRQs are torn down?

Because the driver uses a devm-managed IRQ, the interrupt can still fire
and execute mtk_dp_hpd_event() which reads hardware registers:

mtk_dp_hpd_event() {
        u32 irq_status = mtk_dp_swirq_get_clear(mtk_dp) |
                         mtk_dp_hwirq_get_clear(mtk_dp);
        ...
}

Additionally, child platform devices like the audio codec are still active.
If they are torn down later and trigger mtk_dp_audio_shutdown(), it also
accesses hardware:

mtk_dp_audio_shutdown() {
        mtk_dp_audio_mute(mtk_dp, true);
        ...
}

Will accessing these registers after the PM domain is synchronously powered
down result in a bus fault or system crash? Should the PM operations be
moved to the end of the teardown process after explicitly disabling IRQs
and unregistering child devices?

>       pm_runtime_disable(&pdev->dev);
>       if (mtk_dp->data->bridge_type != DRM_MODE_CONNECTOR_eDP)
> -             timer_delete_sync(&mtk_dp->debounce_timer);
> +             timer_delete_sync(&mtk_dp->debounce_timer);

[Severity: High]
This is a pre-existing issue, but could this timer_delete_sync() result in
a use-after-free?

Since the hardware interrupt is managed by devres, it remains active
throughout mtk_dp_remove(). If the IRQ thread is executing concurrently,
it can unconditionally re-arm the timer:

mtk_dp_hpd_event_thread() {
        ...
        mod_timer(&mtk_dp->debounce_timer,
                  jiffies + msecs_to_jiffies(100) - 1);
}

If mod_timer() is called right after timer_delete_sync() finishes, the
timer is successfully re-armed. Once mtk_dp_remove() returns, devres will
free the mtk_dp structure. When the timer expires, won't it access freed
memory?

Should this be updated to use timer_shutdown_sync() instead to permanently
prevent the timer from being re-armed?

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=3

Reply via email to