mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yaohan Li <shunsheng1218@gmail.com>
To: Patrice Chotard <patrice.chotard@foss.st.com>,
	Sean Young <sean@mess.org>,
	Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Srinivas Kandagatla <srini@kernel.org>,
	Hans Verkuil <hverkuil@kernel.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] media: rc: st_rc: stop IRQ and unregister rc_dev before disabling clock
Date: Thu,  3 Dec 2026 16:52:47 +0800	[thread overview]
Message-ID: <20261203085247.2392209-1-shunsheng1218@gmail.com> (raw)

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


                 reply	other threads:[~2026-12-03  8:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203085247.2392209-1-shunsheng1218@gmail.com \
    --to=shunsheng1218@gmail.com \
    --cc=hverkuil@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=patrice.chotard@foss.st.com \
    --cc=sean@mess.org \
    --cc=srini@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®