public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Jackie Liu <liu.yun@linux.dev>
To: axboe@kernel.dk, yukuai@fnnas.com
Cc: linux-block@vger.kernel.org
Subject: [PATCH 02/10] block: convert blk-mq hw sysfs show to sysfs_emit/sysfs_emit_at
Date: Wed,  1 Apr 2026 15:07:08 +0800	[thread overview]
Message-ID: <20260401070716.991-3-liu.yun@linux.dev> (raw)
In-Reply-To: <20260401070716.991-1-liu.yun@linux.dev>

From: Jackie Liu <liuyun01@kylinos.cn>

Use sysfs_emit() for nr_tags and nr_reserved_tags, and convert
cpus_show to use sysfs_emit_at() which also drops the manual
PAGE_SIZE tracking.

Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
 block/blk-mq-sysfs.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c
index 58ec293373c6..ed9546de7466 100644
--- a/block/blk-mq-sysfs.c
+++ b/block/blk-mq-sysfs.c
@@ -69,36 +69,37 @@ static ssize_t blk_mq_hw_sysfs_show(struct kobject *kobj,
 static ssize_t blk_mq_hw_sysfs_nr_tags_show(struct blk_mq_hw_ctx *hctx,
 					    char *page)
 {
-	return sprintf(page, "%u\n", hctx->tags->nr_tags);
+	return sysfs_emit(page, "%u\n", hctx->tags->nr_tags);
 }
 
 static ssize_t blk_mq_hw_sysfs_nr_reserved_tags_show(struct blk_mq_hw_ctx *hctx,
 						     char *page)
 {
-	return sprintf(page, "%u\n", hctx->tags->nr_reserved_tags);
+	return sysfs_emit(page, "%u\n", hctx->tags->nr_reserved_tags);
 }
 
 static ssize_t blk_mq_hw_sysfs_cpus_show(struct blk_mq_hw_ctx *hctx, char *page)
 {
-	const size_t size = PAGE_SIZE - 1;
 	unsigned int i, first = 1;
-	int ret = 0, pos = 0;
+	int ret, pos = 0;
 
 	for_each_cpu(i, hctx->cpumask) {
 		if (first)
-			ret = snprintf(pos + page, size - pos, "%u", i);
+			ret = sysfs_emit_at(page, pos, "%u", i);
 		else
-			ret = snprintf(pos + page, size - pos, ", %u", i);
+			ret = sysfs_emit_at(page, pos, ", %u", i);
 
-		if (ret >= size - pos)
+		if (ret <= 0)
 			break;
 
 		first = 0;
 		pos += ret;
 	}
 
-	ret = snprintf(pos + page, size + 1 - pos, "\n");
-	return pos + ret;
+	ret = sysfs_emit_at(page, pos, "\n");
+	if (ret > 0)
+		pos += ret;
+	return pos;
 }
 
 static struct blk_mq_hw_ctx_sysfs_entry blk_mq_hw_sysfs_nr_tags = {
-- 
2.51.1


  parent reply	other threads:[~2026-04-01  7:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-01  7:07 [PATCH 00/10] block: sysfs cleanup for deprecated API usage Jackie Liu
2026-04-01  7:07 ` [PATCH 01/10] block: convert to sysfs_emit() in blk_ia_range show() Jackie Liu
2026-04-01  7:07 ` Jackie Liu [this message]
2026-04-01  7:07 ` [PATCH 03/10] block: convert disk events sysfs show to sysfs_emit/sysfs_emit_at Jackie Liu
2026-04-01  7:07 ` [PATCH 04/10] block: convert partition sysfs show to sysfs_emit() Jackie Liu
2026-04-01  7:07 ` [PATCH 05/10] block: convert part_timeout_show() " Jackie Liu
2026-04-01  7:07 ` [PATCH 06/10] block: convert kyber latency show " Jackie Liu
2026-04-01  7:07 ` [PATCH 07/10] block: convert bfq_var_show() " Jackie Liu
2026-04-01  7:07 ` [PATCH 08/10] block: use kstrtol() instead of sscanf() in disk_events_poll_msecs_store() Jackie Liu
2026-04-01  7:07 ` [PATCH 09/10] block: replace simple_strtoul() with kstrtoint() in part_timeout_store() Jackie Liu
2026-04-01  7:07 ` [PATCH 10/10] block: replace sscanf() with kstrtoint() in part_fail_store() Jackie Liu

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=20260401070716.991-3-liu.yun@linux.dev \
    --to=liu.yun@linux.dev \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=yukuai@fnnas.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