public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
* [PATCH] block: zram: replace scnprintf() with sysfs_emit() in *_show() functions
@ 2025-06-27  3:52 Rahul Kumar
  2025-06-27  4:32 ` Sergey Senozhatsky
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Rahul Kumar @ 2025-06-27  3:52 UTC (permalink / raw)
  To: minchan, senozhatsky, axboe
  Cc: linux-block, linux-kernel, linux-kernel-mentees, skhan, rk0006818

Replace scnprintf() with sysfs_emit() or sysfs_emit_at() in sysfs
*_show() functions in zram_drv.c to follow the kernel's guidelines
from Documentation/filesystems/sysfs.rst.

This improves consistency, safety, and makes the code easier to
maintain and update in the future.

Signed-off-by: Rahul Kumar <rk0006818@gmail.com>
---
 drivers/block/zram/zram_drv.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index fda7d8624889..a1f2f45d4b99 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -373,7 +373,7 @@ static ssize_t initstate_show(struct device *dev,
 	val = init_done(zram);
 	up_read(&zram->init_lock);
 
-	return scnprintf(buf, PAGE_SIZE, "%u\n", val);
+	return sysfs_emit(buf, "%u\n", val);
 }
 
 static ssize_t disksize_show(struct device *dev,
@@ -381,7 +381,7 @@ static ssize_t disksize_show(struct device *dev,
 {
 	struct zram *zram = dev_to_zram(dev);
 
-	return scnprintf(buf, PAGE_SIZE, "%llu\n", zram->disksize);
+	return sysfs_emit(buf, "%llu\n", zram->disksize);
 }
 
 static ssize_t mem_limit_store(struct device *dev,
@@ -532,7 +532,7 @@ static ssize_t writeback_limit_enable_show(struct device *dev,
 	spin_unlock(&zram->wb_limit_lock);
 	up_read(&zram->init_lock);
 
-	return scnprintf(buf, PAGE_SIZE, "%d\n", val);
+	return sysfs_emit(buf, "%d\n", val);
 }
 
 static ssize_t writeback_limit_store(struct device *dev,
@@ -567,7 +567,7 @@ static ssize_t writeback_limit_show(struct device *dev,
 	spin_unlock(&zram->wb_limit_lock);
 	up_read(&zram->init_lock);
 
-	return scnprintf(buf, PAGE_SIZE, "%llu\n", val);
+	return sysfs_emit(buf, "%llu\n", val);
 }
 
 static void reset_bdev(struct zram *zram)
@@ -1292,7 +1292,7 @@ static ssize_t recomp_algorithm_show(struct device *dev,
 		if (!zram->comp_algs[prio])
 			continue;
 
-		sz += scnprintf(buf + sz, PAGE_SIZE - sz - 2, "#%d: ", prio);
+		sz += sysfs_emit_at(buf, sz, "#%d: ", prio);
 		sz += __comp_algorithm_show(zram, prio, buf + sz);
 	}
 
@@ -1365,7 +1365,7 @@ static ssize_t io_stat_show(struct device *dev,
 	ssize_t ret;
 
 	down_read(&zram->init_lock);
-	ret = scnprintf(buf, PAGE_SIZE,
+	ret = sysfs_emit(buf,
 			"%8llu %8llu 0 %8llu\n",
 			(u64)atomic64_read(&zram->stats.failed_reads),
 			(u64)atomic64_read(&zram->stats.failed_writes),
@@ -1395,7 +1395,7 @@ static ssize_t mm_stat_show(struct device *dev,
 	orig_size = atomic64_read(&zram->stats.pages_stored);
 	max_used = atomic_long_read(&zram->stats.max_used_pages);
 
-	ret = scnprintf(buf, PAGE_SIZE,
+	ret = sysfs_emit(buf,
 			"%8llu %8llu %8llu %8lu %8ld %8llu %8lu %8llu %8llu\n",
 			orig_size << PAGE_SHIFT,
 			(u64)atomic64_read(&zram->stats.compr_data_size),
@@ -1420,8 +1420,8 @@ static ssize_t bd_stat_show(struct device *dev,
 	ssize_t ret;
 
 	down_read(&zram->init_lock);
-	ret = scnprintf(buf, PAGE_SIZE,
-		"%8llu %8llu %8llu\n",
+	ret = sysfs_emit(buf,
+			"%8llu %8llu %8llu\n",
 			FOUR_K((u64)atomic64_read(&zram->stats.bd_count)),
 			FOUR_K((u64)atomic64_read(&zram->stats.bd_reads)),
 			FOUR_K((u64)atomic64_read(&zram->stats.bd_writes)));
@@ -1439,7 +1439,7 @@ static ssize_t debug_stat_show(struct device *dev,
 	ssize_t ret;
 
 	down_read(&zram->init_lock);
-	ret = scnprintf(buf, PAGE_SIZE,
+	ret = sysfs_emit(buf,
 			"version: %d\n0 %8llu\n",
 			version,
 			(u64)atomic64_read(&zram->stats.miss_free));
@@ -2682,7 +2682,7 @@ static ssize_t hot_add_show(const struct class *class,
 
 	if (ret < 0)
 		return ret;
-	return scnprintf(buf, PAGE_SIZE, "%d\n", ret);
+	return sysfs_emit(buf, "%d\n", ret);
 }
 /* This attribute must be set to 0400, so CLASS_ATTR_RO() can not be used */
 static struct class_attribute class_attr_hot_add =
-- 
2.43.0


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

* Re: [PATCH] block: zram: replace scnprintf() with sysfs_emit() in *_show() functions
  2025-06-27  3:52 [PATCH] block: zram: replace scnprintf() with sysfs_emit() in *_show() functions Rahul Kumar
@ 2025-06-27  4:32 ` Sergey Senozhatsky
  2025-06-27  7:14 ` Sergey Senozhatsky
  2025-07-04  1:57 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Sergey Senozhatsky @ 2025-06-27  4:32 UTC (permalink / raw)
  To: Jens Axboe, Rahul Kumar
  Cc: minchan, senozhatsky, linux-block, linux-kernel,
	linux-kernel-mentees, skhan

On (25/06/27 09:22), Rahul Kumar wrote:
> Replace scnprintf() with sysfs_emit() or sysfs_emit_at() in sysfs
> *_show() functions in zram_drv.c to follow the kernel's guidelines
> from Documentation/filesystems/sysfs.rst.
> 
> This improves consistency, safety, and makes the code easier to
> maintain and update in the future.
> 
> Signed-off-by: Rahul Kumar <rk0006818@gmail.com>

Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>

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

* Re: [PATCH] block: zram: replace scnprintf() with sysfs_emit() in *_show() functions
  2025-06-27  3:52 [PATCH] block: zram: replace scnprintf() with sysfs_emit() in *_show() functions Rahul Kumar
  2025-06-27  4:32 ` Sergey Senozhatsky
