Skip to contentSkip to conversation

Small fixes for cz_dpm.c

PATCH In review Tom St Denis 3 participants 6 messages Aug 25, 2016 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

PATCH 1/3 drm/amd/amdgpu: Fix memleak in cz_parse_power_table()

If one of the entries fails to be allocated then free all of the previous entries before freeing the array which holds their pointers.

---
 drivers/gpu/drm/amd/amdgpu/cz_dpm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/cz_dpm.c +2 -0
index 794c5f36ca68..b06b95ce1350 100644
@@ -350,6 +350,8 @@ static int cz_parse_power_table(struct amdgpu_device *adev)
 
 		ps = kzalloc(sizeof(struct cz_ps), GFP_KERNEL);
 		if (ps == NULL) {
+			for (j = 0; j < i; j++)
+				kfree(adev->pm.dpm.ps[i].ps_priv);
 			kfree(adev->pm.dpm.ps);
 			return -ENOMEM;
 		}
Signature · 6 lines
2.9.2

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

PATCH 2/3 drm/amd/amdgpu: Clean up memory leak in cz_dpm_init().

In reply to a message not in the archive

If init fails free up any allocated memory.

---
 drivers/gpu/drm/amd/amdgpu/cz_dpm.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/cz_dpm.c +9 -5
index b06b95ce1350..d97604386766 100644
@@ -44,6 +44,7 @@
 
 static void cz_dpm_powergate_uvd(struct amdgpu_device *adev, bool gate);
 static void cz_dpm_powergate_vce(struct amdgpu_device *adev, bool gate);
+static void cz_dpm_fini(struct amdgpu_device *adev);
 
 static struct cz_ps *cz_get_ps(struct amdgpu_ps *rps)
 {
@@ -411,11 +412,11 @@ static int cz_dpm_init(struct amdgpu_device *adev)
 
 	ret = amdgpu_get_platform_caps(adev);
 	if (ret)
-		return ret;
+		goto err;
 
 	ret = amdgpu_parse_extended_power_table(adev);
 	if (ret)
-		return ret;
+		goto err;
 
 	pi->sram_end = SMC_RAM_END;
 
@@ -469,23 +470,26 @@ static int cz_dpm_init(struct amdgpu_device *adev)
 
 	ret = cz_parse_sys_info_table(adev);
 	if (ret)
-		return ret;
+		goto err;
 
 	cz_patch_voltage_values(adev);
 	cz_construct_boot_state(adev);
 
 	ret = cz_parse_power_table(adev);
 	if (ret)
-		return ret;
+		goto err;
 
 	ret = cz_process_firmware_header(adev);
 	if (ret)
-		return ret;
+		goto err;
 
 	pi->dpm_enabled = true;
 	pi->uvd_dynamic_pg = false;
 
 	return 0;
+err:
+	cz_dpm_fini(adev);
+	return ret;
 }
 
 static void cz_dpm_fini(struct amdgpu_device *adev)
Signature · 6 lines
2.9.2

_______________________________________________
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): [email protected]

#5 lore raw

Re: [PATCH 2/3] drm/amd/amdgpu: Clean up memory leak in cz_dpm_init().

Patch #2 has a typo should be 'j' in the loop.

I'll resend that patch in a second.

Tom

________________________________
From: Tom St Denis <[email protected]>
Sent: Thursday, August 25, 2016 13:10
To: [email protected]
Cc: StDenis, Tom
Subject: [PATCH 2/3] drm/amd/amdgpu: Clean up memory leak in cz_dpm_init().

If init fails free up any allocated memory.

---
 drivers/gpu/drm/amd/amdgpu/cz_dpm.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/cz_dpm.c +9 -5
index b06b95ce1350..d97604386766 100644
@@ -44,6 +44,7 @@
 
 static void cz_dpm_powergate_uvd(struct amdgpu_device *adev, bool gate);
 static void cz_dpm_powergate_vce(struct amdgpu_device *adev, bool gate);
+static void cz_dpm_fini(struct amdgpu_device *adev);
 
 static struct cz_ps *cz_get_ps(struct amdgpu_ps *rps)
 {
@@ -411,11 +412,11 @@ static int cz_dpm_init(struct amdgpu_device *adev)
 
         ret = amdgpu_get_platform_caps(adev);
         if (ret)
-               return ret;
+               goto err;
 
         ret = amdgpu_parse_extended_power_table(adev);
         if (ret)
-               return ret;
+               goto err;
 
         pi->sram_end = SMC_RAM_END;
 
@@ -469,23 +470,26 @@ static int cz_dpm_init(struct amdgpu_device *adev)
 
         ret = cz_parse_sys_info_table(adev);
         if (ret)
-               return ret;
+               goto err;
 
         cz_patch_voltage_values(adev);
         cz_construct_boot_state(adev);
 
         ret = cz_parse_power_table(adev);
         if (ret)
-               return ret;
+               goto err;
 
         ret = cz_process_firmware_header(adev);
         if (ret)
-               return ret;
+               goto err;
 
         pi->dpm_enabled = true;
         pi->uvd_dynamic_pg = false;
 
         return 0;
+err:
+       cz_dpm_fini(adev);
+       return ret;
 }
 
 static void cz_dpm_fini(struct amdgpu_device *adev)

