public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/10] block: sysfs cleanup for deprecated API usage
@ 2026-04-01  7:07 Jackie Liu
  2026-04-01  7:07 ` [PATCH 01/10] block: convert to sysfs_emit() in blk_ia_range show() Jackie Liu
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Jackie Liu @ 2026-04-01  7:07 UTC (permalink / raw)
  To: axboe, yukuai; +Cc: linux-block

From: Jackie Liu <liuyun01@kylinos.cn>

A set of straightforward cleanups across the block layer sysfs
interfaces:

Patches 1-7 convert remaining sprintf()/snprintf() calls in sysfs
show functions to sysfs_emit()/sysfs_emit_at().

Patches 8-10 replace deprecated sscanf()/simple_strtoul() with
kstrtol()/kstrtoint() in sysfs store functions.

Jackie Liu (10):
  block: convert to sysfs_emit() in blk_ia_range show()
  block: convert blk-mq hw sysfs show to sysfs_emit/sysfs_emit_at
  block: convert disk events sysfs show to sysfs_emit/sysfs_emit_at
  block: convert partition sysfs show to sysfs_emit()
  block: convert part_timeout_show() to sysfs_emit()
  block: convert kyber latency show to sysfs_emit()
  block: convert bfq_var_show() to sysfs_emit()
  block: use kstrtol() instead of sscanf() in
    disk_events_poll_msecs_store()
  block: replace simple_strtoul() with kstrtoint() in
    part_timeout_store()
  block: replace sscanf() with kstrtoint() in part_fail_store()

 block/bfq-iosched.c     |  2 +-
 block/blk-ia-ranges.c   |  4 ++--
 block/blk-mq-sysfs.c    | 19 ++++++++++---------
 block/blk-timeout.c     | 18 ++++++++----------
 block/disk-events.c     | 12 ++++++------
 block/genhd.c           | 16 +++++++++-------
 block/kyber-iosched.c   |  2 +-
 block/partitions/core.c | 10 +++++-----
 8 files changed, 42 insertions(+), 41 deletions(-)

-- 
2.51.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 01/10] block: convert to sysfs_emit() in blk_ia_range show()
  2026-04-01  7:07 [PATCH 00/10] block: sysfs cleanup for deprecated API usage Jackie Liu
@ 2026-04-01  7:07 ` Jackie Liu
  2026-04-01  7:07 ` [PATCH 02/10] block: convert blk-mq hw sysfs show to sysfs_emit/sysfs_emit_at Jackie Liu
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Jackie Liu @ 2026-04-01  7:07 UTC (permalink / raw)
  To: axboe, yukuai; +Cc: linux-block

From: Jackie Liu <liuyun01@kylinos.cn>

Use sysfs_emit() instead of sprintf() per the sysfs output guidelines.

Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
 block/blk-ia-ranges.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/blk-ia-ranges.c b/block/blk-ia-ranges.c
index d479f5481b66..94f4795da7c9 100644
--- a/block/blk-ia-ranges.c
+++ b/block/blk-ia-ranges.c
@@ -15,14 +15,14 @@ static ssize_t
 blk_ia_range_sector_show(struct blk_independent_access_range *iar,
 			 char *buf)
 {
-	return sprintf(buf, "%llu\n", iar->sector);
+	return sysfs_emit(buf, "%llu\n", iar->sector);
 }
 
 static ssize_t
 blk_ia_range_nr_sectors_show(struct blk_independent_access_range *iar,
 			     char *buf)
 {
-	return sprintf(buf, "%llu\n", iar->nr_sectors);
+	return sysfs_emit(buf, "%llu\n", iar->nr_sectors);
 }
 
 struct blk_ia_range_sysfs_entry {
-- 
2.51.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 02/10] block: convert blk-mq hw sysfs show to sysfs_emit/sysfs_emit_at
  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
  2026-04-01  7:07 ` [PATCH 03/10] block: convert disk events " Jackie Liu
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Jackie Liu @ 2026-04-01  7:07 UTC (permalink / raw)
  To: axboe, yukuai; +Cc: linux-block

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


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 03/10] block: convert disk events sysfs show to sysfs_emit/sysfs_emit_at
  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 ` [PATCH 02/10] block: convert blk-mq hw sysfs show to sysfs_emit/sysfs_emit_at Jackie Liu
@ 2026-04-01  7:07 ` Jackie Liu
  2026-04-01  7:07 ` [PATCH 04/10] block: convert partition sysfs show to sysfs_emit() Jackie Liu
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Jackie Liu @ 2026-04-01  7:07 UTC (permalink / raw)
  To: axboe, yukuai; +Cc: linux-block

From: Jackie Liu <liuyun01@kylinos.cn>

Use sysfs_emit()/sysfs_emit_at() instead of sprintf() for the disk
events sysfs attributes.

Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
 block/disk-events.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/block/disk-events.c b/block/disk-events.c
index 9f9f9f8a2d6b..b1680d6a1027 100644
--- a/block/disk-events.c
+++ b/block/disk-events.c
@@ -329,12 +329,12 @@ static ssize_t __disk_events_show(unsigned int events, char *buf)
 
 	for (i = 0; i < ARRAY_SIZE(disk_events_strs); i++)
 		if (events & (1 << i)) {
-			pos += sprintf(buf + pos, "%s%s",
-				       delim, disk_events_strs[i]);
+			pos += sysfs_emit_at(buf, pos, "%s%s",
+					     delim, disk_events_strs[i]);
 			delim = " ";
 		}
 	if (pos)
-		pos += sprintf(buf + pos, "\n");
+		pos += sysfs_emit_at(buf, pos, "\n");
 	return pos;
 }
 
@@ -361,8 +361,8 @@ static ssize_t disk_events_poll_msecs_show(struct device *dev,
 	struct gendisk *disk = dev_to_disk(dev);
 
 	if (!disk->ev)
-		return sprintf(buf, "-1\n");
-	return sprintf(buf, "%ld\n", disk->ev->poll_msecs);
+		return sysfs_emit(buf, "-1\n");
+	return sysfs_emit(buf, "%ld\n", disk->ev->poll_msecs);
 }
 
 static ssize_t disk_events_poll_msecs_store(struct device *dev,
-- 
2.51.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 04/10] block: convert partition sysfs show to sysfs_emit()
  2026-04-01  7:07 [PATCH 00/10] block: sysfs cleanup for deprecated API usage Jackie Liu
                   ` (2 preceding siblings ...)
  2026-04-01  7:07 ` [PATCH 03/10] block: convert disk events " Jackie Liu
@ 2026-04-01  7:07 ` Jackie Liu
  2026-04-01  7:07 ` [PATCH 05/10] block: convert part_timeout_show() " Jackie Liu
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Jackie Liu @ 2026-04-01  7:07 UTC (permalink / raw)
  To: axboe, yukuai; +Cc: linux-block

From: Jackie Liu <liuyun01@kylinos.cn>

Use sysfs_emit() instead of sprintf() for partition attribute
show functions.

Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
 block/partitions/core.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/block/partitions/core.c b/block/partitions/core.c
index 740228750aaf..41b5c09d4551 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -177,31 +177,31 @@ static struct parsed_partitions *check_partition(struct gendisk *hd)
 static ssize_t part_partition_show(struct device *dev,
 				   struct device_attribute *attr, char *buf)
 {
-	return sprintf(buf, "%d\n", bdev_partno(dev_to_bdev(dev)));
+	return sysfs_emit(buf, "%d\n", bdev_partno(dev_to_bdev(dev)));
 }
 
 static ssize_t part_start_show(struct device *dev,
 			       struct device_attribute *attr, char *buf)
 {
-	return sprintf(buf, "%llu\n", dev_to_bdev(dev)->bd_start_sect);
+	return sysfs_emit(buf, "%llu\n", dev_to_bdev(dev)->bd_start_sect);
 }
 
 static ssize_t part_ro_show(struct device *dev,
 			    struct device_attribute *attr, char *buf)
 {
-	return sprintf(buf, "%d\n", bdev_read_only(dev_to_bdev(dev)));
+	return sysfs_emit(buf, "%d\n", bdev_read_only(dev_to_bdev(dev)));
 }
 
 static ssize_t part_alignment_offset_show(struct device *dev,
 					  struct device_attribute *attr, char *buf)
 {
-	return sprintf(buf, "%u\n", bdev_alignment_offset(dev_to_bdev(dev)));
+	return sysfs_emit(buf, "%u\n", bdev_alignment_offset(dev_to_bdev(dev)));
 }
 
 static ssize_t part_discard_alignment_show(struct device *dev,
 					   struct device_attribute *attr, char *buf)
 {
-	return sprintf(buf, "%u\n", bdev_discard_alignment(dev_to_bdev(dev)));
+	return sysfs_emit(buf, "%u\n", bdev_discard_alignment(dev_to_bdev(dev)));
 }
 
 static DEVICE_ATTR(partition, 0444, part_partition_show, NULL);
-- 
2.51.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 05/10] block: convert part_timeout_show() to sysfs_emit()
  2026-04-01  7:07 [PATCH 00/10] block: sysfs cleanup for deprecated API usage Jackie Liu
                   ` (3 preceding siblings ...)
  2026-04-01  7:07 ` [PATCH 04/10] block: convert partition sysfs show to sysfs_emit() Jackie Liu
@ 2026-04-01  7:07 ` Jackie Liu
  2026-04-01  7:07 ` [PATCH 06/10] block: convert kyber latency show " Jackie Liu
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Jackie Liu @ 2026-04-01  7:07 UTC (permalink / raw)
  To: axboe, yukuai; +Cc: linux-block

From: Jackie Liu <liuyun01@kylinos.cn>

Use sysfs_emit() instead of sprintf() for the fail_io timeout
sysfs show function.

Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
 block/blk-timeout.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/blk-timeout.c b/block/blk-timeout.c
index 1b8de0417fc1..eab6422fad4b 100644
--- a/block/blk-timeout.c
+++ b/block/blk-timeout.c
@@ -42,7 +42,7 @@ ssize_t part_timeout_show(struct device *dev, struct device_attribute *attr,
 	struct gendisk *disk = dev_to_disk(dev);
 	int set = test_bit(QUEUE_FLAG_FAIL_IO, &disk->queue->queue_flags);
 
-	return sprintf(buf, "%d\n", set != 0);
+	return sysfs_emit(buf, "%d\n", set != 0);
 }
 
 ssize_t part_timeout_store(struct device *dev, struct device_attribute *attr,
-- 
2.51.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 06/10] block: convert kyber latency show to sysfs_emit()
  2026-04-01  7:07 [PATCH 00/10] block: sysfs cleanup for deprecated API usage Jackie Liu
                   ` (4 preceding siblings ...)
  2026-04-01  7:07 ` [PATCH 05/10] block: convert part_timeout_show() " Jackie Liu
@ 2026-04-01  7:07 ` Jackie Liu
  2026-04-01  7:07 ` [PATCH 07/10] block: convert bfq_var_show() " Jackie Liu
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Jackie Liu @ 2026-04-01  7:07 UTC (permalink / raw)
  To: axboe, yukuai; +Cc: linux-block

From: Jackie Liu <liuyun01@kylinos.cn>

Use sysfs_emit() instead of sprintf() in the KYBER_LAT_SHOW_STORE
macro for the kyber I/O scheduler latency target show functions.

Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
 block/kyber-iosched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/kyber-iosched.c b/block/kyber-iosched.c
index b84163d1f851..4c8070563042 100644
--- a/block/kyber-iosched.c
+++ b/block/kyber-iosched.c
@@ -852,7 +852,7 @@ static ssize_t kyber_##name##_lat_show(struct elevator_queue *e,	\
 {									\
 	struct kyber_queue_data *kqd = e->elevator_data;		\
 									\
-	return sprintf(page, "%llu\n", kqd->latency_targets[domain]);	\
+	return sysfs_emit(page, "%llu\n", kqd->latency_targets[domain]); \
 }									\
 									\
 static ssize_t kyber_##name##_lat_store(struct elevator_queue *e,	\
-- 
2.51.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 07/10] block: convert bfq_var_show() to sysfs_emit()
  2026-04-01  7:07 [PATCH 00/10] block: sysfs cleanup for deprecated API usage Jackie Liu
                   ` (5 preceding siblings ...)
  2026-04-01  7:07 ` [PATCH 06/10] block: convert kyber latency show " Jackie Liu
@ 2026-04-01  7:07 ` Jackie Liu
  2026-04-01  7:07 ` [PATCH 08/10] block: use kstrtol() instead of sscanf() in disk_events_poll_msecs_store() Jackie Liu
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Jackie Liu @ 2026-04-01  7:07 UTC (permalink / raw)
  To: axboe, yukuai; +Cc: linux-block

From: Jackie Liu <liuyun01@kylinos.cn>

Use sysfs_emit() instead of sprintf() in bfq_var_show(), which is
the common helper used by all BFQ sysfs show functions.

Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
 block/bfq-iosched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 141c602d5e85..4123f42faf39 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -7379,7 +7379,7 @@ static int __init bfq_slab_setup(void)
 
 static ssize_t bfq_var_show(unsigned int var, char *page)
 {
-	return sprintf(page, "%u\n", var);
+	return sysfs_emit(page, "%u\n", var);
 }
 
 static int bfq_var_store(unsigned long *var, const char *page)
-- 
2.51.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 08/10] block: use kstrtol() instead of sscanf() in disk_events_poll_msecs_store()
  2026-04-01  7:07 [PATCH 00/10] block: sysfs cleanup for deprecated API usage Jackie Liu
                   ` (6 preceding siblings ...)
  2026-04-01  7:07 ` [PATCH 07/10] block: convert bfq_var_show() " Jackie Liu
@ 2026-04-01  7:07 ` 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
  9 siblings, 0 replies; 11+ messages in thread
