Skip to content

Commit

Permalink
block: move from strlcpy with unused retval to strscpy
Browse files Browse the repository at this point in the history
Follow the advice of the below link and prefer 'strscpy' in this
subsystem. Conversion is 1:1 because the return value is not used.
Generated by a coccinelle script.

Link: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/
Signed-off-by: Wolfram Sang <[email protected]>
Acked-by: Christoph Böhmwalder <[email protected]>
Acked-by: Geoff Levand <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Wolfram Sang authored and axboe committed Sep 22, 2022
1 parent 7f0c1af commit e55e1b4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion drivers/block/brd.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ static int brd_alloc(int i)
disk->minors = max_part;
disk->fops = &brd_fops;
disk->private_data = brd;
strlcpy(disk->disk_name, buf, DISK_NAME_LEN);
strscpy(disk->disk_name, buf, DISK_NAME_LEN);
set_capacity(disk, rd_size * 2);

/*
Expand Down
2 changes: 1 addition & 1 deletion drivers/block/drbd/drbd_nl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4752,7 +4752,7 @@ void notify_helper(enum drbd_notification_type type,
struct drbd_genlmsghdr *dh;
int err;

strlcpy(helper_info.helper_name, name, sizeof(helper_info.helper_name));
strscpy(helper_info.helper_name, name, sizeof(helper_info.helper_name));
helper_info.helper_name_len = min(strlen(name), sizeof(helper_info.helper_name));
helper_info.helper_status = status;

Expand Down
12 changes: 6 additions & 6 deletions drivers/block/mtip32xx/mtip32xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1397,15 +1397,15 @@ static void mtip_dump_identify(struct mtip_port *port)
if (!port->identify_valid)
return;

strlcpy(cbuf, (char *)(port->identify+10), 21);
strscpy(cbuf, (char *)(port->identify + 10), 21);
dev_info(&port->dd->pdev->dev,
"Serial No.: %s\n", cbuf);

strlcpy(cbuf, (char *)(port->identify+23), 9);
strscpy(cbuf, (char *)(port->identify + 23), 9);
dev_info(&port->dd->pdev->dev,
"Firmware Ver.: %s\n", cbuf);

strlcpy(cbuf, (char *)(port->identify+27), 41);
strscpy(cbuf, (char *)(port->identify + 27), 41);
dev_info(&port->dd->pdev->dev, "Model: %s\n", cbuf);

dev_info(&port->dd->pdev->dev, "Security: %04x %s\n",
Expand All @@ -1421,13 +1421,13 @@ static void mtip_dump_identify(struct mtip_port *port)
pci_read_config_word(port->dd->pdev, PCI_REVISION_ID, &revid);
switch (revid & 0xFF) {
case 0x1:
strlcpy(cbuf, "A0", 3);
strscpy(cbuf, "A0", 3);
break;
case 0x3:
strlcpy(cbuf, "A2", 3);
strscpy(cbuf, "A2", 3);
break;
default:
strlcpy(cbuf, "?", 2);
strscpy(cbuf, "?", 2);
break;
}
dev_info(&port->dd->pdev->dev,
Expand Down
2 changes: 1 addition & 1 deletion drivers/block/ps3vram.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ static int ps3vram_probe(struct ps3_system_bus_device *dev)
gendisk->flags |= GENHD_FL_NO_PART;
gendisk->fops = &ps3vram_fops;
gendisk->private_data = dev;
strlcpy(gendisk->disk_name, DEVICE_NAME, sizeof(gendisk->disk_name));
strscpy(gendisk->disk_name, DEVICE_NAME, sizeof(gendisk->disk_name));
set_capacity(gendisk, priv->size >> 9);
blk_queue_max_segments(gendisk->queue, BLK_MAX_SEGMENTS);
blk_queue_max_segment_size(gendisk->queue, BLK_MAX_SEGMENT_SIZE);
Expand Down
6 changes: 3 additions & 3 deletions drivers/block/zram/zram_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ static ssize_t backing_dev_store(struct device *dev,
goto out;
}

strlcpy(file_name, buf, PATH_MAX);
strscpy(file_name, buf, PATH_MAX);
/* ignore trailing newline */
sz = strlen(file_name);
if (sz > 0 && file_name[sz - 1] == '\n')
Expand Down Expand Up @@ -1031,7 +1031,7 @@ static ssize_t comp_algorithm_store(struct device *dev,
char compressor[ARRAY_SIZE(zram->compressor)];
size_t sz;

strlcpy(compressor, buf, sizeof(compressor));
strscpy(compressor, buf, sizeof(compressor));
/* ignore trailing newline */
sz = strlen(compressor);
if (sz > 0 && compressor[sz - 1] == '\n')
Expand Down Expand Up @@ -1952,7 +1952,7 @@ static int zram_add(void)
if (ret)
goto out_cleanup_disk;

strlcpy(zram->compressor, default_compressor, sizeof(zram->compressor));
strscpy(zram->compressor, default_compressor, sizeof(zram->compressor));

zram_debugfs_register(zram);
pr_info("Added device: %s\n", zram->disk->disk_name);
Expand Down

0 comments on commit e55e1b4

Please sign in to comment.