--
2.9.2

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

#6 lore raw

PATCH 3/3 drm/amd/amdgpu: Tidy up cz_dpm.c

In reply to a message not in the archive

Various minor formatting changes.

---
 drivers/gpu/drm/amd/amdgpu/cz_dpm.c | 31 +++++++++++--------------------
 1 file changed, 11 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/cz_dpm.c +11 -20
index d97604386766..1e69c28392b3 100644
@@ -678,17 +678,12 @@ static void cz_reset_ap_mask(struct amdgpu_device *adev)
 	struct cz_power_info *pi = cz_get_pi(adev);
 
 	pi->active_process_mask = 0;
-
 }
 
 static int cz_dpm_download_pptable_from_smu(struct amdgpu_device *adev,
 							void **table)
 {
-	int ret = 0;
-
-	ret = cz_smu_download_pptable(adev, table);
-
-	return ret;
+	return cz_smu_download_pptable(adev, table);
 }
 
 static int cz_dpm_upload_pptable_to_smu(struct amdgpu_device *adev)
@@ -828,9 +823,9 @@ static void cz_init_sclk_limit(struct amdgpu_device *adev)
 	pi->sclk_dpm.hard_min_clk = 0;
 	cz_send_msg_to_smc(adev, PPSMC_MSG_GetMaxSclkLevel);
 	level = cz_get_argument(adev);
-	if (level < table->count)
+	if (level < table->count) {
 		clock = table->entries[level].clk;
-	else {
+	} else {
 		DRM_ERROR("Invalid SLCK Voltage Dependency table entry.\n");
 		clock = table->entries[table->count - 1].clk;
 	}
@@ -856,9 +851,9 @@ static void cz_init_uvd_limit(struct amdgpu_device *adev)
 	pi->uvd_dpm.hard_min_clk = 0;
 	cz_send_msg_to_smc(adev, PPSMC_MSG_GetMaxUvdLevel);
 	level = cz_get_argument(adev);
-	if (level < table->count)
+	if (level < table->count) {
 		clock = table->entries[level].vclk;
-	else {
+	} else {
 		DRM_ERROR("Invalid UVD Voltage Dependency table entry.\n");
 		clock = table->entries[table->count - 1].vclk;
 	}
@@ -884,9 +879,9 @@ static void cz_init_vce_limit(struct amdgpu_device *adev)
 	pi->vce_dpm.hard_min_clk = table->entries[0].ecclk;
 	cz_send_msg_to_smc(adev, PPSMC_MSG_GetMaxEclkLevel);
 	level = cz_get_argument(adev);
-	if (level < table->count)
+	if (level < table->count) {
 		clock = table->entries[level].ecclk;
-	else {
+	} else {
 		/* future BIOS would fix this error */
 		DRM_ERROR("Invalid VCE Voltage Dependency table entry.\n");
 		clock = table->entries[table->count - 1].ecclk;
@@ -913,9 +908,9 @@ static void cz_init_acp_limit(struct amdgpu_device *adev)
 	pi->acp_dpm.hard_min_clk = 0;
 	cz_send_msg_to_smc(adev, PPSMC_MSG_GetMaxAclkLevel);
 	level = cz_get_argument(adev);
-	if (level < table->count)
+	if (level < table->count) {
 		clock = table->entries[level].clk;
-	else {
+	} else {
 		DRM_ERROR("Invalid ACP Voltage Dependency table entry.\n");
 		clock = table->entries[table->count - 1].clk;
 	}
@@ -940,7 +935,6 @@ static void cz_init_sclk_threshold(struct amdgpu_device *adev)
 	struct cz_power_info *pi = cz_get_pi(adev);
 
 	pi->low_sclk_interrupt_threshold = 0;
-
 }
 
 static void cz_dpm_setup_asic(struct amdgpu_device *adev)
@@ -1213,7 +1207,7 @@ static int cz_enable_didt(struct amdgpu_device *adev, bool enable)
 	int ret;
 
 	if (pi->caps_sq_ramping || pi->caps_db_ramping ||
-			pi->caps_td_ramping || pi->caps_tcp_ramping) {
+	    pi->caps_td_ramping || pi->caps_tcp_ramping) {
 		if (adev->gfx.gfx_current_status != AMDGPU_GFX_SAFE_MODE) {
 			ret = cz_disable_cgpg(adev);
 			if (ret) {
@@ -1287,7 +1281,7 @@ static void cz_apply_state_adjust_rules(struct amdgpu_device *adev,
 	ps->force_high = false;
 	ps->need_dfs_bypass = true;
 	pi->video_start = new_rps->dclk || new_rps->vclk ||
-				new_rps->evclk || new_rps->ecclk;
+			  new_rps->evclk || new_rps->ecclk;
 
 	if ((new_rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) ==
 			ATOM_PPLIB_CLASSIFICATION_UI_BATTERY)
@@ -1345,7 +1339,6 @@ static int cz_dpm_enable(struct amdgpu_device *adev)
 	}
 
 	cz_reset_acp_boot_level(adev);
-
 	cz_update_current_ps(adev, adev->pm.dpm.boot_ps);
 
 	return 0;
@@ -1675,7 +1668,6 @@ static void cz_dpm_post_set_power_state(struct amdgpu_device *adev)
 	struct amdgpu_ps *ps = &pi->requested_rps;
 
 	cz_update_current_ps(adev, ps);
-
 }
 
 static int cz_dpm_force_highest(struct amdgpu_device *adev)
@@ -2207,7 +2199,6 @@ static int cz_update_vce_dpm(struct amdgpu_device *adev)
 	/* Stable Pstate is enabled and we need to set the VCE DPM to highest level */
 	if (pi->caps_stable_power_state) {
 		pi->vce_dpm.hard_min_clk = table->entries[table->count-1].ecclk;
-
 	} else { /* non-stable p-state cases. without vce.Arbiter.EcclkHardMin */
 		/* leave it as set by user */
 		/*pi->vce_dpm.hard_min_clk = table->entries[0].ecclk;*/
Signature · 6 lines
2.9.2

_______________________________________________
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): [email protected]

Reviewed-by Alex Deucher
#8 lore raw

RE: [PATCH 3/3] drm/amd/amdgpu: Tidy up cz_dpm.c

Quoted 11 lines

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Tom St Denis
Sent: Thursday, August 25, 2016 1:10 PM
To: [email protected]
Cc: StDenis, Tom
Subject: [PATCH 3/3] drm/amd/amdgpu: Tidy up cz_dpm.c

Various minor formatting changes.

For the series:

Quoted 150 lines
---
 drivers/gpu/drm/amd/amdgpu/cz_dpm.c | 31 +++++++++++------------------
--
 1 file changed, 11 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/cz_dpm.c +1 -6
index d97604386766..1e69c28392b3 100644
@@ -678,17 +678,12 @@ static void cz_reset_ap_mask(struct
 amdgpu_device *adev)
 	struct cz_power_info *pi = cz_get_pi(adev);
 
 	pi->active_process_mask = 0;
-
 }
 
 static int cz_dpm_download_pptable_from_smu(struct amdgpu_device
 *adev,
 							void **table)
 {
-	int ret = 0;
-
-	ret = cz_smu_download_pptable(adev, table);
-
-	return ret;
+	return cz_smu_download_pptable(adev, table);
 }

static int cz_dpm_upload_pptable_to_smu(struct amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/cz_dpm.c +2 -2
@@ -828,9 +823,9 @@ static void cz_init_sclk_limit(struct amdgpu_device
 *adev)
 	pi->sclk_dpm.hard_min_clk = 0;
 	cz_send_msg_to_smc(adev, PPSMC_MSG_GetMaxSclkLevel);
 	level = cz_get_argument(adev);
-	if (level < table->count)
+	if (level < table->count) {
 		clock = table->entries[level].clk;
-	else {
+	} else {
 		DRM_ERROR("Invalid SLCK Voltage Dependency table
 entry.\n");
drivers/gpu/drm/amd/amdgpu/cz_dpm.c +2 -2
 		clock = table->entries[table->count - 1].clk;
 	}
@@ -856,9 +851,9 @@ static void cz_init_uvd_limit(struct amdgpu_device
 *adev)
 	pi->uvd_dpm.hard_min_clk = 0;
 	cz_send_msg_to_smc(adev, PPSMC_MSG_GetMaxUvdLevel);
 	level = cz_get_argument(adev);
-	if (level < table->count)
+	if (level < table->count) {
 		clock = table->entries[level].vclk;
-	else {
+	} else {
 		DRM_ERROR("Invalid UVD Voltage Dependency table
 entry.\n");
drivers/gpu/drm/amd/amdgpu/cz_dpm.c +2 -2
 		clock = table->entries[table->count - 1].vclk;
 	}
@@ -884,9 +879,9 @@ static void cz_init_vce_limit(struct amdgpu_device
 *adev)
 	pi->vce_dpm.hard_min_clk = table->entries[0].ecclk;
 	cz_send_msg_to_smc(adev, PPSMC_MSG_GetMaxEclkLevel);
 	level = cz_get_argument(adev);
-	if (level < table->count)
+	if (level < table->count) {
 		clock = table->entries[level].ecclk;
-	else {
+	} else {
 		/* future BIOS would fix this error */
 		DRM_ERROR("Invalid VCE Voltage Dependency table

entry.\n");

drivers/gpu/drm/amd/amdgpu/cz_dpm.c +2 -2
 		clock = table->entries[table->count - 1].ecclk;
@@ -913,9 +908,9 @@ static void cz_init_acp_limit(struct amdgpu_device
 *adev)
 	pi->acp_dpm.hard_min_clk = 0;
 	cz_send_msg_to_smc(adev, PPSMC_MSG_GetMaxAclkLevel);
 	level = cz_get_argument(adev);
-	if (level < table->count)
+	if (level < table->count) {
 		clock = table->entries[level].clk;
-	else {
+	} else {
 		DRM_ERROR("Invalid ACP Voltage Dependency table
 entry.\n");
drivers/gpu/drm/amd/amdgpu/cz_dpm.c +0 -1
 		clock = table->entries[table->count - 1].clk;
 	}
@@ -940,7 +935,6 @@ static void cz_init_sclk_threshold(struct
 amdgpu_device *adev)
 	struct cz_power_info *pi = cz_get_pi(adev);
 
 	pi->low_sclk_interrupt_threshold = 0;
-
 }
 

static void cz_dpm_setup_asic(struct amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/cz_dpm.c +1 -1
@@ -1213,7 +1207,7 @@ static int cz_enable_didt(struct amdgpu_device
 *adev, bool enable)
 	int ret;
 
 	if (pi->caps_sq_ramping || pi->caps_db_ramping ||
-			pi->caps_td_ramping || pi->caps_tcp_ramping) {
+	    pi->caps_td_ramping || pi->caps_tcp_ramping) {
 		if (adev->gfx.gfx_current_status !=
 AMDGPU_GFX_SAFE_MODE) {
drivers/gpu/drm/amd/amdgpu/cz_dpm.c +1 -1
 			ret = cz_disable_cgpg(adev);
 			if (ret) {
@@ -1287,7 +1281,7 @@ static void cz_apply_state_adjust_rules(struct
 amdgpu_device *adev,
 	ps->force_high = false;
 	ps->need_dfs_bypass = true;
 	pi->video_start = new_rps->dclk || new_rps->vclk ||
-				new_rps->evclk || new_rps->ecclk;
+			  new_rps->evclk || new_rps->ecclk;
 
 	if ((new_rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) ==
drivers/gpu/drm/amd/amdgpu/cz_dpm.c +0 -1
 			ATOM_PPLIB_CLASSIFICATION_UI_BATTERY)
@@ -1345,7 +1339,6 @@ static int cz_dpm_enable(struct amdgpu_device
 *adev)
 	}
 
 	cz_reset_acp_boot_level(adev);
-
 	cz_update_current_ps(adev, adev->pm.dpm.boot_ps);
 
drivers/gpu/drm/amd/amdgpu/cz_dpm.c +0 -1
 	return 0;
@@ -1675,7 +1668,6 @@ static void cz_dpm_post_set_power_state(struct
 amdgpu_device *adev)
 	struct amdgpu_ps *ps = &pi->requested_rps;
 
 	cz_update_current_ps(adev, ps);
-
 }
 

static int cz_dpm_force_highest(struct amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/cz_dpm.c +0 -0
@@ -2207,7 +2199,6 @@ static int cz_update_vce_dpm(struct
 amdgpu_device *adev)
 	/* Stable Pstate is enabled and we need to set the VCE DPM to

highest level */

drivers/gpu/drm/amd/amdgpu/cz_dpm.c +0 -0
 	if (pi->caps_stable_power_state) {
 		pi->vce_dpm.hard_min_clk = table->entries[table->count-

1].ecclk;

drivers/gpu/drm/amd/amdgpu/cz_dpm.c +0 -1
-
 	} else { /* non-stable p-state cases. without vce.Arbiter.EcclkHardMin

*/

drivers/gpu/drm/amd/amdgpu/cz_dpm.c +0 -1
 		/* leave it as set by user */
 		/*pi->vce_dpm.hard_min_clk = table->entries[0].ecclk;*/
--

2.9.2

Quoted 4 lines

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

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