Skip to content

Commit 526816f

Browse files
Xulin SunSasha Levin
authored andcommitted
media: chips-media: wave5: Fix device cleanup order to prevent kernel panic
[ Upstream commit b74ceda ] Move video device unregistration to the beginning of the remove function to ensure all video operations are stopped before cleaning up the worker thread and disabling PM runtime. This prevents hardware register access after the device has been powered down. In polling mode, the hrtimer periodically triggers wave5_vpu_timer_callback() which queues work to the kthread worker. The worker executes wave5_vpu_irq_work_fn() which reads hardware registers via wave5_vdi_read_register(). The original cleanup order disabled PM runtime and powered down hardware before unregistering video devices. When autosuspend triggers and powers off the hardware, the video devices are still registered and the worker thread can still be triggered by the hrtimer, causing it to attempt reading registers from powered-off hardware. This results in a bus error (synchronous external abort) and kernel panic. This causes random kernel panics during encoding operations: Internal error: synchronous external abort: 0000000096000010 [linux4microchip#1] PREEMPT SMP Modules linked in: wave5 rpmsg_ctrl rpmsg_char ... CPU: 0 UID: 0 PID: 1520 Comm: vpu_irq_thread Tainted: G M W pc : wave5_vdi_read_register+0x10/0x38 [wave5] lr : wave5_vpu_irq_work_fn+0x28/0x60 [wave5] Call trace: wave5_vdi_read_register+0x10/0x38 [wave5] kthread_worker_fn+0xd8/0x238 kthread+0x104/0x120 ret_from_fork+0x10/0x20 Code: aa1e03e9 d503201f f9416800 8b214000 (b9400000) ---[ end trace 0000000000000000 ]--- Kernel panic - not syncing: synchronous external abort: Fatal exception Fixes: 9707a62 ("media: chips-media: wave5: Add the v4l2 layer") Cc: stable@vger.kernel.org Signed-off-by: Xulin Sun <xulin.sun@windriver.com> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent cc8071b commit 526816f

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

drivers/media/platform/chips-media/wave5/wave5-vpu.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ static void wave5_vpu_remove(struct platform_device *pdev)
351351
{
352352
struct vpu_device *dev = dev_get_drvdata(&pdev->dev);
353353

354+
wave5_vpu_enc_unregister_device(dev);
355+
wave5_vpu_dec_unregister_device(dev);
356+
v4l2_device_unregister(&dev->v4l2_dev);
357+
354358
if (dev->irq < 0) {
355359
hrtimer_cancel(&dev->hrtimer);
356360
kthread_cancel_work_sync(&dev->work);
@@ -364,9 +368,6 @@ static void wave5_vpu_remove(struct platform_device *pdev)
364368
mutex_destroy(&dev->hw_lock);
365369
reset_control_assert(dev->resets);
366370
clk_bulk_disable_unprepare(dev->num_clks, dev->clks);
367-
wave5_vpu_enc_unregister_device(dev);
368-
wave5_vpu_dec_unregister_device(dev);
369-
v4l2_device_unregister(&dev->v4l2_dev);
370371
wave5_vdi_release(&pdev->dev);
371372
ida_destroy(&dev->inst_ida);
372373
}

0 commit comments

Comments
 (0)