mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: s5p-mfc: use timer_shutdown_sync() for the self-rearming watchdog
@ 2026-07-30  7:15 ` Fan Wu
  2026-08-05  7:14   ` Marek Szyprowski
  0 siblings, 1 reply; 2+ messages in thread
From: Fan Wu @ 2026-07-30  7:15 UTC (permalink / raw)
  To: linux-media
  Cc: stable, m.szyprowski, andrzej.hajda, mchehab, linux-kernel, Fan Wu

The MFC watchdog timer (s5p_mfc_watchdog) is self-rearming: every
callback re-arms itself with add_timer() and, on a timeout, schedules
watchdog_work. s5p_mfc_remove() tears this down with timer_delete_sync()
followed by flush_work().

timer_delete_sync() dequeues the timer and waits for a callback that is
already running, but it does not prevent a subsequent re-arm. Because the
watchdog callback re-arms via add_timer(), this is the wrong shutdown
primitive: once the wait returns nothing guarantees a just-queued re-arm
will not fire later, dereferencing dev (clock on/off, deinit_hw,
load_firmware, init_hw) after video_unregister_device(), DMA teardown and
s5p_mfc_final_pm() have run, a potential use-after-free.

Use timer_shutdown_sync(), which puts the timer into a shutdown state so
that any add_timer()/mod_timer() from the callback becomes a no-op and no
later firing is possible. Switch flush_work() to cancel_work_sync() so any
watchdog_work that was already queued before the timer was stopped is
cancelled rather than allowed to run to completion against the torn-down
device.

This issue was found by an in-house static analysis tool. No runtime
reproducer is available.

Fixes: af9357467810 ("[media] MFC: Add MFC 5.1 V4L2 driver")
Cc: stable@vger.kernel.org
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Andrzej Hajda <andrzej.hajda@intel.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
Assisted-by: Codex:gpt-5.6
Signed-off-by: Fan Wu <fanwu01@zju.edu.cn>
---
 drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c
index 32eb402d439c..03e7eac8d1f7 100644
--- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c
@@ -1474,8 +1474,8 @@ static void s5p_mfc_remove(struct platform_device *pdev)
 	}
 	mutex_unlock(&dev->mfc_mutex);
 
-	timer_delete_sync(&dev->watchdog_timer);
-	flush_work(&dev->watchdog_work);
+	timer_shutdown_sync(&dev->watchdog_timer);
+	cancel_work_sync(&dev->watchdog_work);
 
 	video_unregister_device(dev->vfd_enc);
 	video_unregister_device(dev->vfd_dec);
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] media: s5p-mfc: use timer_shutdown_sync() for the self-rearming watchdog
  2026-07-30  7:15 ` [PATCH] media: s5p-mfc: use timer_shutdown_sync() for the self-rearming watchdog Fan Wu
@ 2026-08-05  7:14   ` Marek Szyprowski
  0 siblings, 0 replies; 2+ messages in thread
From: Marek Szyprowski @ 2026-08-05  7:14 UTC (permalink / raw)
  To: Fan Wu, linux-media; +Cc: stable, andrzej.hajda, mchehab, linux-kernel

On 30.07.2026 09:15, Fan Wu wrote:
> The MFC watchdog timer (s5p_mfc_watchdog) is self-rearming: every
> callback re-arms itself with add_timer() and, on a timeout, schedules
> watchdog_work. s5p_mfc_remove() tears this down with timer_delete_sync()
> followed by flush_work().
>
> timer_delete_sync() dequeues the timer and waits for a callback that is
> already running, but it does not prevent a subsequent re-arm. Because the
> watchdog callback re-arms via add_timer(), this is the wrong shutdown
> primitive: once the wait returns nothing guarantees a just-queued re-arm
> will not fire later, dereferencing dev (clock on/off, deinit_hw,
> load_firmware, init_hw) after video_unregister_device(), DMA teardown and
> s5p_mfc_final_pm() have run, a potential use-after-free.
>
> Use timer_shutdown_sync(), which puts the timer into a shutdown state so
> that any add_timer()/mod_timer() from the callback becomes a no-op and no
> later firing is possible. Switch flush_work() to cancel_work_sync() so any
> watchdog_work that was already queued before the timer was stopped is
> cancelled rather than allowed to run to completion against the torn-down
> device.
>
> This issue was found by an in-house static analysis tool. No runtime
> reproducer is available.
>
> Fixes: af9357467810 ("[media] MFC: Add MFC 5.1 V4L2 driver")
> Cc: stable@vger.kernel.org
> Cc: Marek Szyprowski <m.szyprowski@samsung.com>
> Cc: Andrzej Hajda <andrzej.hajda@intel.com>
> Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
> Assisted-by: Codex:gpt-5.6
> Signed-off-by: Fan Wu <fanwu01@zju.edu.cn>
Reviewed-by: Marek Szyprowski <m.szyprowski@samsung.com>
> ---
>  drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c
> index 32eb402d439c..03e7eac8d1f7 100644
> --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c
> +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c
> @@ -1474,8 +1474,8 @@ static void s5p_mfc_remove(struct platform_device *pdev)
>  	}
>  	mutex_unlock(&dev->mfc_mutex);
>  
> -	timer_delete_sync(&dev->watchdog_timer);
> -	flush_work(&dev->watchdog_work);
> +	timer_shutdown_sync(&dev->watchdog_timer);
> +	cancel_work_sync(&dev->watchdog_work);
>  
>  	video_unregister_device(dev->vfd_enc);
>  	video_unregister_device(dev->vfd_dec);

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-05  7:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20260730071659eucas1p29e5e6fa1209da048bf1cec7fd821ef77@eucas1p2.samsung.com>
2026-07-30  7:15 ` [PATCH] media: s5p-mfc: use timer_shutdown_sync() for the self-rearming watchdog Fan Wu
2026-08-05  7:14   ` Marek Szyprowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®