Skip to contentSkip to conversation

media: Documentation: Use right function to test device power state

PATCH In review Sakari Ailus 2 participants 3 messages Mar 26 – May 5

Subsystems (2)
lore
Share & tools
lore

Sakari Ailus

author maintainer
#0 lore raw

PATCH 1/1 media: Documentation: Use right function to test device power state

Tell driver authors to use pm_runtime_get_if_active() instead of pm_runtime_get_if_in_use() to check the device's power state in the s_ctrl callback. pm_runtime_get_if_active() is the right function to use here since it returns non-zero if the device is powered on rather than its PM runtime usage_count is non-zero.

---
 Documentation/driver-api/media/camera-sensor.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/driver-api/media/camera-sensor.rst +1 -1
index 94bd1dae82d5..c8552f70f496 100644
@@ -114,7 +114,7 @@ of the device. This is because the power state of the device is only changed
 after the power state transition has taken place. The ``s_ctrl`` callback can be
 used to obtain device's power state after the power state transition:
 
-.. c:function:: int pm_runtime_get_if_in_use(struct device *dev);
+.. c:function:: int pm_runtime_get_if_active(struct device *dev);
 
 The function returns a non-zero value if it succeeded getting the power count or
 runtime PM was disabled, in either of which cases the driver may proceed to
Signature · 1 line
2.47.3
Reviewed-by on v1 1/1
#1 lore raw

Hi Sakari,

Thank you for the patch.

Quoted 16 lines · Sakari Ailus

Tell driver authors to use pm_runtime_get_if_active() instead of pm_runtime_get_if_in_use() to check the device's power state in the s_ctrl callback. pm_runtime_get_if_active() is the right function to use here since it returns non-zero if the device is powered on rather than its PM runtime usage_count is non-zero.

---
 Documentation/driver-api/media/camera-sensor.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/driver-api/media/camera-sensor.rst +0 -0
index 94bd1dae82d5..c8552f70f496 100644

Documentation/driver-api/media/camera-sensor.rst of the device. This is because the power state of the device is only changed · line 117

Quoted 5 lines
Documentation/driver-api/media/camera-sensor.rst +1 -1
@@ -114,7 +114,7 @@ of the device. This is because the power state of the device is only changed
 after the power state transition has taken place. The ``s_ctrl`` callback can be
 used to obtain device's power state after the power state transition:
 
-.. c:function:: int pm_runtime_get_if_in_use(struct device *dev);
+.. c:function:: int pm_runtime_get_if_active(struct device *dev);

This looks fine, but I think we should also mass-convert drivers. There are more drivers using pm_runtime_get_if_in_use() than pm_runtime_get_if_active(), so we'll keep seeing new code using the former due to cargo cult.

For this patch,

Should I submit a series to mass-convert drivers, or will you do it ?

Quoted 3 lines
Documentation/driver-api/media/camera-sensor.rst +0 -0
 The function returns a non-zero value if it succeeded getting the power count or
 runtime PM was disabled, in either of which cases the driver may proceed to
Signature · 3 lines
Regards,

Laurent Pinchart
author maintainer
#2 lore raw

Hi Laurent,

Quoted 32 lines · Laurent Pinchart

Hi Sakari,

Thank you for the patch.

Quoted 16 lines · Sakari Ailus

Tell driver authors to use pm_runtime_get_if_active() instead of pm_runtime_get_if_in_use() to check the device's power state in the s_ctrl callback. pm_runtime_get_if_active() is the right function to use here since it returns non-zero if the device is powered on rather than its PM runtime usage_count is non-zero.

---
 Documentation/driver-api/media/camera-sensor.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/driver-api/media/camera-sensor.rst +0 -0
index 94bd1dae82d5..c8552f70f496 100644

Documentation/driver-api/media/camera-sensor.rst of the device. This is because the power state of the device is only changed · line 117

Quoted 5 lines
Documentation/driver-api/media/camera-sensor.rst +1 -1
@@ -114,7 +114,7 @@ of the device. This is because the power state of the device is only changed
 after the power state transition has taken place. The ``s_ctrl`` callback can be
 used to obtain device's power state after the power state transition:
 
-.. c:function:: int pm_runtime_get_if_in_use(struct device *dev);
+.. c:function:: int pm_runtime_get_if_active(struct device *dev);

This looks fine, but I think we should also mass-convert drivers. There are more drivers using pm_runtime_get_if_in_use() than pm_runtime_get_if_active(), so we'll keep seeing new code using the former due to cargo cult.

Quoted 3 lines

For this patch,

Thank you.

Quoted 2 lines

Should I submit a series to mass-convert drivers, or will you do it ?

I was planning to, yes.

It seems what happened was that the APIs and the usage of the APIs in sensor drivers changed but we forgot to update the documentation. Oh well.

I'm a bit surprised there have been no complaints but I guess in practice you'd need quite a bit of bad luck to hit this. Relatively few drivers use autosuspend, too.

Signature · 3 lines
Regards,

Sakari Ailus