comedi: Convert snprintf() to sysfs_emit()
PATCH v2 1/1 comedi: Convert snprintf() to sysfs_emit()
Coccinnelle reports a warning
Warning: Use scnprintf or sprintf
Adding to that, there has been a slow migration from snprintf to scnprintf. This LWN article explains the rationale for this change
https: //lwn.net/Articles/69419/
ie. snprintf() returns what *would* be the resulting length,
while scnprintf() returns the actual length.
However following the advice on
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.
Hence here
We convert to sysfs_emit() that even does better and shorten the code using the same rationale of scnprintf()
---
v2: Replace scnprintf() with sysfs_emit()
drivers/comedi/comedi_fops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/comedi/comedi_fops.c +1 -1
@@ -396,7 +396,7 @@ static ssize_t max_read_buffer_kb_show(struct device *csdev,mutex_unlock (&dev->mutex);comedi_dev_put (dev); -return snprintf (buf,PAGE_SIZE ,"%u\n" , size); +return sysfs_emit (buf,"%u\n" , size); } static ssize_t max_read_buffer_kb_store(struct device *csdev,
Signature · 1 line
2.37.3
Quoted 9 lines · Jules Irenge
Coccinnelle reports a warning
Warning: Use scnprintf or sprintfAdding to that, there has been a slow migration from snprintf to scnprintf. This LWN article explains the rationale for this change
https: //lwn.net/Articles/69419/
ie.snprintf()returns what *would* be the resulting length,
whilescnprintf()returns the actual length.
None of this is needed or relevant for this change.
Quoted 24 lines
However following the advice on
https://www.kernel.org/doc/html/latest/filesystems/sysfs.htmlFor
show(device *...)functions we should only usesysfs_emit()orsysfs_emit_at()
especially when formatting the value to be returned to user space.Hence here
We convert tosysfs_emit()that even does better and shorten the code using the same rationale ofscnprintf()Signed-off-by Jules Irenge <[email protected]>---
v2: Replace
scnprintf()withsysfs_emit()drivers/comedi/comedi_fops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/comedi/comedi_fops.c +0
-0
drivers/comedi/comedi_fops.c static ssize_t max_read_buffer_kb_show(struct device *csdev, · line 402
Quoted 8 lines
drivers/comedi/comedi_fops.c +1
-1@@ -396,7 +396,7 @@ static ssize_t max_read_buffer_kb_show(struct device *csdev,mutex_unlock (&dev->mutex);comedi_dev_put (dev); -return snprintf (buf,PAGE_SIZE ,"%u\n" , size); +return sysfs_emit (buf,"%u\n" , size); } static ssize_t max_read_buffer_kb_store(struct device *csdev,
Does not apply to my tree :(
thanks,
greg k-h