<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Reviewed-by: Alex Deucher <alexander.deucher@amd.com><br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Evan Quan <evan.quan@amd.com><br>
<b>Sent:</b> Thursday, July 25, 2019 12:23 AM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Quan, Evan <Evan.Quan@amd.com><br>
<b>Subject:</b> [PATCH] drm/amd/powerplay: fix null pointer dereference around dpm state relates</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">DPM state relates are not supported on the new SW SMU ASICs. But still<br>
it's not OK to trigger null pointer dereference on accessing them.<br>
<br>
Change-Id: I368d108fbea438ed5d9e3b849d006ddd5308052b<br>
Signed-off-by: Evan Quan <evan.quan@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c     | 18 +++++++++++++-----<br>
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c |  3 ++-<br>
 2 files changed, 15 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
index 304626b21a8c..61312b02b5c7 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
@@ -209,12 +209,16 @@ static ssize_t amdgpu_get_dpm_state(struct device *dev,<br>
         struct amdgpu_device *adev = ddev->dev_private;<br>
         enum amd_pm_state_type pm;<br>
 <br>
-       if (is_support_sw_smu(adev) && adev->smu.ppt_funcs->get_current_power_state)<br>
-               pm = amdgpu_smu_get_current_power_state(adev);<br>
-       else if (adev->powerplay.pp_funcs->get_current_power_state)<br>
+       if (is_support_sw_smu(adev)) {<br>
+               if (adev->smu.ppt_funcs->get_current_power_state)<br>
+                       pm = amdgpu_smu_get_current_power_state(adev);<br>
+               else<br>
+                       pm = adev->pm.dpm.user_state;<br>
+       } else if (adev->powerplay.pp_funcs->get_current_power_state) {<br>
                 pm = amdgpu_dpm_get_current_power_state(adev);<br>
-       else<br>
+       } else {<br>
                 pm = adev->pm.dpm.user_state;<br>
+       }<br>
 <br>
         return snprintf(buf, PAGE_SIZE, "%s\n",<br>
                         (pm == POWER_STATE_TYPE_BATTERY) ? "battery" :<br>
@@ -241,7 +245,11 @@ static ssize_t amdgpu_set_dpm_state(struct device *dev,<br>
                 goto fail;<br>
         }<br>
 <br>
-       if (adev->powerplay.pp_funcs->dispatch_tasks) {<br>
+       if (is_support_sw_smu(adev)) {<br>
+               mutex_lock(&adev->pm.mutex);<br>
+               adev->pm.dpm.user_state = state;<br>
+               mutex_unlock(&adev->pm.mutex);<br>
+       } else if (adev->powerplay.pp_funcs->dispatch_tasks) {<br>
                 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_ENABLE_USER_STATE, &state);<br>
         } else {<br>
                 mutex_lock(&adev->pm.mutex);<br>
diff --git a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c<br>
index a5079b93caa3..3ecd67e6e65c 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c<br>
+++ b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c<br>
@@ -304,7 +304,8 @@ int smu_get_power_num_states(struct smu_context *smu,<br>
 <br>
         /* not support power state */<br>
         memset(state_info, 0, sizeof(struct pp_states_info));<br>
-       state_info->nums = 0;<br>
+       state_info->nums = 1;<br>
+       state_info->states[0] = POWER_STATE_TYPE_DEFAULT;<br>
 <br>
         return 0;<br>
 }<br>
-- <br>
2.22.0<br>
<br>
_______________________________________________<br>
amd-gfx mailing list<br>
amd-gfx@lists.freedesktop.org<br>
<a href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a></div>
</span></font></div>
</body>
</html>