Re: [PATCH net-next] net: bridge: use sysfs_emit instead of sprintf
From: Nikolay Aleksandrov <razor@blackwall.org>
Date: 2026-02-01 08:29:17
Also in:
bridge, lkml
From: Nikolay Aleksandrov <razor@blackwall.org>
Date: 2026-02-01 08:29:17
Also in:
bridge, lkml
On 31/01/2026 18:53, David Corvaglia wrote:
Replace sprintf with sysfs_emit in sysfs show() methods as outlined in Documentation/filesystems/sysfs.rst. sysfs_emit is preferred to sprintf in sysfs show() methods as it is safer with buffer handling. Signed-off-by: David Corvaglia <redacted> --- This is my first patch to the kernel! I've been able to build and boot with the patch. I also tested the sysfs reads and they seem to be correct. Any feedback is appreciated. net/bridge/br_stp_if.c | 2 +- net/bridge/br_sysfs_br.c | 84 ++++++++++++++++++++-------------------- net/bridge/br_sysfs_if.c | 32 +++++++-------- 3 files changed, 59 insertions(+), 59 deletions(-)
Hi, IIUC it is safer because it takes into account the provided buffer's size (PAGE_SIZE). I'm saying it for the curious as I only found in Documentation/filesystems/sysfs.rst: "- New implementations of show() methods should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space." Which does say "new implementations", also most of these are numbers and cannot really fill the provided buffer, there is one instance of a string but it is an interface name, so that is limited as well. That being said, I'm ok with switching to sysfs_emit() and the patch looks good to me so: Acked-by: Nikolay Aleksandrov <razor@blackwall.org> Thanks, Nik