Skip to contentSkip to conversation

media: atomisp: drain assert recovery before tearing down resources

PATCH In review Myeonghun Pak 2 participants 3 messages Oct 12

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: atomisp: drain assert recovery before tearing down resources

The threaded IRQ queues assert_recovery_work, which can stop, reset and restart CSS. Removal currently tears down CSS and the CPU latency QoS request while recovery can still be running.

Disable and drain recovery before atomisp_pm_uninit(), keeping the IRQ available until recovery finishes. Then release the IRQ before CSS and firmware teardown. Apply the same ordering on probe failure, and skip the uninitialized recovery work in PM-only mode.

This issue was found by static analysis.

Fixes 93d3fb35aa10 ("media: atomisp: Remove watchdog timer")
Assisted-by LLM
---
 drivers/staging/media/atomisp/pci/atomisp_v4l2.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/staging/media/atomisp/pci/atomisp_v4l2.c +9 -1
index 812230397409..768b35468380 100644
@@ -1443,9 +1443,13 @@ static int atomisp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *i
 	return 0;
 
 error_unload_firmware:
+	disable_work_sync(&isp->assert_recovery_work);
 	atomisp_pm_uninit(isp);
+	devm_free_irq(&pdev->dev, pdev->irq, isp);
 	ia_css_unload_firmware();
+	goto error_unregister_entities;
 error_free_irq:
+	disable_work_sync(&isp->assert_recovery_work);
 	devm_free_irq(&pdev->dev, pdev->irq, isp);
 error_unregister_entities:
 	hmm_cleanup();
@@ -1464,15 +1468,19 @@ static void atomisp_pci_remove(struct pci_dev *pdev)
 {
 	struct atomisp_device *isp = pci_get_drvdata(pdev);
 
+	if (!isp->pm_only)
+		disable_work_sync(&isp->assert_recovery_work);
+
 	atomisp_pm_uninit(isp);
 
 	if (isp->pm_only)
 		return;
 
+	devm_free_irq(&pdev->dev, pdev->irq, isp);
+
 	/* Undo ia_css_init() from atomisp_power_on() */
 	atomisp_css_uninit(isp);
 	ia_css_unload_firmware();
-	devm_free_irq(&pdev->dev, pdev->irq, isp);
 	hmm_cleanup();
 
 	atomisp_unregister_entities(isp);
#1 lore raw
Quoted 11 lines · Myeonghun Pak

The threaded IRQ queues assert_recovery_work, which can stop, reset and restart CSS. Removal currently tears down CSS and the CPU latency QoS request while recovery can still be running.

Disable and drain recovery before atomisp_pm_uninit(), keeping the IRQ available until recovery finishes. Then release the IRQ before CSS and firmware teardown. Apply the same ordering on probe failure, and skip the uninitialized recovery work in PM-only mode.

This issue was found by static analysis.

Nice, have you read the code that you sent?

...

drivers/staging/media/atomisp/pci/atomisp_v4l2.c static int atomisp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *i · line 1448

Quoted 4 lines

error_unload_firmware:

drivers/staging/media/atomisp/pci/atomisp_v4l2.c +2 -0
+       disable_work_sync(&isp->assert_recovery_work);
        atomisp_pm_uninit(isp);
+       devm_free_irq(&pdev->dev, pdev->irq, isp);

^^^

drivers/staging/media/atomisp/pci/atomisp_v4l2.c static int atomisp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *i · line 1453

Quoted 5 lines
        ia_css_unload_firmware();
drivers/staging/media/atomisp/pci/atomisp_v4l2.c +2 -0
+       goto error_unregister_entities;
 error_free_irq:
+       disable_work_sync(&isp->assert_recovery_work);
        devm_free_irq(&pdev->dev, pdev->irq, isp);

^^^

Quoted 2 lines

error_unregister_entities:

        hmm_cleanup();
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Myeonghun Pak

The threaded IRQ queues assert_recovery_work, which can stop, reset and restart CSS. Removal currently tears down CSS and the CPU latency QoS request while recovery can still be running.

Quoted 8 lines
Quoted 6 lines

Disable and drain recovery before atomisp_pm_uninit(), keeping the IRQ available until recovery finishes. Then release the IRQ before CSS and firmware teardown. Apply the same ordering on probe failure, and skip the uninitialized recovery work in PM-only mode.

This issue was found by static analysis.

Nice, have you read the code that you sent?

Next time, please also test this on real HW.

...

Quoted 17 lines

drivers/staging/media/atomisp/pci/atomisp_v4l2.c static int atomisp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *i · line 1448

Quoted 4 lines

error_unload_firmware:

drivers/staging/media/atomisp/pci/atomisp_v4l2.c +2 -0
+       disable_work_sync(&isp->assert_recovery_work);
        atomisp_pm_uninit(isp);
+       devm_free_irq(&pdev->dev, pdev->irq, isp);

^^^

drivers/staging/media/atomisp/pci/atomisp_v4l2.c static int atomisp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *i · line 1453

Quoted 5 lines
        ia_css_unload_firmware();
drivers/staging/media/atomisp/pci/atomisp_v4l2.c +2 -0
+       goto error_unregister_entities;
 error_free_irq:
+       disable_work_sync(&isp->assert_recovery_work);
        devm_free_irq(&pdev->dev, pdev->irq, isp);

^^^

Quoted 2 lines

error_unregister_entities:

        hmm_cleanup();
Signature · 2 lines
With Best Regards,
Andy Shevchenko