Skip to contentSkip to conversation

drm/vc4: Fix pm_runtime_get_sync() error checking

PATCH In review Miaoqian Lin 2 participants 8 messages Apr 12, 2022 – Apr 21, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/vc4: Fix pm_runtime_get_sync() error checking

If the device is already in a runtime PM enabled state pm_runtime_get_sync() will return 1, so a test for negative value should be used to check for errors.

Fixes 4078f5757144 ("drm/vc4: Add DSI driver")
---
 drivers/gpu/drm/vc4/vc4_dsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vc4/vc4_dsi.c +1 -1
index 752f921735c6..26aa7d1fa421 100644
@@ -847,7 +847,7 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder)
 	int ret;
 
 	ret = pm_runtime_get_sync(dev);
-	if (ret) {
+	if (ret < 0) {
 		DRM_ERROR("Failed to runtime PM enable on DSI%d\n", dsi->variant->port);
 		return;
 	}
Signature · 1 line
2.17.1
#1 lore raw

Hi,

Quoted 15 lines · Miaoqian Lin

If the device is already in a runtime PM enabled state pm_runtime_get_sync() will return 1, so a test for negative value should be used to check for errors.

Fixes 4078f5757144 ("drm/vc4: Add DSI driver")
---
 drivers/gpu/drm/vc4/vc4_dsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vc4/vc4_dsi.c +0 -0
index 752f921735c6..26aa7d1fa421 100644

drivers/gpu/drm/vc4/vc4_dsi.c static void vc4_dsi_encoder_enable(struct drm_encoder *encoder) · line 853

Quoted 8 lines
drivers/gpu/drm/vc4/vc4_dsi.c +1 -1
@@ -847,7 +847,7 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder)
 	int ret;
 
 	ret = pm_runtime_get_sync(dev);
-	if (ret) {
+	if (ret < 0) {
 		DRM_ERROR("Failed to runtime PM enable on DSI%d\n", dsi->variant->port);
 		return;
 	}

We also don't put back our reference after an error. I think a better fix would be to switch to pm_runtime_resume_and_get.

Maxime

#2 lore raw

PATCH v2 1/1 drm/vc4: Fix pm_runtime_get_sync() usage

If the device is already in a runtime PM enabled state pm_runtime_get_sync() will return 1, so a test for negative value should be used to check for errors.

Also, we need to call pm_runtime_put_noidle() when pm_runtime_get_sync() fails, so use pm_runtime_resume_and_get() instead. this function will handle this.

Fixes 4078f5757144 ("drm/vc4: Add DSI driver")

---
change in v2:
- switch to pm_runtime_resume_and_get() to fix refcount leak.

---
 drivers/gpu/drm/vc4/vc4_dsi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/vc4/vc4_dsi.c +2 -2
index 752f921735c6..9d7ffaf6bc70 100644
@@ -846,8 +846,8 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder)
 	unsigned long phy_clock;
 	int ret;
 
-	ret = pm_runtime_get_sync(dev);
-	if (ret) {
+	ret = pm_runtime_resume_and_get(dev);
+	if (ret < 0) {
 		DRM_ERROR("Failed to runtime PM enable on DSI%d\n", dsi->variant->port);
 		return;
 	}
Signature · 1 line
2.17.1
#3 lore raw

Re: [PATCH v2] drm/vc4: Fix pm_runtime_get_sync() usage

Quoted 22 lines · Miaoqian Lin

If the device is already in a runtime PM enabled state pm_runtime_get_sync() will return 1, so a test for negative value should be used to check for errors.

Also, we need to call pm_runtime_put_noidle() when pm_runtime_get_sync() fails, so use pm_runtime_resume_and_get() instead. this function will handle this.

Fixes 4078f5757144 ("drm/vc4: Add DSI driver")

---
change in v2:
- switch to pm_runtime_resume_and_get() to fix refcount leak.

---
 drivers/gpu/drm/vc4/vc4_dsi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/vc4/vc4_dsi.c +0 -0
index 752f921735c6..9d7ffaf6bc70 100644

drivers/gpu/drm/vc4/vc4_dsi.c static void vc4_dsi_encoder_enable(struct drm_encoder *encoder) · line 850

Quoted 7 lines
drivers/gpu/drm/vc4/vc4_dsi.c +2 -2
@@ -846,8 +846,8 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder)
 	unsigned long phy_clock;
 	int ret;
 
