Re: [PATCH net-next] net: bridge: use sysfs_emit instead of sprintf

Nikolay Aleksandrov <[email protected]>
Newsgroups gmane.linux.network.bridge,gmane.linux.network,gmane.linux.kernel
Message-ID <[email protected]>
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 <[email protected]>
> ---
> 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 <[email protected]>

Thanks,
  Nik
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.