null_blk: Use strscpy() instead of strscpy_pad() in null_add_dev()
PATCH 1/1 null_blk: Use strscpy() instead of strscpy_pad() in null_add_dev()
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.
--- drivers/block/null_blk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/null_blk/main.c +1 -1
@@ -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);
Signature · 1 line
2.49.0
Quoted 5 lines · Thorsten Blum
blk_mq_alloc_disk()already zero-initializes the destination buffer, makingstrscpy()sufficient for safely copying the disk's name. The additional NUL-padding performed bystrscpy_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.
Zhu Yanjun
Quoted 26 lines
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 ofstrscpy().No functional changes intended.
Signed-off-by Thorsten Blum <[email protected]>--- drivers/block/null_blk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/block/null_blk/main.c +1
-1@@ -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);
Signature · 2 lines
Best Regards, Yanjun.Zhu
Quoted 8 lines · Thorsten Blum
blk_mq_alloc_disk()already zero-initializes the destination buffer, makingstrscpy()sufficient for safely copying the disk's name. The additional NUL-padding performed bystrscpy_pad()is unnecessary.If the destination buffer has a fixed length,
strscpy()automatically determines its size usingsizeof()when the argument is omitted. This makes the explicit size argument unnecessary.
Quoted 6 lines
The source string is also NUL-terminated and meets the
__must_be_cstr()requirement ofstrscpy().No functional changes intended.
Signed-off-by Thorsten Blum <[email protected]>
Signature · 2 lines
Damien Le Moal Western Digital Research
Quoted 9 lines · Thorsten Blum
blk_mq_alloc_disk()already zero-initializes the destination buffer, makingstrscpy()sufficient for safely copying the disk's name. The additional NUL-padding performed bystrscpy_pad()is unnecessary.If the destination buffer has a fixed length,
strscpy()automatically determines its size usingsizeof()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,
Signature · 1 line
Jens Axboe