drm/amdgpu: switch XGMI sysfs show helpers to sysfs_emit_at()
Subsystems (2)
PATCH 1/1 drm/amdgpu: switch XGMI sysfs show helpers to sysfs_emit_at()
The XGMI sysfs show helpers amdgpu_xgmi_show_num_hops() and amdgpu_xgmi_show_num_links() currently populate the output buffer with sprintf() and then call sysfs_emit(buf, "%s\n", buf) to append the final newline.
Convert both helpers to use sysfs_emit_at() while tracking the current offset. This keeps buffer construction in the sysfs helpers, avoids feeding the output buffer back into the final formatted write, and matches the style already used by amdgpu_xgmi_show_connected_port_num().
--- drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +6 -6
@@ -469,12 +469,12 @@ static ssize_t amdgpu_xgmi_show_num_hops(struct device *dev,struct drm_device *ddev =dev_get_drvdata (dev);struct amdgpu_device *adev =drm_to_adev (ddev);struct psp_xgmi_topology_info *top = &adev->psp.xgmi_context.top_info; -int i; +int i, offset =0 ;for (i =0 ; i < top->num_nodes; i++) -sprintf (buf +3 * i,"%02x " , top->nodes[i].num_hops); + offset +=sysfs_emit_at (buf, offset,"%02x " , top->nodes[i].num_hops); -return sysfs_emit (buf,"%s\n" , buf); +return offset +sysfs_emit_at (buf, offset,"\n" ); } static ssize_t amdgpu_xgmi_show_num_links(struct device *dev,
@@ -484,12 +484,12 @@ static ssize_t amdgpu_xgmi_show_num_links(struct device *dev,struct drm_device *ddev =dev_get_drvdata (dev);struct amdgpu_device *adev =drm_to_adev (ddev);struct psp_xgmi_topology_info *top = &adev->psp.xgmi_context.top_info; -int i; +int i, offset =0 ;for (i =0 ; i < top->num_nodes; i++) -sprintf (buf +3 * i,"%02x " , top->nodes[i].num_links); + offset +=sysfs_emit_at (buf, offset,"%02x " , top->nodes[i].num_links); -return sysfs_emit (buf,"%s\n" , buf); +return offset +sysfs_emit_at (buf, offset,"\n" ); } static ssize_t amdgpu_xgmi_show_connected_port_num(struct device *dev,
Signature · 1 line
2.50.1 (Apple Git-155)
Alex Deucher
AppliedApplied. Thanks!
Alex
Quoted 56 lines · David Baum
The XGMI sysfs show helpers
amdgpu_xgmi_show_num_hops()andamdgpu_xgmi_show_num_links()currently populate the output buffer withsprintf()and then callsysfs_emit(buf, "%s\n", buf)to append the final newline.Convert both helpers to use
sysfs_emit_at()while tracking the current offset. This keeps buffer construction in the sysfs helpers, avoids feeding the output buffer back into the final formatted write, and matches the style already used byamdgpu_xgmi_show_connected_port_num().Signed-off-by David Baum <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +6
-7@@ -469,12 +469,12 @@ static ssize_t amdgpu_xgmi_show_num_hops(struct device *dev,struct drm_device *ddev =dev_get_drvdata (dev);struct amdgpu_device *adev =drm_to_adev (ddev);struct psp_xgmi_topology_info *top = &adev->psp.xgmi_context.top_info; -int i; +int i, offset =0 ;for (i =0 ; i < top->num_nodes; i++) -sprintf (buf +3 * i,"%02x " , top->nodes[i].num_hops); + offset +=sysfs_emit_at (buf, offset,"%02x " , top->nodes[i].num_hops); -return sysfs_emit (buf,"%s\n" , buf); +return offset +sysfs_emit_at (buf, offset,"\n" ); } static ssize_t amdgpu_xgmi_show_num_links(struct device *dev,@@ -484,12 +484,12 @@ static ssize_t amdgpu_xgmi_show_num_links(struct device *dev,struct drm_device *ddev =dev_get_drvdata (dev);struct amdgpu_device *adev =drm_to_adev (ddev);struct psp_xgmi_topology_info *top = &adev->psp.xgmi_context.top_info; -int i; +int i, offset =0 ;for (i =0 ; i < top->num_nodes; i++) -sprintf (buf +3 * i,"%02x " , top->nodes[i].num_links); + offset +=sysfs_emit_at (buf, offset,"%02x " , top->nodes[i].num_links); -return sysfs_emit (buf,"%s\n" , buf); +return offset +sysfs_emit_at (buf, offset,"\n" ); } static ssize_t amdgpu_xgmi_show_connected_port_num(struct device *dev, --2.50.1 (Apple Git-155)