Skip to contentSkip to conversation

drm/amd/display: fix array lenth error.

PATCH In review Rex Zhu 2 participants 6 messages Feb 6, 2017 4 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

Rex Zhu

author
#0 lore raw

PATCH 1/2 drm/amd/display: fix array lenth error.

Change-Id I09011c5e6d5493db7e3d9a7ff7ab8c871a8db862
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c +2 -2
index 5af27aa..50576c6 100644
@@ -358,7 +358,7 @@ bool dm_pp_get_clock_levels_by_type(
 				 * non-boosted one. */
 				DRM_INFO("DM_PPLIB: reducing engine clock level from %d to %d\n",
 						dc_clks->num_levels, i + 1);
-				dc_clks->num_levels = i;
+				dc_clks->num_levels = i + 1;
 				break;
 			}
 		}
@@ -367,7 +367,7 @@ bool dm_pp_get_clock_levels_by_type(
 			if (dc_clks->clocks_in_khz[i] > validation_clks.memory_max_clock) {
 				DRM_INFO("DM_PPLIB: reducing memory clock level from %d to %d\n",
 						dc_clks->num_levels, i + 1);
-				dc_clks->num_levels = i;
+				dc_clks->num_levels = i + 1;
 				break;
 			}
 		}
Signature · 6 lines
1.9.1

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

A message that is not in the archive (sent off-list or not yet received): 1486357719-7102-1-git-send-email-Rex.Zhu-5C7GfCeVMHo@public.gmane.org

author
#2 lore raw

PATCH 2/2 drm/amd/powerplay: refine code to avoid potential bug that the memory not cleared.

Change-Id If286d163cbabd8e9921a9d3cfcb71bb2b99aaceb
---
 drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c +7 -10
index 0a6c833..18f8ee7 100644
@@ -4397,16 +4397,14 @@ static int smu7_get_sclks(struct pp_hwmgr *hwmgr, struct amd_pp_clocks *clocks)
 		if (table_info == NULL || table_info->vdd_dep_on_sclk == NULL)
 			return -EINVAL;
 		dep_sclk_table = table_info->vdd_dep_on_sclk;
-		for (i = 0; i < dep_sclk_table->count; i++) {
+		for (i = 0; i < dep_sclk_table->count; i++)
 			clocks->clock[i] = dep_sclk_table->entries[i].clk;
-			clocks->count++;
-		}
+		clocks->count = dep_sclk_table->count;
 	} else if (hwmgr->pp_table_version == PP_TABLE_V0) {
 		sclk_table = hwmgr->dyn_state.vddc_dependency_on_sclk;
-		for (i = 0; i < sclk_table->count; i++) {
+		for (i = 0; i < sclk_table->count; i++)
 			clocks->clock[i] = sclk_table->entries[i].clk;
-			clocks->count++;
-		}
+		clocks->count = sclk_table->count;
 	}
 
 	return 0;
@@ -4440,14 +4438,13 @@ static int smu7_get_mclks(struct pp_hwmgr *hwmgr, struct amd_pp_clocks *clocks)
 			clocks->clock[i] = dep_mclk_table->entries[i].clk;
 			clocks->latency[i] = smu7_get_mem_latency(hwmgr,
 						dep_mclk_table->entries[i].clk);
-			clocks->count++;
 		}
+		clocks->count = dep_mclk_table->count;
 	} else if (hwmgr->pp_table_version == PP_TABLE_V0) {
 		mclk_table = hwmgr->dyn_state.vddc_dependency_on_mclk;
-		for (i = 0; i < mclk_table->count; i++) {
+		for (i = 0; i < mclk_table->count; i++)
 			clocks->clock[i] = mclk_table->entries[i].clk;
-			clocks->count++;
-		}
+		clocks->count = mclk_table->count
 	}
 	return 0;
 }
Signature · 6 lines
1.9.1

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

A message that is not in the archive (sent off-list or not yet received): 1486357719-7102-2-git-send-email-Rex.Zhu-5C7GfCeVMHo@public.gmane.org

author
#4 lore raw

RE: [PATCH 2/2] drm/amd/powerplay: refine code to avoid potential bug that the memory not cleared.

+ clocks->count = mclk_table->count

Missing semicolon. Will fix in V2.

Best Regards
Rex

-----Original Message-----
From: Rex Zhu [mailto:[email protected]]
Sent: Monday, February 06, 2017 1:09 PM
To: [email protected]
Cc: Zhu, Rex
Subject: [PATCH 2/2] drm/amd/powerplay: refine code to avoid potential bug that the memory not cleared.

Change-Id If286d163cbabd8e9921a9d3cfcb71bb2b99aaceb
---
 drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c +7 -10
index 0a6c833..18f8ee7 100644
@@ -4397,16 +4397,14 @@ static int smu7_get_sclks(struct pp_hwmgr *hwmgr, struct amd_pp_clocks *clocks)
 		if (table_info == NULL || table_info->vdd_dep_on_sclk == NULL)
 			return -EINVAL;
 		dep_sclk_table = table_info->vdd_dep_on_sclk;
-		for (i = 0; i < dep_sclk_table->count; i++) {
+		for (i = 0; i < dep_sclk_table->count; i++)
 			clocks->clock[i] = dep_sclk_table->entries[i].clk;
-			clocks->count++;
-		}
+		clocks->count = dep_sclk_table->count;
 	} else if (hwmgr->pp_table_version == PP_TABLE_V0) {
 		sclk_table = hwmgr->dyn_state.vddc_dependency_on_sclk;
-		for (i = 0; i < sclk_table->count; i++) {
+		for (i = 0; i < sclk_table->count; i++)
 			clocks->clock[i] = sclk_table->entries[i].clk;
-			clocks->count++;
-		}
+		clocks->count = sclk_table->count;
 	}
 
 	return 0;
@@ -4440,14 +4438,13 @@ static int smu7_get_mclks(struct pp_hwmgr *hwmgr, struct amd_pp_clocks *clocks)
 			clocks->clock[i] = dep_mclk_table->entries[i].clk;
 			clocks->latency[i] = smu7_get_mem_latency(hwmgr,
 						dep_mclk_table->entries[i].clk);
-			clocks->count++;
 		}
+		clocks->count = dep_mclk_table->count;
 	} else if (hwmgr->pp_table_version == PP_TABLE_V0) {
 		mclk_table = hwmgr->dyn_state.vddc_dependency_on_mclk;
-		for (i = 0; i < mclk_table->count; i++) {
+		for (i = 0; i < mclk_table->count; i++)
 			clocks->clock[i] = mclk_table->entries[i].clk;
-			clocks->count++;
-		}
+		clocks->count = mclk_table->count
 	}
 	return 0;
 }
