Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: ehci: replace scnprintf() with sysfs_emit()

Per Documentation/filesystems/sysfs.rst, show() methods should only
use sysfs_emit() or sysfs_emit_at() when formatting values to be
returned to userspace.

Convert the uses of scnprintf() in sysfs show() methods to
sysfs_emit() and sysfs_emit_at() for better safety and consistency.

Signed-off-by: Hendrik Hamerlinck <hendrik.hamerlinck@hammernet.be>
Link: https://lore.kernel.org/r/20250623140950.61568-1-hendrik.hamerlinck@hammernet.be
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Hendrik Hamerlinck and committed by
Greg Kroah-Hartman
4f4b2f13 711d41ab

+6 -12
+6 -12
drivers/usb/host/ehci-sysfs.c
··· 12 12 char *buf) 13 13 { 14 14 struct ehci_hcd *ehci; 15 - int nports, index, n; 16 - int count = PAGE_SIZE; 17 - char *ptr = buf; 15 + int nports, index; 16 + int len = 0; 18 17 19 18 ehci = hcd_to_ehci(dev_get_drvdata(dev)); 20 19 nports = HCS_N_PORTS(ehci->hcs_params); 21 20 22 21 for (index = 0; index < nports; ++index) { 23 - if (test_bit(index, &ehci->companion_ports)) { 24 - n = scnprintf(ptr, count, "%d\n", index + 1); 25 - ptr += n; 26 - count -= n; 27 - } 22 + if (test_bit(index, &ehci->companion_ports)) 23 + len += sysfs_emit_at(buf, len, "%d\n", index + 1); 28 24 } 29 - return ptr - buf; 25 + return len; 30 26 } 31 27 32 28 /* ··· 66 70 char *buf) 67 71 { 68 72 struct ehci_hcd *ehci; 69 - int n; 70 73 71 74 ehci = hcd_to_ehci(dev_get_drvdata(dev)); 72 - n = scnprintf(buf, PAGE_SIZE, "%d\n", ehci->uframe_periodic_max); 73 - return n; 75 + return sysfs_emit(buf, "%d\n", ehci->uframe_periodic_max); 74 76 } 75 77 76 78