From 711d41ab4a0e4230e394fd5da5b85604ddb9fc51 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hanne-Lotta=20M=C3=A4enp=C3=A4=C3=A4?= Date: Sat, 21 Jun 2025 19:40:05 +0300 Subject: [PATCH] usb: core: Use sysfs_emit_at() when showing dynamic IDs MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When formatting the dynamic USB device IDs to show to the user space, instead of scnprintf() function use sysfs_emit_at(). The functions are equivalent, but using the latter is recommended as it ensures that no buffer overruns occur. Testing the change can be done by assigning new IDs to the USB driver's sysfs attribute new_id, and then checking that the same values are returned. For example: echo 4533 7515 > /sys/bus/usb/drivers/usbfs/new_id cat /sys/bus/usb/drivers/usbfs/new_id The output should match the assigned IDs (4533 7515). Signed-off-by: Hanne-Lotta Mäenpää Link: https://lore.kernel.org/r/20250621164005.4004-1-hannelotta@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/driver.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 460d4dde5994e..c3177034b779e 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -119,11 +119,11 @@ ssize_t usb_show_dynids(struct usb_dynids *dynids, char *buf) guard(mutex)(&usb_dynids_lock); list_for_each_entry(dynid, &dynids->list, node) if (dynid->id.bInterfaceClass != 0) - count += scnprintf(&buf[count], PAGE_SIZE - count, "%04x %04x %02x\n", + count += sysfs_emit_at(&buf[count], count, "%04x %04x %02x\n", dynid->id.idVendor, dynid->id.idProduct, dynid->id.bInterfaceClass); else - count += scnprintf(&buf[count], PAGE_SIZE - count, "%04x %04x\n", + count += sysfs_emit_at(&buf[count], count, "%04x %04x\n", dynid->id.idVendor, dynid->id.idProduct); return count; } -- 2.47.3