]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
usb: ehci: replace scnprintf() with sysfs_emit()
authorHendrik Hamerlinck <hendrik.hamerlinck@hammernet.be>
Mon, 23 Jun 2025 14:09:50 +0000 (16:09 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 24 Jun 2025 14:40:19 +0000 (15:40 +0100)
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>
drivers/usb/host/ehci-sysfs.c

index 8f75cb7b197cbaee0567772a22681bc2c4b6a8aa..5e6b545c30e6d8d3617042a5e90f69eb3de1b6af 100644 (file)
@@ -12,21 +12,17 @@ static ssize_t companion_show(struct device *dev,
                              char *buf)
 {
        struct ehci_hcd         *ehci;
-       int                     nports, index, n;
-       int                     count = PAGE_SIZE;
-       char                    *ptr = buf;
+       int                     nports, index;
+       int                     len = 0;
 
        ehci = hcd_to_ehci(dev_get_drvdata(dev));
        nports = HCS_N_PORTS(ehci->hcs_params);
 
        for (index = 0; index < nports; ++index) {
-               if (test_bit(index, &ehci->companion_ports)) {
-                       n = scnprintf(ptr, count, "%d\n", index + 1);
-                       ptr += n;
-                       count -= n;
-               }
+               if (test_bit(index, &ehci->companion_ports))
+                       len += sysfs_emit_at(buf, len, "%d\n", index + 1);
        }
-       return ptr - buf;
+       return len;
 }
 
 /*
@@ -70,11 +66,9 @@ static ssize_t uframe_periodic_max_show(struct device *dev,
                                        char *buf)
 {
        struct ehci_hcd         *ehci;
-       int                     n;
 
        ehci = hcd_to_ehci(dev_get_drvdata(dev));
-       n = scnprintf(buf, PAGE_SIZE, "%d\n", ehci->uframe_periodic_max);
-       return n;
+       return sysfs_emit(buf, "%d\n", ehci->uframe_periodic_max);
 }