fs/xfs: use scnprintf() in show functions
PATCH 1/1 fs/xfs: use scnprintf() in show functions
Replace all snprintf() instances with scnprintf(). snprintf() returns the number of bytes that would have been written had there been enough space. For sysfs attributes, snprintf() should not be used for the show() method. Instead use scnprintf() which returns the number of bytes actually written.
--- fs/xfs/xfs_sysfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/xfs/xfs_sysfs.c +3 -3
@@ -257,7 +257,7 @@ larp_show(struct kobject *kobject, char *buf) { - return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.larp); + return scnprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.larp); }XFS_SYSFS_ATTR_RW (larp);
@@ -283,7 +283,7 @@ bload_leaf_slack_show(struct kobject *kobject, char *buf) { - return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.bload_leaf_slack); + return scnprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.bload_leaf_slack); }XFS_SYSFS_ATTR_RW (bload_leaf_slack);
@@ -309,7 +309,7 @@ bload_node_slack_show(struct kobject *kobject, char *buf) { - return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.bload_node_slack); + return scnprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.bload_node_slack); }XFS_SYSFS_ATTR_RW (bload_node_slack);
Signature · 1 line
2.49.0
Quoted 5 lines · Pranav Tyagi
Replace all
snprintf()instances withscnprintf().snprintf()returns the number of bytes that would have been written had there been enough space. For sysfs attributes,snprintf()should not be used for theshow()method. Instead usescnprintf()which returns the number of bytes actually written.
No, please use sysfs_emit() if you really want to change this.
Quoted 11 lines
Signed-off-by Pranav Tyagi <[email protected]>--- fs/xfs/xfs_sysfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)fs/xfs/xfs_sysfs.c +0
-0
fs/xfs/xfs_sysfs.c larp_show( · line 260
Quoted 4 lines
fs/xfs/xfs_sysfs.c +0
-1@@ -257,7 +257,7 @@ larp_show(struct kobject *kobject, char *buf) { - return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.larp);
There is nothing wrong with the original code here, you could use sprintf() and it too is ok. So this type of change is not needed. But again, if you really want to, use sysfs_emit() instead.
Same for all the other show() callback changes you just made.
thanks,
greg k-h
Quoted 30 lines · Greg KH
Quoted 5 lines · Pranav Tyagi
Replace all
snprintf()instances withscnprintf().snprintf()returns the number of bytes that would have been written had there been enough space. For sysfs attributes,snprintf()should not be used for theshow()method. Instead usescnprintf()which returns the number of bytes actually written.No, please use
sysfs_emit()if you really want to change this.Quoted 11 lines
Signed-off-by Pranav Tyagi <[email protected]>--- fs/xfs/xfs_sysfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)fs/xfs/xfs_sysfs.c +0
-0fs/xfs/xfs_sysfs.c larp_show( · line 260
Quoted 4 lines
fs/xfs/xfs_sysfs.c +0
-1@@ -257,7 +257,7 @@ larp_show(struct kobject *kobject, char *buf) { - return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.larp);There is nothing wrong with the original code here, you could use
sprintf()and it too is ok. So this type of change is not needed. But again, if you really want to, usesysfs_emit()instead.
Quoted 5 lines
Same for all the other
show()callback changes you just made.thanks,
greg k-h
Hi,
Thanks for the feedback. I understand the original code is perfectly fine. All these show callback changes were intended as cleanups. I'll drop these patches. And will use sysfs_emit() if I ever have to.
Regards
Pranav Tyagi