public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: <ye.xingchen@zte.com.cn>
To: <hubcap@omnibond.com>
Cc: <martin@omnibond.com>, <devel@lists.orangefs.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH] orangefs: use sysfs_emit() to instead of scnprintf()
Date: Mon, 5 Dec 2022 19:03:39 +0800 (CST)	[thread overview]
Message-ID: <202212051903396321367@zte.com.cn> (raw)

From: ye xingchen <ye.xingchen@zte.com.cn>

Follow the advice of the Documentation/filesystems/sysfs.rst and show()
should only use sysfs_emit() or sysfs_emit_at() when formatting the
value to be returned to user space.

Signed-off-by: ye xingchen <ye.xingchen@zte.com.cn>
---
 fs/orangefs/orangefs-sysfs.c | 45 ++++++++----------------------------
 1 file changed, 10 insertions(+), 35 deletions(-)

diff --git a/fs/orangefs/orangefs-sysfs.c b/fs/orangefs/orangefs-sysfs.c
index de80b62553bb..c89f16052e92 100644
--- a/fs/orangefs/orangefs-sysfs.c
+++ b/fs/orangefs/orangefs-sysfs.c
@@ -217,38 +217,23 @@ static ssize_t sysfs_int_show(struct kobject *kobj,

 	if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
 		if (!strcmp(attr->attr.name, "op_timeout_secs")) {
-			rc = scnprintf(buf,
-				       PAGE_SIZE,
-				       "%d\n",
-				       op_timeout_secs);
+			rc = sysfs_emit(buf, "%d\n", op_timeout_secs);
 			goto out;
 		} else if (!strcmp(attr->attr.name,
 				   "slot_timeout_secs")) {
-			rc = scnprintf(buf,
-				       PAGE_SIZE,
-				       "%d\n",
-				       slot_timeout_secs);
+			rc = sysfs_emit(buf, "%d\n", slot_timeout_secs);
 			goto out;
 		} else if (!strcmp(attr->attr.name,
 				   "cache_timeout_msecs")) {
-			rc = scnprintf(buf,
-				       PAGE_SIZE,
-				       "%d\n",
-				       orangefs_cache_timeout_msecs);
+			rc = sysfs_emit(buf, "%d\n", orangefs_cache_timeout_msecs);
 			goto out;
 		} else if (!strcmp(attr->attr.name,
 				   "dcache_timeout_msecs")) {
-			rc = scnprintf(buf,
-				       PAGE_SIZE,
-				       "%d\n",
-				       orangefs_dcache_timeout_msecs);
+			rc = sysfs_emit(buf, "%d\n", orangefs_dcache_timeout_msecs);
 			goto out;
 		} else if (!strcmp(attr->attr.name,
 				   "getattr_timeout_msecs")) {
-			rc = scnprintf(buf,
-				       PAGE_SIZE,
-				       "%d\n",
-				       orangefs_getattr_timeout_msecs);
+			rc = sysfs_emit(buf, "%d\n", orangefs_getattr_timeout_msecs);
 			goto out;
 		} else {
 			goto out;
@@ -256,16 +241,10 @@ static ssize_t sysfs_int_show(struct kobject *kobj,

 	} else if (!strcmp(kobj->name, STATS_KOBJ_ID)) {
 		if (!strcmp(attr->attr.name, "reads")) {
-			rc = scnprintf(buf,
-				       PAGE_SIZE,
-				       "%lu\n",
-				       orangefs_stats.reads);
+			rc = sysfs_emit(buf, "%lu\n", orangefs_stats.reads);
 			goto out;
 		} else if (!strcmp(attr->attr.name, "writes")) {
-			rc = scnprintf(buf,
-				       PAGE_SIZE,
-				       "%lu\n",
-				       orangefs_stats.writes);
+			rc = sysfs_emit(buf, "%lu\n", orangefs_stats.writes);
 			goto out;
 		} else {
 			goto out;
@@ -497,21 +476,17 @@ static ssize_t sysfs_service_op_show(struct kobject *kobj,
 		if (strcmp(kobj->name, PC_KOBJ_ID)) {
 			if (new_op->upcall.req.param.op ==
 			    ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE) {
-				rc = scnprintf(buf, PAGE_SIZE, "%d %d\n",
+				rc = sysfs_emit(buf, "%d %d\n",
 				    (int)new_op->downcall.resp.param.u.
 				    value32[0],
 				    (int)new_op->downcall.resp.param.u.
 				    value32[1]);
 			} else {
-				rc = scnprintf(buf, PAGE_SIZE, "%d\n",
+				rc = sysfs_emit(buf, "%d\n",
 				    (int)new_op->downcall.resp.param.u.value64);
 			}
 		} else {
-			rc = scnprintf(
-				buf,
-				PAGE_SIZE,
-				"%s",
-				new_op->downcall.resp.perf_count.buffer);
+			rc = sysfs_emit(buf, "%s", new_op->downcall.resp.perf_count.buffer);
 		}
 	}

-- 
2.25.1

                 reply	other threads:[~2022-12-05 11:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202212051903396321367@zte.com.cn \
    --to=ye.xingchen@zte.com.cn \
    --cc=devel@lists.orangefs.org \
    --cc=hubcap@omnibond.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin@omnibond.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox