media: atomisp: drain assert recovery before tearing down resources
Subsystems (4)
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.
--- 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
@@ -1443,9 +1443,13 @@ static int atomisp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ireturn 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);
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
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