Re: [PATCH linux-next] ocfs2: use sysfs_emit() instead of scnprintf().

From: Jiri Slaby
Date: Mon Mar 17 2025 - 02:21:04 EST


On 15. 03. 25, 7:16, xie.ludan@xxxxxxxxxx wrote:
From: XieLudan <xie.ludan@xxxxxxxxxx>


Follow the advice in Documentation/filesystems/sysfs.rst:

show() should only use sysfs_emit() or sysfs_emit_at() when formatting

the value to be returned to user space.


Signed-off-by: XieLudan <xie.ludan@xxxxxxxxxx>

---

 fs/ocfs2/cluster/heartbeat.c | 10 +++++-----

 1 file changed, 5 insertions(+), 5 deletions(-)


diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c

index 724350925aff..8282fc193906 100644

--- a/fs/ocfs2/cluster/heartbeat.c

+++ b/fs/ocfs2/cluster/heartbeat.c

@@ -1308,7 +1308,7 @@ static int o2hb_debug_open(struct inode *inode, struct file *file)

case O2HB_DB_TYPE_REGION_NUMBER:

reg = (struct o2hb_region *)db->db_data;

-out += scnprintf(buf + out, PAGE_SIZE - out, "%d\n",

+out += sysfs_emit(buf + out, "%d\n",


This is wrong too [1].

[1] https://lore.kernel.org/all/9c552d9a-2d46-4069-a9c4-35fab857bfc3@xxxxxxxxxx/

regards,
--
js
suse labs