<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:15pt;" align="Left">
[AMD Official Use Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Reviewed-by: Kevin Wang <kevin1.wang@amd.com></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Best Regards,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Kevin</div>
<div id="appendonsend"></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Darren Powell <darren.powell@amd.com><br>
<b>Sent:</b> Wednesday, June 16, 2021 12:31 PM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Powell, Darren <Darren.Powell@amd.com><br>
<b>Subject:</b> [PATCH] amdgpu/pm: replaced snprintf usage in amdgpu_pm.c with sysfs_emit</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">replaced snprintf usage in amdgpu_pm.c with sysfs_emit<br>
 fixed warning on comparing int with uint32_t in amdgpu_get_pp_num_states()<br>
<br>
== Test ==<br>
AMDGPU_PCI_ADDR=`lspci -nn | grep "VGA\|Display" | cut -d " " -f 1`<br>
AMDGPU_HWMON=`ls -la /sys/class/hwmon | grep $AMDGPU_PCI_ADDR | cut -d " " -f 10`<br>
HWMON_DIR=/sys/class/hwmon/${AMDGPU_HWMON}<br>
<br>
lspci -nn | grep "VGA\|Display"  > scnprintf.test.log<br>
FILES="pp_num_states<br>
pp_od_clk_voltage<br>
pp_features<br>
pp_dpm_sclk<br>
pp_dpm_mclk<br>
pp_dpm_socclk<br>
pp_dpm_fclk<br>
pp_dpm_vclk<br>
pp_dpm_dclk<br>
pp_dpm_dcefclk<br>
pp_power_profile_mode "<br>
<br>
for f in $FILES<br>
do<br>
  echo === $f === >> scnprintf.test.log<br>
  cat $HWMON_DIR/device/$f >> scnprintf.test.log<br>
done<br>
<br>
Signed-off-by: Darren Powell <darren.powell@amd.com><br>
---<br>
 drivers/gpu/drm/amd/pm/amdgpu_pm.c | 27 ++++++++++++++-------------<br>
 1 file changed, 14 insertions(+), 13 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c<br>
index b2335a1d3f98..a276ebad47e6 100644<br>
--- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c<br>
+++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c<br>
@@ -411,7 +411,8 @@ static ssize_t amdgpu_get_pp_num_states(struct device *dev,<br>
         struct amdgpu_device *adev = drm_to_adev(ddev);<br>
         const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;<br>
         struct pp_states_info data;<br>
-       int i, buf_len, ret;<br>
+       uint32_t i;<br>
+       int buf_len, ret;<br>
 <br>
         if (amdgpu_in_reset(adev))<br>
                 return -EPERM;<br>
@@ -433,9 +434,9 @@ static ssize_t amdgpu_get_pp_num_states(struct device *dev,<br>
         pm_runtime_mark_last_busy(ddev->dev);<br>
         pm_runtime_put_autosuspend(ddev->dev);<br>
 <br>
-       buf_len = snprintf(buf, PAGE_SIZE, "states: %d\n", data.nums);<br>
+       buf_len = sysfs_emit(buf, "states: %d\n", data.nums);<br>
         for (i = 0; i < data.nums; i++)<br>
-               buf_len += snprintf(buf + buf_len, PAGE_SIZE, "%d %s\n", i,<br>
+               buf_len += sysfs_emit_at(buf, buf_len, "%d %s\n", i,<br>
                                 (data.states[i] == POWER_STATE_TYPE_INTERNAL_BOOT) ? "boot" :<br>
                                 (data.states[i] == POWER_STATE_TYPE_BATTERY) ? "battery" :<br>
                                 (data.states[i] == POWER_STATE_TYPE_BALANCED) ? "balanced" :<br>
@@ -923,7 +924,7 @@ static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,<br>
                 size += amdgpu_dpm_print_clock_levels(adev, OD_RANGE, buf+size);<br>
                 size += amdgpu_dpm_print_clock_levels(adev, OD_CCLK, buf+size);<br>
         } else {<br>
-               size = snprintf(buf, PAGE_SIZE, "\n");<br>
+               size = sysfs_emit(buf, "\n");<br>
         }<br>
         pm_runtime_mark_last_busy(ddev->dev);<br>
         pm_runtime_put_autosuspend(ddev->dev);<br>
@@ -1009,7 +1010,7 @@ static ssize_t amdgpu_get_pp_features(struct device *dev,<br>
         if (adev->powerplay.pp_funcs->get_ppfeature_status)<br>
                 size = amdgpu_dpm_get_ppfeature_status(adev, buf);<br>
         else<br>
-               size = snprintf(buf, PAGE_SIZE, "\n");<br>
+               size = sysfs_emit(buf, "\n");<br>
 <br>
         pm_runtime_mark_last_busy(ddev->dev);<br>
         pm_runtime_put_autosuspend(ddev->dev);<br>
@@ -1070,7 +1071,7 @@ static ssize_t amdgpu_get_pp_dpm_clock(struct device *dev,<br>
         if (adev->powerplay.pp_funcs->print_clock_levels)<br>
                 size = amdgpu_dpm_print_clock_levels(adev, type, buf);<br>
         else<br>
-               size = snprintf(buf, PAGE_SIZE, "\n");<br>
+               size = sysfs_emit(buf, "\n");<br>
 <br>
         pm_runtime_mark_last_busy(ddev->dev);<br>
         pm_runtime_put_autosuspend(ddev->dev);<br>
@@ -1469,7 +1470,7 @@ static ssize_t amdgpu_get_pp_power_profile_mode(struct device *dev,<br>
         if (adev->powerplay.pp_funcs->get_power_profile_mode)<br>
                 size = amdgpu_dpm_get_power_profile_mode(adev, buf);<br>
         else<br>
-               size = snprintf(buf, PAGE_SIZE, "\n");<br>
+               size = sysfs_emit(buf, "\n");<br>
 <br>
         pm_runtime_mark_last_busy(ddev->dev);<br>
         pm_runtime_put_autosuspend(ddev->dev);<br>
@@ -2931,9 +2932,9 @@ static ssize_t amdgpu_hwmon_show_power_cap_max(struct device *dev,<br>
                 r = -ENODATA;<br>
 <br>
         if (!r)<br>
-               size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);<br>
+               size = sysfs_emit(buf, "%u\n", limit * 1000000);<br>
         else<br>
-               size = snprintf(buf, PAGE_SIZE, "\n");<br>
+               size = sysfs_emit(buf, "\n");<br>
 <br>
         pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);<br>
         pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
@@ -2971,9 +2972,9 @@ static ssize_t amdgpu_hwmon_show_power_cap(struct device *dev,<br>
                 r = -ENODATA;<br>
 <br>
         if (!r)<br>
-               size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);<br>
+               size = sysfs_emit(buf, "%u\n", limit * 1000000);<br>
         else<br>
-               size = snprintf(buf, PAGE_SIZE, "\n");<br>
+               size = sysfs_emit(buf, "\n");<br>
 <br>
         pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);<br>
         pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
@@ -3011,9 +3012,9 @@ static ssize_t amdgpu_hwmon_show_power_cap_default(struct device *dev,<br>
                 r = -ENODATA;<br>
 <br>
         if (!r)<br>
-               size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);<br>
+               size = sysfs_emit(buf, "%u\n", limit * 1000000);<br>
         else<br>
-               size = snprintf(buf, PAGE_SIZE, "\n");<br>
+               size = sysfs_emit(buf, "\n");<br>
 <br>
         pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);<br>
         pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
-- <br>
2.31.1<br>
<br>
_______________________________________________<br>
amd-gfx mailing list<br>
amd-gfx@lists.freedesktop.org<br>
<a href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7CKevin1.Wang%40amd.com%7Ca4803946245b4521d26e08d9307f9e27%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637594146951324361%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=FgYkesFOLYQAfD2ZS6KFFO3soJm8Xutyv6nrJLivx%2Bw%3D&amp;reserved=0">https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7CKevin1.Wang%40amd.com%7Ca4803946245b4521d26e08d9307f9e27%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637594146951324361%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=FgYkesFOLYQAfD2ZS6KFFO3soJm8Xutyv6nrJLivx%2Bw%3D&amp;reserved=0</a><br>
</div>
</span></font></div>
</div>
</body>
</html>