Skip to contentSkip to conversation

amdgpu: replace snprintf in show functions with sysfs_emit

PATCH Applied Qing Wang 2 participants 2 messages Oct 15, 2021 – Oct 19, 2021

Subsystems (2)
lore
Share & tools
lore

Qing Wang

author
#0 lore raw

PATCH 1/1 amdgpu: replace snprintf in show functions with sysfs_emit

show() must not use snprintf() when formatting the value to be returned to user space.

Fix the following coccicheck warning:
drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c:427:
WARNING: use scnprintf or sprintf.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c +1 -1
index 2834981..faf4011 100644
@@ -424,7 +424,7 @@ static ssize_t show_##name(struct device *dev,				\
 	struct drm_device *ddev = dev_get_drvdata(dev);			\
 	struct amdgpu_device *adev = drm_to_adev(ddev);			\
 									\
-	return snprintf(buf, PAGE_SIZE, "0x%08x\n", adev->field);	\
+	return sysfs_emit(buf, "0x%08x\n", adev->field);	\
 }									\
 static DEVICE_ATTR(name, mode, show_##name, NULL)
 
Signature · 1 line
2.7.4
Applied
#1 lore raw

Applied. thanks!

Quoted 29 lines · Qing Wang

show() must not use snprintf() when formatting the value to be returned to user space.

Fix the following coccicheck warning:
drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c:427:
WARNING: use scnprintf or sprintf.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c +1 -2
index 2834981..faf4011 100644
@@ -424,7 +424,7 @@ static ssize_t show_##name(struct device *dev,                              \
        struct drm_device *ddev = dev_get_drvdata(dev);                 \
        struct amdgpu_device *adev = drm_to_adev(ddev);                 \
                                                                        \
-       return snprintf(buf, PAGE_SIZE, "0x%08x\n", adev->field);       \
+       return sysfs_emit(buf, "0x%08x\n", adev->field);        \
 }                                                                      \
 static DEVICE_ATTR(name, mode, show_##name, NULL)
 
--

2.7.4