@ 2025-06-27  7:14 ` Sergey Senozhatsky
  2025-07-04  1:57 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Sergey Senozhatsky @ 2025-06-27  7:14 UTC (permalink / raw)
  To: Jens Axboe, Rahul Kumar
  Cc: minchan, senozhatsky, axboe, linux-block, linux-kernel,
	linux-kernel-mentees, skhan

On (25/06/27 09:22), Rahul Kumar wrote:
[..]
>  static void reset_bdev(struct zram *zram)
> @@ -1292,7 +1292,7 @@ static ssize_t recomp_algorithm_show(struct device *dev,
>  		if (!zram->comp_algs[prio])
>  			continue;
>  
> -		sz += scnprintf(buf + sz, PAGE_SIZE - sz - 2, "#%d: ", prio);
> +		sz += sysfs_emit_at(buf, sz, "#%d: ", prio);
>  		sz += __comp_algorithm_show(zram, prio, buf + sz);

Actually, there is a tiny bug in zcomp.  It's unrelated to this
patch, but I'll send a fix as followup, to avoid any conflicts.

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

* Re: [PATCH] block: zram: replace scnprintf() with sysfs_emit() in *_show() functions
  2025-06-27  3:52 [PATCH] block: zram: replace scnprintf() with sysfs_emit() in *_show() functions Rahul Kumar
  2025-06-27  4:32 ` Sergey Senozhatsky
  2025-06-27  7:14 ` Sergey Senozhatsky
@ 2025-07-04  1:57 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2025-07-04  1:57 UTC (permalink / raw)
  To: minchan, senozhatsky, Rahul Kumar
  Cc: linux-block, linux-kernel, linux-kernel-mentees, skhan


On Fri, 27 Jun 2025 09:22:56 +0530, Rahul Kumar wrote:
> Replace scnprintf() with sysfs_emit() or sysfs_emit_at() in sysfs
> *_show() functions in zram_drv.c to follow the kernel's guidelines
> from Documentation/filesystems/sysfs.rst.
> 
> This improves consistency, safety, and makes the code easier to
> maintain and update in the future.
> 
> [...]

Applied, thanks!

[1/1] block: zram: replace scnprintf() with sysfs_emit() in *_show() functions
      commit: 264a3fdab2365395e43d3a0b40162a29e61ffa22
[1/1] zram: pass buffer offset to zcomp_available_show()
      commit: e74a1c6a8e8af2422fce125c29b14f1d3fab5b5c

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2025-07-04  1:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-27  3:52 [PATCH] block: zram: replace scnprintf() with sysfs_emit() in *_show() functions Rahul Kumar
2025-06-27  4:32 ` Sergey Senozhatsky
2025-06-27  7:14 ` Sergey Senozhatsky
2025-07-04  1:57 ` Jens Axboe

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