From: Jackie Liu @ 2026-04-01  7:07 UTC (permalink / raw)
  To: axboe, yukuai; +Cc: linux-block

From: Jackie Liu <liuyun01@kylinos.cn>

kstrtol() is the preferred way to parse a single integer from sysfs
input. It also makes the !count check unnecessary since kstrtol()
returns -EINVAL on empty or malformed strings.

Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
 block/disk-events.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/disk-events.c b/block/disk-events.c
index b1680d6a1027..b6233b0d5575 100644
--- a/block/disk-events.c
+++ b/block/disk-events.c
@@ -372,7 +372,7 @@ static ssize_t disk_events_poll_msecs_store(struct device *dev,
 	struct gendisk *disk = dev_to_disk(dev);
 	long intv;
 
-	if (!count || !sscanf(buf, "%ld", &intv))
+	if (kstrtol(buf, 10, &intv))
 		return -EINVAL;
 
 	if (intv < 0 && intv != -1)
-- 
2.51.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 09/10] block: replace simple_strtoul() with kstrtoint() in part_timeout_store()
  2026-04-01  7:07 [PATCH 00/10] block: sysfs cleanup for deprecated API usage Jackie Liu
                   ` (7 preceding siblings ...)
  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 ` Jackie Liu
  2026-04-01  7:07 ` [PATCH 10/10] block: replace sscanf() with kstrtoint() in part_fail_store() Jackie Liu
  9 siblings, 0 replies; 11+ messages in thread
From: Jackie Liu @ 2026-04-01  7:07 UTC (permalink / raw)
  To: axboe, yukuai; +Cc: linux-block

From: Jackie Liu <liuyun01@kylinos.cn>

simple_strtoul() is deprecated. Switch to kstrtoint() which also
removes the need for the const-discarding cast and the if (count)
wrapper.

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

diff --git a/block/blk-timeout.c b/block/blk-timeout.c
index eab6422fad4b..ea3c5451d6cf 100644
--- a/block/blk-timeout.c
+++ b/block/blk-timeout.c
@@ -49,18 +49,16 @@ ssize_t part_timeout_store(struct device *dev, struct device_attribute *attr,
 			   const char *buf, size_t count)
 {
 	struct gendisk *disk = dev_to_disk(dev);
+	struct request_queue *q = disk->queue;
 	int val;
 
-	if (count) {
-		struct request_queue *q = disk->queue;
-		char *p = (char *) buf;
+	if (kstrtoint(buf, 10, &val))
+		return -EINVAL;
 
-		val = simple_strtoul(p, &p, 10);
-		if (val)
-			blk_queue_flag_set(QUEUE_FLAG_FAIL_IO, q);
-		else
-			blk_queue_flag_clear(QUEUE_FLAG_FAIL_IO, q);
-	}
+	if (val)
+		blk_queue_flag_set(QUEUE_FLAG_FAIL_IO, q);
+	else
+		blk_queue_flag_clear(QUEUE_FLAG_FAIL_IO, q);
 
 	return count;
 }
-- 
2.51.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 10/10] block: replace sscanf() with kstrtoint() in part_fail_store()
  2026-04-01  7:07 [PATCH 00/10] block: sysfs cleanup for deprecated API usage Jackie Liu
                   ` (8 preceding siblings ...)
  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 ` Jackie Liu
  9 siblings, 0 replies; 11+ messages in thread
From: Jackie Liu @ 2026-04-01  7:07 UTC (permalink / raw)
  To: axboe, yukuai; +Cc: linux-block

From: Jackie Liu <liuyun01@kylinos.cn>

sscanf() is overly lenient for parsing a single integer from sysfs.
Use kstrtoint() which also properly rejects malformed input and
makes the count > 0 guard unnecessary.

Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
 block/genhd.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/block/genhd.c b/block/genhd.c
index 7d6854fd28e9..369bd8c13bbf 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1186,14 +1186,16 @@ ssize_t part_fail_store(struct device *dev,
 			struct device_attribute *attr,
 			const char *buf, size_t count)
 {
-	int i;
+	int val;
+
+	if (kstrtoint(buf, 10, &val))
+		return -EINVAL;
+
+	if (val)
+		bdev_set_flag(dev_to_bdev(dev), BD_MAKE_IT_FAIL);
+	else
+		bdev_clear_flag(dev_to_bdev(dev), BD_MAKE_IT_FAIL);
 
-	if (count > 0 && sscanf(buf, "%d", &i) > 0) {
-		if (i)
-			bdev_set_flag(dev_to_bdev(dev), BD_MAKE_IT_FAIL);
-		else
-			bdev_clear_flag(dev_to_bdev(dev), BD_MAKE_IT_FAIL);
-	}
 	return count;
 }
 
-- 
2.51.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-04-01  7:08 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 02/10] block: convert blk-mq hw sysfs show to sysfs_emit/sysfs_emit_at Jackie Liu
2026-04-01  7:07 ` [PATCH 03/10] block: convert disk events " 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox