Skip to content

Commit

Permalink
media: pisp_be: Fix pm_runtime underrun in probe
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Laurent Pinchart <[email protected]>

---
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 <[email protected]>
  • Loading branch information
Jacopo Mondi committed Sep 4, 2024
1 parent 0ea92dc commit 775912b
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions drivers/media/platform/raspberrypi/pisp_be/pisp_be.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 775912b

Please sign in to comment.