Skip to content

Commit c58e7ed

Browse files
krzkrafaeljw
authored andcommitted
PM: runtime: document common mistake with pm_runtime_get_sync()
pm_runtime_get_sync(), contradictory to intuition, does not drop the runtime PM usage counter on errors which lead to several wrong usages in drivers (missing the put). pm_runtime_resume_and_get() was added as a better implementation so document the preference of using it, hoping it will stop bad patterns. Suggested-by: Marek Szyprowski <[email protected]> Signed-off-by: Krzysztof Kozlowski <[email protected]> [ rjw: Documentation change edits ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 8124c8a commit c58e7ed

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Documentation/power/runtime_pm.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,11 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
378378

379379
`int pm_runtime_get_sync(struct device *dev);`
380380
- increment the device's usage counter, run pm_runtime_resume(dev) and
381-
return its result
381+
return its result;
382+
note that it does not drop the device's usage counter on errors, so
383+
consider using pm_runtime_resume_and_get() instead of it, especially
384+
if its return value is checked by the caller, as this is likely to
385+
result in cleaner code.
382386

383387
`int pm_runtime_get_if_in_use(struct device *dev);`
384388
- return -EINVAL if 'power.disable_depth' is nonzero; otherwise, if the

include/linux/pm_runtime.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ static inline int pm_runtime_get(struct device *dev)
380380
* The possible return values of this function are the same as for
381381
* pm_runtime_resume() and the runtime PM usage counter of @dev remains
382382
* incremented in all cases, even if it returns an error code.
383+
* Consider using pm_runtime_resume_and_get() instead of it, especially
384+
* if its return value is checked by the caller, as this is likely to result
385+
* in cleaner code.
383386
*/
384387
static inline int pm_runtime_get_sync(struct device *dev)
385388
{

0 commit comments

Comments
 (0)