Skip to contentSkip to conversation

drm/amd/display: do not allocate display_mode_lib unnecessarily

PATCH In review Dor Askayo 2 participants 4 messages Jan 4, 2020 – Jan 24, 2020

Subsystems (3)
lore
Share & tools
lore

Dor Askayo

author
#0 lore raw

PATCH 1/1 drm/amd/display: do not allocate display_mode_lib unnecessarily

This allocation isn't required and can fail when resuming from suspend.

---
 drivers/gpu/drm/amd/display/dc/core/dc.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc.c +9 -8
index dd4731ab935c..83ebb716166b 100644
@@ -2179,12 +2179,7 @@ void dc_set_power_state(
 	enum dc_acpi_cm_power_state power_state)
 {
 	struct kref refcount;
-	struct display_mode_lib *dml = kzalloc(sizeof(struct display_mode_lib),
-						GFP_KERNEL);
-
-	ASSERT(dml);
-	if (!dml)
-		return;
+	struct display_mode_lib *dml;
 
 	switch (power_state) {
 	case DC_ACPI_CM_POWER_STATE_D0:
@@ -2206,6 +2201,12 @@ void dc_set_power_state(
 		 * clean state, and dc hw programming optimizations will not
 		 * cause any trouble.
 		 */
+		dml = kzalloc(sizeof(struct display_mode_lib),
+				GFP_KERNEL);
+
+		ASSERT(dml);
+		if (!dml)
+			return;
 
 		/* Preserve refcount */
 		refcount = dc->current_state->refcount;
@@ -2219,10 +2220,10 @@ void dc_set_power_state(
 		dc->current_state->refcount = refcount;
 		dc->current_state->bw_ctx.dml = *dml;
 
+		kfree(dml);
+
 		break;
 	}
-
-	kfree(dml);
 }
 
 void dc_resume(struct dc *dc)
Signature · 1 line
2.24.1
author
#1 lore raw
Quoted 54 lines · Dor Askayo

This allocation isn't required and can fail when resuming from suspend.

---
 drivers/gpu/drm/amd/display/dc/core/dc.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc.c +9 -9
index dd4731ab935c..83ebb716166b 100644
@@ -2179,12 +2179,7 @@ void dc_set_power_state(
        enum dc_acpi_cm_power_state power_state)
 {
        struct kref refcount;
-       struct display_mode_lib *dml = kzalloc(sizeof(struct display_mode_lib),
-                                               GFP_KERNEL);
-
-       ASSERT(dml);
-       if (!dml)
-               return;
+       struct display_mode_lib *dml;
 
        switch (power_state) {
        case DC_ACPI_CM_POWER_STATE_D0:
@@ -2206,6 +2201,12 @@ void dc_set_power_state(
                 * clean state, and dc hw programming optimizations will not
                 * cause any trouble.
                 */
+               dml = kzalloc(sizeof(struct display_mode_lib),
+                               GFP_KERNEL);
+
+               ASSERT(dml);
+               if (!dml)
+                       return;
 
                /* Preserve refcount */
                refcount = dc->current_state->refcount;
@@ -2219,10 +2220,10 @@ void dc_set_power_state(
                dc->current_state->refcount = refcount;
                dc->current_state->bw_ctx.dml = *dml;
 
+               kfree(dml);
+
                break;
        }
-
-       kfree(dml);
 }
 
 void dc_resume(struct dc *dc)
--
Quoted 2 lines

2.24.1

I've been running with this fix applied on top of Fedora's 5.3.16-300.fc31.x86_64 kernel for
the past two weeks, suspending and resuming often. This the first time since I bought my
RX 580 8GB more than a year ago that I can suspend and resume reliably.

I'd appreciate a quick review for the above, it really is a trivial change.

Thanks,
Dor

author
#2 lore raw
Quoted 64 lines · Dor Askayo
Quoted 54 lines · Dor Askayo

This allocation isn't required and can fail when resuming from suspend.

---
 drivers/gpu/drm/amd/display/dc/core/dc.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc.c +9 -9
index dd4731ab935c..83ebb716166b 100644
@@ -2179,12 +2179,7 @@ void dc_set_power_state(
        enum dc_acpi_cm_power_state power_state)
 {
        struct kref refcount;
-       struct display_mode_lib *dml = kzalloc(sizeof(struct display_mode_lib),
-                                               GFP_KERNEL);
-
-       ASSERT(dml);
-       if (!dml)
-               return;
+       struct display_mode_lib *dml;
 
        switch (power_state) {
        case DC_ACPI_CM_POWER_STATE_D0:
@@ -2206,6 +2201,12 @@ void dc_set_power_state(
                 * clean state, and dc hw programming optimizations will not
                 * cause any trouble.
                 */
+               dml = kzalloc(sizeof(struct display_mode_lib),
+                               GFP_KERNEL);
+
+               ASSERT(dml);
+               if (!dml)
+                       return;
 
                /* Preserve refcount */
                refcount = dc->current_state->refcount;
@@ -2219,10 +2220,10 @@ void dc_set_power_state(
                dc->current_state->refcount = refcount;
                dc->current_state->bw_ctx.dml = *dml;
 
+               kfree(dml);
+
                break;
        }
-
-       kfree(dml);
 }
 
 void dc_resume(struct dc *dc)
--
Quoted 2 lines

2.24.1

I've been running with this fix applied on top of Fedora's 5.3.16-300.fc31.x86_64 kernel for the past two weeks, suspending and resuming often. This the first time since I bought my RX 580 8GB more than a year ago that I can suspend and resume reliably.

Quoted 4 lines

I'd appreciate a quick review for the above, it really is a trivial change.

Thanks,
Dor

Bumping this up again. I've been running with this change for the past 20 days without issues.

Thanks,
Dor

Quoted 69 lines · Dor Askayo
Quoted 54 lines · Dor Askayo

This allocation isn't required and can fail when resuming from suspend.

---
 drivers/gpu/drm/amd/display/dc/core/dc.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc.c +9 -9
index dd4731ab935c..83ebb716166b 100644
@@ -2179,12 +2179,7 @@ void dc_set_power_state(
        enum dc_acpi_cm_power_state power_state)
 {
        struct kref refcount;
-       struct display_mode_lib *dml = kzalloc(sizeof(struct display_mode_lib),
-                                               GFP_KERNEL);
-
-       ASSERT(dml);
-       if (!dml)
-               return;
+       struct display_mode_lib *dml;
 
        switch (power_state) {
        case DC_ACPI_CM_POWER_STATE_D0:
@@ -2206,6 +2201,12 @@ void dc_set_power_state(
                 * clean state, and dc hw programming optimizations will not
                 * cause any trouble.
                 */
+               dml = kzalloc(sizeof(struct display_mode_lib),
+                               GFP_KERNEL);
+
+               ASSERT(dml);
+               if (!dml)
+                       return;
 
                /* Preserve refcount */
                refcount = dc->current_state->refcount;
@@ -2219,10 +2220,10 @@ void dc_set_power_state(
                dc->current_state->refcount = refcount;
                dc->current_state->bw_ctx.dml = *dml;
 
+               kfree(dml);
+
                break;
        }
-
-       kfree(dml);
 }
 
 void dc_resume(struct dc *dc)
--
Quoted 2 lines

2.24.1

I've been running with this fix applied on top of Fedora's 5.3.16-300.fc31.x86_64 kernel for
the past two weeks, suspending and resuming often. This the first time since I bought my
RX 580 8GB more than a year ago that I can suspend and resume reliably.

I'd appreciate a quick review for the above, it really is a trivial change.

Thanks,
Dor

maintainer Reviewed-by
#3 lore raw

Sorry for the delay, change LGTM.

, and applied.

Thanks!
Leo

Quoted 69 lines · Dor Askayo
Quoted 63 lines · Dor Askayo
Quoted 53 lines · Dor Askayo

This allocation isn't required and can fail when resuming from suspend.

 drivers/gpu/drm/amd/display/dc/core/dc.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc.c +9 -9
index dd4731ab935c..83ebb716166b 100644
@@ -2179,12 +2179,7 @@ void dc_set_power_state(
        enum dc_acpi_cm_power_state power_state)
 {
        struct kref refcount;
-       struct display_mode_lib *dml = kzalloc(sizeof(struct display_mode_lib),
-                                               GFP_KERNEL);
-
-       ASSERT(dml);
-       if (!dml)
-               return;
+       struct display_mode_lib *dml;
 
        switch (power_state) {
        case DC_ACPI_CM_POWER_STATE_D0:
@@ -2206,6 +2201,12 @@ void dc_set_power_state(
                 * clean state, and dc hw programming optimizations will not
                 * cause any trouble.
                 */
+               dml = kzalloc(sizeof(struct display_mode_lib),
+                               GFP_KERNEL);
+
+               ASSERT(dml);
+               if (!dml)
+                       return;
 
                /* Preserve refcount */
                refcount = dc->current_state->refcount;
@@ -2219,10 +2220,10 @@ void dc_set_power_state(
                dc->current_state->refcount = refcount;
                dc->current_state->bw_ctx.dml = *dml;
 
+               kfree(dml);
+
                break;
        }
-
-       kfree(dml);
 }
 
 void dc_resume(struct dc *dc)
--
Quoted 2 lines

2.24.1

I've been running with this fix applied on top of Fedora's 5.3.16-300.fc31.x86_64 kernel for the past two weeks, suspending and resuming often. This the first time since I bought my RX 580 8GB more than a year ago that I can suspend and resume reliably.

Quoted 4 lines

I'd appreciate a quick review for the above, it really is a trivial change.

Thanks,
Dor

Quoted 76 lines

Bumping this up again. I've been running with this change for the past 20 days without issues.

Thanks,
Dor

Quoted 69 lines · Dor Askayo
Quoted 54 lines · Dor Askayo

This allocation isn't required and can fail when resuming from suspend.

---
 drivers/gpu/drm/amd/display/dc/core/dc.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc.c +9 -9
index dd4731ab935c..83ebb716166b 100644
@@ -2179,12 +2179,7 @@ void dc_set_power_state(
        enum dc_acpi_cm_power_state power_state)
 {
        struct kref refcount;
-       struct display_mode_lib *dml = kzalloc(sizeof(struct display_mode_lib),
-                                               GFP_KERNEL);
-
-       ASSERT(dml);
-       if (!dml)
-               return;
+       struct display_mode_lib *dml;
 
        switch (power_state) {
        case DC_ACPI_CM_POWER_STATE_D0:
@@ -2206,6 +2201,12 @@ void dc_set_power_state(
                 * clean state, and dc hw programming optimizations will not
                 * cause any trouble.
                 */
+               dml = kzalloc(sizeof(struct display_mode_lib),
+                               GFP_KERNEL);
+
+               ASSERT(dml);
+               if (!dml)
+                       return;
 
                /* Preserve refcount */
                refcount = dc->current_state->refcount;
@@ -2219,10 +2220,10 @@ void dc_set_power_state(
                dc->current_state->refcount = refcount;
                dc->current_state->bw_ctx.dml = *dml;
 
+               kfree(dml);
+
                break;
        }
-
-       kfree(dml);
 }
 
 void dc_resume(struct dc *dc)
--
Quoted 2 lines

2.24.1

I've been running with this fix applied on top of Fedora's 5.3.16-300.fc31.x86_64 kernel for
the past two weeks, suspending and resuming often. This the first time since I bought my
RX 580 8GB more than a year ago that I can suspend and resume reliably.

I'd appreciate a quick review for the above, it really is a trivial change.

Thanks,
Dor

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx