public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] null_blk: Use strscpy() instead of strscpy_pad() in null_add_dev()
@ 2025-04-10 15:47 Thorsten Blum
  2025-04-10 16:11 ` Zhu Yanjun
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Thorsten Blum @ 2025-04-10 15:47 UTC (permalink / raw)
  To: Jens Axboe, Damien Le Moal, Chaitanya Kulkarni,
	Johannes Thumshirn, Shin'ichiro Kawasaki, Zhu Yanjun,
	Zheng Qixing, Yu Kuai
  Cc: Thorsten Blum, linux-block, linux-kernel

blk_mq_alloc_disk() already zero-initializes the destination buffer,
making strscpy() sufficient for safely copying the disk's name. The
additional NUL-padding performed by strscpy_pad() is unnecessary.

If the destination buffer has a fixed length, strscpy() automatically
determines its size using sizeof() when the argument is omitted. This
makes the explicit size argument unnecessary.

The source string is also NUL-terminated and meets the __must_be_cstr()
requirement of strscpy().

No functional changes intended.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 drivers/block/null_blk/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 3bb9cee0a9b5..aa163ae9b2aa 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -2031,7 +2031,7 @@ static int null_add_dev(struct nullb_device *dev)
 	nullb->disk->minors = 1;
 	nullb->disk->fops = &null_ops;
 	nullb->disk->private_data = nullb;
-	strscpy_pad(nullb->disk->disk_name, nullb->disk_name, DISK_NAME_LEN);
+	strscpy(nullb->disk->disk_name, nullb->disk_name);
 
 	if (nullb->dev->zoned) {
 		rv = null_register_zoned_dev(nullb);
-- 
2.49.0


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

* Re: [PATCH] null_blk: Use strscpy() instead of strscpy_pad() in null_add_dev()
  2025-04-10 15:47 [PATCH] null_blk: Use strscpy() instead of strscpy_pad() in null_add_dev() Thorsten Blum
@ 2025-04-10 16:11 ` Zhu Yanjun
  2025-04-11  0:01 ` Damien Le Moal
  2025-04-11 13:10 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Zhu Yanjun @ 2025-04-10 16:11 UTC (permalink / raw)
  To: Thorsten Blum, Jens Axboe, Damien Le Moal, Chaitanya Kulkarni,
	Johannes Thumshirn, Shin'ichiro Kawasaki, Zheng Qixing,
	Yu Kuai
  Cc: linux-block, linux-kernel


On 10.04.25 17:47, Thorsten Blum wrote:
> blk_mq_alloc_disk() already zero-initializes the destination buffer,
> making strscpy() sufficient for safely copying the disk's name. The
> additional NUL-padding performed by strscpy_pad() is unnecessary.
>
> If the destination buffer has a fixed length, strscpy() automatically

Looks good to me. The destination buffer is indeed has a fixed length, 
it is DISK_NAME_LEN.

Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev>

Zhu Yanjun

> determines its size using sizeof() when the argument is omitted. This
> makes the explicit size argument unnecessary.
>
> The source string is also NUL-terminated and meets the __must_be_cstr()
> requirement of strscpy().
>
> No functional changes intended.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>   drivers/block/null_blk/main.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
> index 3bb9cee0a9b5..aa163ae9b2aa 100644
> --- a/drivers/block/null_blk/main.c
> +++ b/drivers/block/null_blk/main.c
> @@ -2031,7 +2031,7 @@ static int null_add_dev(struct nullb_device *dev)
>   	nullb->disk->minors = 1;
>   	nullb->disk->fops = &null_ops;
>   	nullb->disk->private_data = nullb;
> -	strscpy_pad(nullb->disk->disk_name, nullb->disk_name, DISK_NAME_LEN);
> +	strscpy(nullb->disk->disk_name, nullb->disk_name);
>   
>   	if (nullb->dev->zoned) {
>   		rv = null_register_zoned_dev(nullb);

-- 
Best Regards,
Yanjun.Zhu


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

* Re: [PATCH] null_blk: Use strscpy() instead of strscpy_pad() in null_add_dev()
  2025-04-10 15:47 [PATCH] null_blk: Use strscpy() instead of strscpy_pad() in null_add_dev() Thorsten Blum
  2025-04-10 16:11 ` Zhu Yanjun
@ 2025-04-11  0:01 ` Damien Le Moal
  2025-04-11 13:10 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Damien Le Moal @ 2025-04-11  0:01 UTC (permalink / raw)
  To: Thorsten Blum, Jens Axboe, Chaitanya Kulkarni, Johannes Thumshirn,
	Shin'ichiro Kawasaki, Zhu Yanjun, Zheng Qixing, Yu Kuai
  Cc: linux-block, linux-kernel

On 4/11/25 00:47, Thorsten Blum wrote:
> blk_mq_alloc_disk() already zero-initializes the destination buffer,
> making strscpy() sufficient for safely copying the disk's name. The
> additional NUL-padding performed by strscpy_pad() is unnecessary.
> 
> If the destination buffer has a fixed length, strscpy() automatically
> determines its size using sizeof() when the argument is omitted. This
> makes the explicit size argument unnecessary.
> 
> The source string is also NUL-terminated and meets the __must_be_cstr()
> requirement of strscpy().
> 
> No functional changes intended.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

-- 
Damien Le Moal
Western Digital Research

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

* Re: [PATCH] null_blk: Use strscpy() instead of strscpy_pad() in null_add_dev()
  2025-04-10 15:47 [PATCH] null_blk: Use strscpy() instead of strscpy_pad() in null_add_dev() Thorsten Blum
  2025-04-10 16:11 ` Zhu Yanjun
  2025-04-11  0:01 ` Damien Le Moal
@ 2025-04-11 13:10 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2025-04-11 13:10 UTC (permalink / raw)
  To: Damien Le Moal, Chaitanya Kulkarni, Johannes Thumshirn,
	Shin'ichiro Kawasaki, Zhu Yanjun, Zheng Qixing, Yu Kuai,
	Thorsten Blum
  Cc: linux-block, linux-kernel


On Thu, 10 Apr 2025 17:47:23 +0200, Thorsten Blum wrote:
> blk_mq_alloc_disk() already zero-initializes the destination buffer,
> making strscpy() sufficient for safely copying the disk's name. The
> additional NUL-padding performed by strscpy_pad() is unnecessary.
> 
> If the destination buffer has a fixed length, strscpy() automatically
> determines its size using sizeof() when the argument is omitted. This
> makes the explicit size argument unnecessary.
> 
> [...]

Applied, thanks!

[1/1] null_blk: Use strscpy() instead of strscpy_pad() in null_add_dev()
      commit: 3b607b75a345b1d808031bf1bb1038e4dac8d521

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2025-04-11 13:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-10 15:47 [PATCH] null_blk: Use strscpy() instead of strscpy_pad() in null_add_dev() Thorsten Blum
2025-04-10 16:11 ` Zhu Yanjun
2025-04-11  0:01 ` Damien Le Moal
2025-04-11 13:10 ` Jens Axboe

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