From 775912be4da6a53cecc40d020b6bd66b4533463e Mon Sep 17 00:00:00 2001 From: Jacopo Mondi Date: Mon, 26 Aug 2024 15:30:54 +0200 Subject: [PATCH] media: pisp_be: Fix pm_runtime underrun in probe During the probe() routine, the driver needs to power up the interface in order to identify and initialize the hardware and it later suspends it at the end of probe(). The driver erroneously resumes the interface by calling the pispbe_runtime_resume() function directly but suspends it by calling pm_runtime_put_autosuspend(). This causes a PM usage count imbalance at probe time, notified by the runtime_pm framework with the below message in the system log: pispbe 1000880000.pisp_be: Runtime PM usage count underflow! Fix this by suspending the interface using pm_runtime_idle() which doesn't decrease the pm_runtime usage count and inform the PM framework that the device is active by calling pm_runtime_set_active(). Adjust the pispbe_remove() function as well to disable the pm_runtime in the correct order. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- v4->v5: - Indent with tabs :/ v3->v4: - Instead of using pm_runtime for resuming, suspend using pm_runtime_idle() to support !CONFIG_PM v2->v3: - Mark pispbe_runtime_resume() as __maybe_unused as reported by the kernel test robot --- .../platform/raspberrypi/pisp_be/pisp_be.c | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c index f4dce34a1c3d84..369f33001278fd 100644 --- a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c +++ b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c @@ -1768,19 +1768,15 @@ static int pispbe_probe(struct platform_device *pdev) "Failed to get clock"); /* Hardware initialisation */ - pm_runtime_set_autosuspend_delay(pispbe->dev, 200); - pm_runtime_use_autosuspend(pispbe->dev); - pm_runtime_enable(pispbe->dev); - ret = pispbe_runtime_resume(pispbe->dev); if (ret) - goto pm_runtime_disable_err; + return ret; pispbe->hw_busy = false; spin_lock_init(&pispbe->hw_lock); ret = pispbe_hw_init(pispbe); if (ret) - goto pm_runtime_suspend_err; + goto runtime_suspend_err; /* * Initialise and register devices for each node_group, including media @@ -1794,19 +1790,19 @@ static int pispbe_probe(struct platform_device *pdev) goto disable_nodes_err; } - pm_runtime_mark_last_busy(pispbe->dev); - pm_runtime_put_autosuspend(pispbe->dev); + pm_runtime_set_autosuspend_delay(pispbe->dev, 200); + pm_runtime_use_autosuspend(pispbe->dev); + pm_runtime_set_active(pispbe->dev); + pm_runtime_enable(pispbe->dev); + pm_runtime_idle(pispbe->dev); return 0; disable_nodes_err: while (num_groups-- > 0) pispbe_destroy_node_group(&pispbe->node_group[num_groups]); -pm_runtime_suspend_err: +runtime_suspend_err: pispbe_runtime_suspend(pispbe->dev); -pm_runtime_disable_err: - pm_runtime_dont_use_autosuspend(pispbe->dev); - pm_runtime_disable(pispbe->dev); return ret; } @@ -1818,9 +1814,11 @@ static int pispbe_remove(struct platform_device *pdev) for (int i = PISPBE_NUM_NODE_GROUPS - 1; i >= 0; i--) pispbe_destroy_node_group(&pispbe->node_group[i]); - pispbe_runtime_suspend(pispbe->dev); pm_runtime_dont_use_autosuspend(pispbe->dev); pm_runtime_disable(pispbe->dev); + if (!pm_runtime_status_suspended(pispbe->dev)) + pispbe_runtime_suspend(pispbe->dev); + pm_runtime_set_suspended(pispbe->dev); return 0; }