-	ret = pm_runtime_get_sync(dev);
-	if (ret) {
+	ret = pm_runtime_resume_and_get(dev);
+	if (ret < 0) {

pm_runtime_resume_and_get will return 0 on success, so the previous check was correct

Maxime

#4 lore raw

Re: [PATCH v2] drm/vc4: Fix pm_runtime_get_sync() usage

Quoted 26 lines · Maxime Ripard
Quoted 25 lines · Miaoqian Lin

If the device is already in a runtime PM enabled state pm_runtime_get_sync() will return 1, so a test for negative value should be used to check for errors.

Also, we need to call pm_runtime_put_noidle() when pm_runtime_get_sync() fails, so use pm_runtime_resume_and_get() instead. this function will handle this.

Fixes 4078f5757144 ("drm/vc4: Add DSI driver")

---
change in v2:
- switch to pm_runtime_resume_and_get() to fix refcount leak.

---
 drivers/gpu/drm/vc4/vc4_dsi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/vc4/vc4_dsi.c +0 -0
index 752f921735c6..9d7ffaf6bc70 100644
@@ -846,8 +846,8 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder)
 	unsigned long phy_clock;
 	int ret;
 
Quoted 5 lines

drivers/gpu/drm/vc4/vc4_dsi.c static void vc4_dsi_encoder_enable(struct drm_encoder *encoder) · line 850

Quoted 4 lines
drivers/gpu/drm/vc4/vc4_dsi.c +2 -2
-	ret = pm_runtime_get_sync(dev);
-	if (ret) {
+	ret = pm_runtime_resume_and_get(dev);
+	if (ret < 0) {

pm_runtime_resume_and_get will return 0 on success, so the previous check was correct

previous check is for pm_runtime_get_sync() not for pm_runtime_resume_and_get (),

I switch to pm_runtime_resume_and_get() to fix the refcount leak bug at the same time.

Sure it's ok to use check if(ret) to check the retval, I just follow a more common way

for usage of pm_runtime_resume_and_get() in the codebase—— check ret<0

Since pm_runtime_resume_and_get() return negative error code.

Quoted 1 line

Maxime

#5 lore raw

Re: [PATCH v2] drm/vc4: Fix pm_runtime_get_sync() usage

Quoted 36 lines · Miaoqian Lin
Quoted 26 lines · Maxime Ripard
Quoted 25 lines · Miaoqian Lin

If the device is already in a runtime PM enabled state pm_runtime_get_sync() will return 1, so a test for negative value should be used to check for errors.

Also, we need to call pm_runtime_put_noidle() when pm_runtime_get_sync() fails, so use pm_runtime_resume_and_get() instead. this function will handle this.

Fixes 4078f5757144 ("drm/vc4: Add DSI driver")

---
change in v2:
- switch to pm_runtime_resume_and_get() to fix refcount leak.

---
 drivers/gpu/drm/vc4/vc4_dsi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/vc4/vc4_dsi.c +0 -0
index 752f921735c6..9d7ffaf6bc70 100644
@@ -846,8 +846,8 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder)
 	unsigned long phy_clock;
 	int ret;
 
Quoted 5 lines

drivers/gpu/drm/vc4/vc4_dsi.c static void vc4_dsi_encoder_enable(struct drm_encoder *encoder) · line 850

Quoted 4 lines
drivers/gpu/drm/vc4/vc4_dsi.c +2 -2
-	ret = pm_runtime_get_sync(dev);
-	if (ret) {
+	ret = pm_runtime_resume_and_get(dev);
+	if (ret < 0) {

pm_runtime_resume_and_get will return 0 on success, so the previous check was correct

previous check is for pm_runtime_get_sync() not for pm_runtime_resume_and_get (),

Quoted 7 lines

I switch to pm_runtime_resume_and_get() to fix the refcount leak bug at the same time.

Sure it's ok to use check if(ret) to check the retval, I just follow a more common way

for usage of pm_runtime_resume_and_get() in the codebase—— check ret<0

Since pm_runtime_resume_and_get() return negative error code.

If it ain't broke, don't fix it. The previous condition was working perfectly fine to catch the errors from pm_runtime_resume_and_get, there's no reason to change it.

Maxime

#6 lore raw

PATCH v3 1/1 drm/vc4: Use pm_runtime_resume_and_get to fix pm_runtime_get_sync() usage

If the device is already in a runtime PM enabled state pm_runtime_get_sync() will return 1.

Also, we need to call pm_runtime_put_noidle() when pm_runtime_get_sync() fails, so use pm_runtime_resume_and_get() instead. this function will handle this.

Fixes 4078f5757144 ("drm/vc4: Add DSI driver")

---
change in v2:
- switch to pm_runtime_resume_and_get() to fix refcount leak. changes in v3:
- keep the original checking way for retval.

---
 drivers/gpu/drm/vc4/vc4_dsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vc4/vc4_dsi.c +1 -1
index 752f921735c6..98308a17e4ed 100644
@@ -846,7 +846,7 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder)
 	unsigned long phy_clock;
 	int ret;
 
-	ret = pm_runtime_get_sync(dev);
+	ret = pm_runtime_resume_and_get(dev);
 	if (ret) {
 		DRM_ERROR("Failed to runtime PM enable on DSI%d\n", dsi->variant->port);
 		return;
Signature · 1 line
2.17.1
#7 lore raw

Re: (subset) [PATCH v3] drm/vc4: Use pm_runtime_resume_and_get to fix pm_runtime_get_sync() usage

Quoted 8 lines · Miaoqian Lin

If the device is already in a runtime PM enabled state pm_runtime_get_sync() will return 1.

Also, we need to call pm_runtime_put_noidle() when pm_runtime_get_sync() fails, so use pm_runtime_resume_and_get() instead. this function will handle this.

[...]

Applied to drm/drm-misc (drm-misc-fixes).

Thanks!
Maxime