mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: rc: st_rc: stop IRQ and unregister rc_dev before disabling clock
@ 2026-12-03  8:52 Yaohan Li
  0 siblings, 0 replies; only message in thread
From: Yaohan Li @ 2026-12-03  8:52 UTC (permalink / raw)
  To: Patrice Chotard, Sean Young, Mauro Carvalho Chehab
  Cc: Srinivas Kandagatla, Hans Verkuil, linux-arm-kernel, linux-media,
	linux-kernel

In the original driver from commit 80f93c7b0f45 ("[media] media: st-rc:
Add ST remote control driver"), st_rc_remove() disables rc_dev->sys_clock
before calling rc_unregister_device() and leaves the devm-managed
interrupt handler active until devres teardown runs after remove()
returns.  If userspace still has the RC device open on unbind,
rc_unregister_device() invokes st_rc_close(), which writes IRB_RX_EN and
IRB_RX_INT_EN after sys_clock has already been gated.

Commit dccc0c3ddf8f ("media: rc: fix race between unregister and urb/irq
callbacks") later split rc_unregister_device() and rc_free_device() so
drivers could stop their IRQ or URB callbacks before freeing rc_dev, but
only added rc_free_device() at the end of st_rc_remove() without stopping
rc_dev->irq first.  Because st_rc_rx_interrupt() polls the RX FIFO for up
to 10 ms while pushing events to rc_dev->rdev, it can race with both
clock disable and rc_free_device().

Unregister the RC device while sys_clock is still enabled, free and
synchronize rc_dev->irq with devm_free_irq(), disable sys_clock, and then
call rc_free_device(), matching the probe error path.

Fixes: 80f93c7b0f45 ("[media] media: st-rc: Add ST remote control driver")
Fixes: dccc0c3ddf8f ("media: rc: fix race between unregister and urb/irq callbacks")
Cc: stable@vger.kernel.org
Signed-off-by: Yaohan Li <shunsheng1218@gmail.com>
---
Based on v7.4-rc5 (fe6ff8d5d675); applies cleanly on media-committers fixes
and next.

I don't have STi hardware, so I tested this in QEMU (x86_64, KASAN +
PROVE_LOCKING) with the in-tree st_rc.ko bound to a platform device using
reserved MMIO, a CCF clk_hw clock, and a virtual IRQ.  Unbinding with
/dev/lirc0 open and st_rc_rx_interrupt() active on another vCPU reproduces
sys_clock turning off while IRB_RX_EN is still set on the unmodified driver;
with this patch applied, concurrent unbind, system suspend/resume (wakeup
enabled and disabled), and rebind all complete with 0 KASAN or lockdep
warnings.  Also build-tested on x86_64 and arm64 with W=1 (0 warnings).

AI assistance: Claude and Gemini helped trace the teardown order, write the
QEMU test module, and draft the commit message.  I reviewed the driver code,
test logs, and final patch myself.

 drivers/media/rc/st_rc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/rc/st_rc.c b/drivers/media/rc/st_rc.c
index 211e06e744130..9274d28f23bcb 100644
--- a/drivers/media/rc/st_rc.c
+++ b/drivers/media/rc/st_rc.c
@@ -201,8 +201,9 @@ static void st_rc_remove(struct platform_device *pdev)
 
 	dev_pm_clear_wake_irq(&pdev->dev);
 	device_init_wakeup(&pdev->dev, false);
-	clk_disable_unprepare(rc_dev->sys_clock);
 	rc_unregister_device(rc_dev->rdev);
+	devm_free_irq(&pdev->dev, rc_dev->irq, rc_dev);
+	clk_disable_unprepare(rc_dev->sys_clock);
 	rc_free_device(rc_dev->rdev);
 }
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-03  8:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03  8:52 [PATCH] media: rc: st_rc: stop IRQ and unregister rc_dev before disabling clock Yaohan Li

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®