* [PATCH] xfs: replace snprintf in show functions with sysfs_emit
@ 2021-10-13 3:29 Qing Wang
2021-10-14 16:37 ` Darrick J. Wong
2021-10-14 16:51 ` Joe Perches
0 siblings, 2 replies; 3+ messages in thread
From: Qing Wang @ 2021-10-13 3:29 UTC (permalink / raw)
To: Darrick J. Wong, linux-xfs, linux-kernel; +Cc: Qing Wang
coccicheck complains about the use of snprintf() in sysfs show functions.
Fix the coccicheck warning:
WARNING: use scnprintf or sprintf.
Use sysfs_emit instead of scnprintf or sprintf makes more sense.
Signed-off-by: Qing Wang <wangqing@vivo.com>
---
fs/xfs/xfs_sysfs.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/fs/xfs/xfs_sysfs.c b/fs/xfs/xfs_sysfs.c
index f1bc88f..3c171bf 100644
--- a/fs/xfs/xfs_sysfs.c
+++ b/fs/xfs/xfs_sysfs.c
@@ -104,7 +104,7 @@ bug_on_assert_show(
struct kobject *kobject,
char *buf)
{
- return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.bug_on_assert ? 1 : 0);
+ return sysfs_emit(buf, "%d\n", xfs_globals.bug_on_assert ? 1 : 0);
}
XFS_SYSFS_ATTR_RW(bug_on_assert);
@@ -134,7 +134,7 @@ log_recovery_delay_show(
struct kobject *kobject,
char *buf)
{
- return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.log_recovery_delay);
+ return sysfs_emit(buf, "%d\n", xfs_globals.log_recovery_delay);
}
XFS_SYSFS_ATTR_RW(log_recovery_delay);
@@ -164,7 +164,7 @@ mount_delay_show(
struct kobject *kobject,
char *buf)
{
- return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.mount_delay);
+ return sysfs_emit(buf, "%d\n", xfs_globals.mount_delay);
}
XFS_SYSFS_ATTR_RW(mount_delay);
@@ -187,7 +187,7 @@ always_cow_show(
struct kobject *kobject,
char *buf)
{
- return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.always_cow);
+ return sysfs_emit(buf, "%d\n", xfs_globals.always_cow);
}
XFS_SYSFS_ATTR_RW(always_cow);
@@ -223,7 +223,7 @@ pwork_threads_show(
struct kobject *kobject,
char *buf)
{
- return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.pwork_threads);
+ return sysfs_emit(buf, "%d\n", xfs_globals.pwork_threads);
}
XFS_SYSFS_ATTR_RW(pwork_threads);
#endif /* DEBUG */
@@ -326,7 +326,7 @@ log_head_lsn_show(
block = log->l_curr_block;
spin_unlock(&log->l_icloglock);
- return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
+ return sysfs_emit(buf, "%d:%d\n", cycle, block);
}
XFS_SYSFS_ATTR_RO(log_head_lsn);
@@ -340,7 +340,7 @@ log_tail_lsn_show(
struct xlog *log = to_xlog(kobject);
xlog_crack_atomic_lsn(&log->l_tail_lsn, &cycle, &block);
- return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
+ return sysfs_emit(buf, "%d:%d\n", cycle, block);
}
XFS_SYSFS_ATTR_RO(log_tail_lsn);
@@ -355,7 +355,7 @@ reserve_grant_head_show(
struct xlog *log = to_xlog(kobject);
xlog_crack_grant_head(&log->l_reserve_head.grant, &cycle, &bytes);
- return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
+ return sysfs_emit(buf, "%d:%d\n", cycle, bytes);
}
XFS_SYSFS_ATTR_RO(reserve_grant_head);
@@ -369,7 +369,7 @@ write_grant_head_show(
struct xlog *log = to_xlog(kobject);
xlog_crack_grant_head(&log->l_write_head.grant, &cycle, &bytes);
- return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
+ return sysfs_emit(buf, "%d:%d\n", cycle, bytes);
}
XFS_SYSFS_ATTR_RO(write_grant_head);
@@ -424,7 +424,7 @@ max_retries_show(
else
retries = cfg->max_retries;
- return snprintf(buf, PAGE_SIZE, "%d\n", retries);
+ return sysfs_emit(buf, "%d\n", retries);
}
static ssize_t
@@ -465,7 +465,7 @@ retry_timeout_seconds_show(
else
timeout = jiffies_to_msecs(cfg->retry_timeout) / MSEC_PER_SEC;
- return snprintf(buf, PAGE_SIZE, "%d\n", timeout);
+ return sysfs_emit(buf, "%d\n", timeout);
}
static ssize_t
@@ -503,7 +503,7 @@ fail_at_unmount_show(
{
struct xfs_mount *mp = err_to_mp(kobject);
- return snprintf(buf, PAGE_SIZE, "%d\n", mp->m_fail_unmount);
+ return sysfs_emit(buf, "%d\n", mp->m_fail_unmount);
}
static ssize_t
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] xfs: replace snprintf in show functions with sysfs_emit
2021-10-13 3:29 [PATCH] xfs: replace snprintf in show functions with sysfs_emit Qing Wang
@ 2021-10-14 16:37 ` Darrick J. Wong
2021-10-14 16:51 ` Joe Perches
1 sibling, 0 replies; 3+ messages in thread
From: Darrick J. Wong @ 2021-10-14 16:37 UTC (permalink / raw)
To: Qing Wang; +Cc: linux-xfs, linux-kernel
On Tue, Oct 12, 2021 at 08:29:31PM -0700, Qing Wang wrote:
> coccicheck complains about the use of snprintf() in sysfs show functions.
>
> Fix the coccicheck warning:
> WARNING: use scnprintf or sprintf.
>
> Use sysfs_emit instead of scnprintf or sprintf makes more sense.
>
> Signed-off-by: Qing Wang <wangqing@vivo.com>
This seems like a fairly straightforward conversion.
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
--D
> ---
> fs/xfs/xfs_sysfs.c | 24 ++++++++++++------------
> 1 file changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/fs/xfs/xfs_sysfs.c b/fs/xfs/xfs_sysfs.c
> index f1bc88f..3c171bf 100644
> --- a/fs/xfs/xfs_sysfs.c
> +++ b/fs/xfs/xfs_sysfs.c
> @@ -104,7 +104,7 @@ bug_on_assert_show(
> struct kobject *kobject,
> char *buf)
> {
> - return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.bug_on_assert ? 1 : 0);
> + return sysfs_emit(buf, "%d\n", xfs_globals.bug_on_assert ? 1 : 0);
> }
> XFS_SYSFS_ATTR_RW(bug_on_assert);
>
> @@ -134,7 +134,7 @@ log_recovery_delay_show(
> struct kobject *kobject,
> char *buf)
> {
> - return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.log_recovery_delay);
> + return sysfs_emit(buf, "%d\n", xfs_globals.log_recovery_delay);
> }
> XFS_SYSFS_ATTR_RW(log_recovery_delay);
>
> @@ -164,7 +164,7 @@ mount_delay_show(
> struct kobject *kobject,
> char *buf)
> {
> - return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.mount_delay);
> + return sysfs_emit(buf, "%d\n", xfs_globals.mount_delay);
> }
> XFS_SYSFS_ATTR_RW(mount_delay);
>
> @@ -187,7 +187,7 @@ always_cow_show(
> struct kobject *kobject,
> char *buf)
> {
> - return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.always_cow);
> + return sysfs_emit(buf, "%d\n", xfs_globals.always_cow);
> }
> XFS_SYSFS_ATTR_RW(always_cow);
>
> @@ -223,7 +223,7 @@ pwork_threads_show(
> struct kobject *kobject,
> char *buf)
> {
> - return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.pwork_threads);
> + return sysfs_emit(buf, "%d\n", xfs_globals.pwork_threads);
> }
> XFS_SYSFS_ATTR_RW(pwork_threads);
> #endif /* DEBUG */
> @@ -326,7 +326,7 @@ log_head_lsn_show(
> block = log->l_curr_block;
> spin_unlock(&log->l_icloglock);
>
> - return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
> + return sysfs_emit(buf, "%d:%d\n", cycle, block);
> }
> XFS_SYSFS_ATTR_RO(log_head_lsn);
>
> @@ -340,7 +340,7 @@ log_tail_lsn_show(
> struct xlog *log = to_xlog(kobject);
>
> xlog_crack_atomic_lsn(&log->l_tail_lsn, &cycle, &block);
> - return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
> + return sysfs_emit(buf, "%d:%d\n", cycle, block);
> }
> XFS_SYSFS_ATTR_RO(log_tail_lsn);
>
> @@ -355,7 +355,7 @@ reserve_grant_head_show(
> struct xlog *log = to_xlog(kobject);
>
> xlog_crack_grant_head(&log->l_reserve_head.grant, &cycle, &bytes);
> - return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
> + return sysfs_emit(buf, "%d:%d\n", cycle, bytes);
> }
> XFS_SYSFS_ATTR_RO(reserve_grant_head);
>
> @@ -369,7 +369,7 @@ write_grant_head_show(
> struct xlog *log = to_xlog(kobject);
>
> xlog_crack_grant_head(&log->l_write_head.grant, &cycle, &bytes);
> - return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
> + return sysfs_emit(buf, "%d:%d\n", cycle, bytes);
> }
> XFS_SYSFS_ATTR_RO(write_grant_head);
>
> @@ -424,7 +424,7 @@ max_retries_show(
> else
> retries = cfg->max_retries;
>
> - return snprintf(buf, PAGE_SIZE, "%d\n", retries);
> + return sysfs_emit(buf, "%d\n", retries);
> }
>
> static ssize_t
> @@ -465,7 +465,7 @@ retry_timeout_seconds_show(
> else
> timeout = jiffies_to_msecs(cfg->retry_timeout) / MSEC_PER_SEC;
>
> - return snprintf(buf, PAGE_SIZE, "%d\n", timeout);
> + return sysfs_emit(buf, "%d\n", timeout);
> }
>
> static ssize_t
> @@ -503,7 +503,7 @@ fail_at_unmount_show(
> {
> struct xfs_mount *mp = err_to_mp(kobject);
>
> - return snprintf(buf, PAGE_SIZE, "%d\n", mp->m_fail_unmount);
> + return sysfs_emit(buf, "%d\n", mp->m_fail_unmount);
> }
>
> static ssize_t
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] xfs: replace snprintf in show functions with sysfs_emit
2021-10-13 3:29 [PATCH] xfs: replace snprintf in show functions with sysfs_emit Qing Wang
2021-10-14 16:37 ` Darrick J. Wong
@ 2021-10-14 16:51 ` Joe Perches
1 sibling, 0 replies; 3+ messages in thread
From: Joe Perches @ 2021-10-14 16:51 UTC (permalink / raw)
To: Qing Wang, Darrick J. Wong, linux-xfs, linux-kernel
On Tue, 2021-10-12 at 20:29 -0700, Qing Wang wrote:
> coccicheck complains about the use of snprintf() in sysfs show functions.
>
> Fix the coccicheck warning:
> WARNING: use scnprintf or sprintf.
>
> Use sysfs_emit instead of scnprintf or sprintf makes more sense.
[]
> diff --git a/fs/xfs/xfs_sysfs.c b/fs/xfs/xfs_sysfs.c
[]
> @@ -104,7 +104,7 @@ bug_on_assert_show(
> struct kobject *kobject,
> char *buf)
> {
> - return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.bug_on_assert ? 1 : 0);
> + return sysfs_emit(buf, "%d\n", xfs_globals.bug_on_assert ? 1 : 0);
trivia:
The ?: is not necessary as xfs_globals.bug_on_assert is a bool
and would have an implicit cast done.
return sysfs_emit(buf, "%d\n", xfs_globals.bug_on_assert);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-10-14 16:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-13 3:29 [PATCH] xfs: replace snprintf in show functions with sysfs_emit Qing Wang
2021-10-14 16:37 ` Darrick J. Wong
2021-10-14 16:51 ` Joe Perches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).