[PATCH 2/2] firewire: Convert snprintf/sprintf to sysfs_emit

Li Zhijian
2024-01-22T05:40:02Z

Per filesystems/sysfs.rst, show() should only use sysfs_emit()
or sysfs_emit_at() when formatting the value to be returned to user space.

coccinelle complains that there are still a couple of functions that use
snprintf(). Convert them to sysfs_emit().

> drivers/firewire/core-device.c:326:8-16: WARNING: please use sysfs_emit or sysfs_emit_at

No functional change intended

Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
"[PATCH 00/42] Fix coccicheck warnings"[1] is trying to fix all warnings
reported by coccicheck. firewire introduce newly abused snprintf case.
[1] https://lore.kernel.org/lkml/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
drivers/firewire/core-device.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
index 47d6cb3dc916..790985479ff3 100644
--- a/drivers/firewire/core-device.c
+++ b/drivers/firewire/core-device.c
@@ -323,7 +323,7 @@ static ssize_t show_immediate(struct device *dev,
if (value < 0)
return -ENOENT;

- return snprintf(buf, PAGE_SIZE, "0x%06x\n", value);
+ return sysfs_emit(buf, "0x%06x\n", value);
}

#define IMMEDIATE_ATTR(name, key) \
@@ -474,7 +474,7 @@ static ssize_t is_local_show(struct device *dev,
{
struct fw_device *device = fw_device(dev);

- return sprintf(buf, "%u\n", device->is_local);
+ return sysfs_emit(buf, "%u\n", device->is_local);
}

static int units_sprintf(char *buf, const u32 *directory)
--
2.29.2