Skip to contentSkip to conversation

usbip: vudc: Convert snprintf() to sysfs_emit()

PATCH In review Jules Irenge 2 participants 2 messages Oct 1, 2022 – Oct 3, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usbip: vudc: Convert snprintf() to sysfs_emit()

Coccinnelle reports a warning
Warning: Use scnprintf or sprintf

Following the advice on kernel documentation
https://www.kernel.org/doc/html/latest/filesystems/sysfs.html

For show(device *...) functions we should only use sysfs_emit() or sysfs_emit_at() especially when formatting the value to be returned to user space. Convert snprintf() to sysfs_emit()

---
 drivers/usb/usbip/vudc_sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/usbip/vudc_sysfs.c +1 -1
index c95e6b2bfd32..907a43a00896 100644
@@ -242,7 +242,7 @@ static ssize_t usbip_status_show(struct device *dev,
 	status = udc->ud.status;
 	spin_unlock_irq(&udc->ud.lock);
 
-	return snprintf(out, PAGE_SIZE, "%d\n", status);
+	return sysfs_emit(out, "%d\n", status);
 }
 static DEVICE_ATTR_RO(usbip_status);
 
Signature · 1 line
2.37.3
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · Jules Irenge

Coccinnelle reports a warning
Warning: Use scnprintf or sprintf

Following the advice on kernel documentation
https://www.kernel.org/doc/html/latest/filesystems/sysfs.html

For show(device *...) functions we should only use sysfs_emit() or sysfs_emit_at() especially when formatting the value to be returned to user space. Convert snprintf() to sysfs_emit()

---
  drivers/usb/usbip/vudc_sysfs.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/usbip/vudc_sysfs.c +0 -0
index c95e6b2bfd32..907a43a00896 100644

drivers/usb/usbip/vudc_sysfs.c static ssize_t usbip_status_show(struct device *dev, · line 248

Quoted 8 lines
drivers/usb/usbip/vudc_sysfs.c +1 -1
@@ -242,7 +242,7 @@ static ssize_t usbip_status_show(struct device *dev,
  	status = udc->ud.status;
  	spin_unlock_irq(&udc->ud.lock);
 
-	return snprintf(out, PAGE_SIZE, "%d\n", status);
+	return sysfs_emit(out, "%d\n", status);
  }
  static DEVICE_ATTR_RO(usbip_status);
 

Looks good to me.

Greg, Please pick this up.

thanks,
-- Shuah