Signature · 6 lines
1.9.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#5 lore raw
In reply to a message not in the archive
Quoted 11 lines · Rex Zhu
Change-Id I09011c5e6d5493db7e3d9a7ff7ab8c871a8db862
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c +0 -0
index 5af27aa..50576c6 100644

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c bool dm_pp_get_clock_levels_by_type( · line 361

Quoted 5 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c +1 -1
@@ -358,7 +358,7 @@ bool dm_pp_get_clock_levels_by_type(
 				 * non-boosted one. */
 				DRM_INFO("DM_PPLIB: reducing engine clock level from %d to %d\n",
 						dc_clks->num_levels, i + 1);
-				dc_clks->num_levels = i;
+				dc_clks->num_levels = i + 1;

It seems to me the DRM_INFO print is wrong here, not the actual assignment. We're setting num_levels to the current index if the clocks for that index are higher than the max validation clocks, hence this index now should become num_levels.

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c bool dm_pp_get_clock_levels_by_type( · line 373

Quoted 13 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c +1 -1
 				break;
 			}
 		}
@@ -367,7 +367,7 @@ bool dm_pp_get_clock_levels_by_type(
 			if (dc_clks->clocks_in_khz[i] > validation_clks.memory_max_clock) {
 				DRM_INFO("DM_PPLIB: reducing memory clock level from %d to %d\n",
 						dc_clks->num_levels, i + 1);
-				dc_clks->num_levels = i;
+				dc_clks->num_levels = i + 1;
 				break;
 			}
 		}

Same comment as above.

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

A message that is not in the archive (sent off-list or not yet received): d7898cb1-cf89-6672-dd92-9ae74b168edf-5C7GfCeVMHo@public.gmane.org

author
#7 lore raw

seems reasonable.

but i think need to check num_levels can't be 0. in some case, there is only one level of mclk, and higher than the max validation clocks.. and will lead kernel panic.

Best Regards

Rex

________________________________
From: Wentland, Harry
Sent: Monday, February 6, 2017 10:54:24 PM
To: Zhu, Rex; [email protected]
Subject: Re: [PATCH 1/2] drm/amd/display: fix array lenth error.

Quoted 11 lines · Rex Zhu
Change-Id I09011c5e6d5493db7e3d9a7ff7ab8c871a8db862
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c +0 -0
index 5af27aa..50576c6 100644

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c bool dm_pp_get_clock_levels_by_type( · line 361

Quoted 5 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c +1 -1
@@ -358,7 +358,7 @@ bool dm_pp_get_clock_levels_by_type(
                                * non-boosted one. */
                               DRM_INFO("DM_PPLIB: reducing engine clock level from %d to %d\n",
                                               dc_clks->num_levels, i + 1);
-                             dc_clks->num_levels = i;
+                             dc_clks->num_levels = i + 1;

It seems to me the DRM_INFO print is wrong here, not the actual assignment. We're setting num_levels to the current index if the clocks for that index are higher than the max validation clocks, hence this index now should become num_levels.

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c bool dm_pp_get_clock_levels_by_type( · line 373

Quoted 13 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c +1 -1
                               break;
                       }
               }
@@ -367,7 +367,7 @@ bool dm_pp_get_clock_levels_by_type(
                       if (dc_clks->clocks_in_khz[i] > validation_clks.memory_max_clock) {
                               DRM_INFO("DM_PPLIB: reducing memory clock level from %d to %d\n",
                                               dc_clks->num_levels, i + 1);
-                             dc_clks->num_levels = i;
+                             dc_clks->num_levels = i + 1;
                               break;
                       }
               }

Same comment as above.

Harry

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

A message that is not in the archive (sent off-list or not yet received): CY4PR12MB168712DD6B6D2BA7E7861CB7FB400-rpdhrqHFk06Y0SjTqZDccQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#9 lore raw

True, we should probably always keep one level even if it's larger than max_clock, but output a big fat warning message when that happens.

Harry

Quoted 57 lines · Rex

seems reasonable.

but i think need to check num_levels can't be 0. in some case, there is only one level of mclk, and higher than the max validation clocks.. and will lead kernel panic.

Best Regards

Rex

------------------------------------------------------------------------
*From:* Wentland, Harry
*Sent:* Monday, February 6, 2017 10:54:24 PM
*To:* Zhu, Rex; [email protected] *Subject:* Re: [PATCH 1/2] drm/amd/display: fix array lenth error.

Quoted 11 lines · Rex Zhu
Change-Id I09011c5e6d5493db7e3d9a7ff7ab8c871a8db862
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c +0 -0
index 5af27aa..50576c6 100644

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c bool dm_pp_get_clock_levels_by_type( · line 361

Quoted 5 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c +1 -1
@@ -358,7 +358,7 @@ bool dm_pp_get_clock_levels_by_type(
                                * non-boosted one. */
                               DRM_INFO("DM_PPLIB: reducing engine clock level from %d to %d\n",
                                               dc_clks->num_levels, i + 1);
-                             dc_clks->num_levels = i;
+                             dc_clks->num_levels = i + 1;

It seems to me the DRM_INFO print is wrong here, not the actual assignment. We're setting num_levels to the current index if the clocks for that index are higher than the max validation clocks, hence this index now should become num_levels.

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c bool dm_pp_get_clock_levels_by_type( · line 373

Quoted 13 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c +1 -1
                               break;
                       }
               }
@@ -367,7 +367,7 @@ bool dm_pp_get_clock_levels_by_type(
                       if (dc_clks->clocks_in_khz[i] > validation_clks.memory_max_clock) {
                               DRM_INFO("DM_PPLIB: reducing memory clock level from %d to %d\n",
                                               dc_clks->num_levels, i + 1);
-                             dc_clks->num_levels = i;
+                             dc_clks->num_levels = i + 1;
                               break;
                       }
               }

Same comment as above.

Quoted 1 line

Harry

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