Skip to content

Commit 1197c5b

Browse files
arndbmartinkpetersen
authored andcommitted
scsi: mylex: Fix sysfs buffer lengths
The myrb and myrs drivers use an odd way of implementing their sysfs files, calling snprintf() with a fixed length of 32 bytes to print into a page sized buffer. One of the strings is actually longer than 32 bytes, which clang can warn about: drivers/scsi/myrb.c:1906:10: error: 'snprintf' will always be truncated; specified size is 32, but format string expands to at least 34 [-Werror,-Wformat-truncation] drivers/scsi/myrs.c:1089:10: error: 'snprintf' will always be truncated; specified size is 32, but format string expands to at least 34 [-Werror,-Wformat-truncation] These could all be plain sprintf() without a length as the buffer is always long enough. On the other hand, sysfs files should not be overly long either, so just double the length to make sure the longest strings don't get truncated here. Fixes: 7726618 ("scsi: myrs: Add Mylex RAID controller (SCSI interface)") Fixes: 081ff39 ("scsi: myrb: Add Mylex RAID controller (block interface)") Signed-off-by: Arnd Bergmann <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Hannes Reinecke <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent c214ed2 commit 1197c5b

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

drivers/scsi/myrb.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,9 +1775,9 @@ static ssize_t raid_state_show(struct device *dev,
17751775

17761776
name = myrb_devstate_name(ldev_info->state);
17771777
if (name)
1778-
ret = snprintf(buf, 32, "%s\n", name);
1778+
ret = snprintf(buf, 64, "%s\n", name);
17791779
else
1780-
ret = snprintf(buf, 32, "Invalid (%02X)\n",
1780+
ret = snprintf(buf, 64, "Invalid (%02X)\n",
17811781
ldev_info->state);
17821782
} else {
17831783
struct myrb_pdev_state *pdev_info = sdev->hostdata;
@@ -1796,9 +1796,9 @@ static ssize_t raid_state_show(struct device *dev,
17961796
else
17971797
name = myrb_devstate_name(pdev_info->state);
17981798
if (name)
1799-
ret = snprintf(buf, 32, "%s\n", name);
1799+
ret = snprintf(buf, 64, "%s\n", name);
18001800
else
1801-
ret = snprintf(buf, 32, "Invalid (%02X)\n",
1801+
ret = snprintf(buf, 64, "Invalid (%02X)\n",
18021802
pdev_info->state);
18031803
}
18041804
return ret;
@@ -1886,11 +1886,11 @@ static ssize_t raid_level_show(struct device *dev,
18861886

18871887
name = myrb_raidlevel_name(ldev_info->raid_level);
18881888
if (!name)
1889-
return snprintf(buf, 32, "Invalid (%02X)\n",
1889+
return snprintf(buf, 64, "Invalid (%02X)\n",
18901890
ldev_info->state);
1891-
return snprintf(buf, 32, "%s\n", name);
1891+
return snprintf(buf, 64, "%s\n", name);
18921892
}
1893-
return snprintf(buf, 32, "Physical Drive\n");
1893+
return snprintf(buf, 64, "Physical Drive\n");
18941894
}
18951895
static DEVICE_ATTR_RO(raid_level);
18961896

@@ -1903,15 +1903,15 @@ static ssize_t rebuild_show(struct device *dev,
19031903
unsigned char status;
19041904

19051905
if (sdev->channel < myrb_logical_channel(sdev->host))
1906-
return snprintf(buf, 32, "physical device - not rebuilding\n");
1906+
return snprintf(buf, 64, "physical device - not rebuilding\n");
19071907

19081908
status = myrb_get_rbld_progress(cb, &rbld_buf);
19091909

19101910
if (rbld_buf.ldev_num != sdev->id ||
19111911
status != MYRB_STATUS_SUCCESS)
1912-
return snprintf(buf, 32, "not rebuilding\n");
1912+
return snprintf(buf, 64, "not rebuilding\n");
19131913

1914-
return snprintf(buf, 32, "rebuilding block %u of %u\n",
1914+
return snprintf(buf, 64, "rebuilding block %u of %u\n",
19151915
rbld_buf.ldev_size - rbld_buf.blocks_left,
19161916
rbld_buf.ldev_size);
19171917
}

drivers/scsi/myrs.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -947,9 +947,9 @@ static ssize_t raid_state_show(struct device *dev,
947947

948948
name = myrs_devstate_name(ldev_info->dev_state);
949949
if (name)
950-
ret = snprintf(buf, 32, "%s\n", name);
950+
ret = snprintf(buf, 64, "%s\n", name);
951951
else
952-
ret = snprintf(buf, 32, "Invalid (%02X)\n",
952+
ret = snprintf(buf, 64, "Invalid (%02X)\n",
953953
ldev_info->dev_state);
954954
} else {
955955
struct myrs_pdev_info *pdev_info;
@@ -958,9 +958,9 @@ static ssize_t raid_state_show(struct device *dev,
958958
pdev_info = sdev->hostdata;
959959
name = myrs_devstate_name(pdev_info->dev_state);
960960
if (name)
961-
ret = snprintf(buf, 32, "%s\n", name);
961+
ret = snprintf(buf, 64, "%s\n", name);
962962
else
963-
ret = snprintf(buf, 32, "Invalid (%02X)\n",
963+
ret = snprintf(buf, 64, "Invalid (%02X)\n",
964964
pdev_info->dev_state);
965965
}
966966
return ret;
@@ -1066,13 +1066,13 @@ static ssize_t raid_level_show(struct device *dev,
10661066
ldev_info = sdev->hostdata;
10671067
name = myrs_raid_level_name(ldev_info->raid_level);
10681068
if (!name)
1069-
return snprintf(buf, 32, "Invalid (%02X)\n",
1069+
return snprintf(buf, 64, "Invalid (%02X)\n",
10701070
ldev_info->dev_state);
10711071

10721072
} else
10731073
name = myrs_raid_level_name(MYRS_RAID_PHYSICAL);
10741074

1075-
return snprintf(buf, 32, "%s\n", name);
1075+
return snprintf(buf, 64, "%s\n", name);
10761076
}
10771077
static DEVICE_ATTR_RO(raid_level);
10781078

@@ -1086,7 +1086,7 @@ static ssize_t rebuild_show(struct device *dev,
10861086
unsigned char status;
10871087

10881088
if (sdev->channel < cs->ctlr_info->physchan_present)
1089-
return snprintf(buf, 32, "physical device - not rebuilding\n");
1089+
return snprintf(buf, 64, "physical device - not rebuilding\n");
10901090

10911091
ldev_info = sdev->hostdata;
10921092
ldev_num = ldev_info->ldev_num;
@@ -1098,11 +1098,11 @@ static ssize_t rebuild_show(struct device *dev,
10981098
return -EIO;
10991099
}
11001100
if (ldev_info->rbld_active) {
1101-
return snprintf(buf, 32, "rebuilding block %zu of %zu\n",
1101+
return snprintf(buf, 64, "rebuilding block %zu of %zu\n",
11021102
(size_t)ldev_info->rbld_lba,
11031103
(size_t)ldev_info->cfg_devsize);
11041104
} else
1105-
return snprintf(buf, 32, "not rebuilding\n");
1105+
return snprintf(buf, 64, "not rebuilding\n");
11061106
}
11071107

11081108
static ssize_t rebuild_store(struct device *dev,
@@ -1190,19 +1190,19 @@ static ssize_t consistency_check_show(struct device *dev,
11901190
unsigned short ldev_num;
11911191

11921192
if (sdev->channel < cs->ctlr_info->physchan_present)
1193-
return snprintf(buf, 32, "physical device - not checking\n");
1193+
return snprintf(buf, 64, "physical device - not checking\n");
11941194

11951195
ldev_info = sdev->hostdata;
11961196
if (!ldev_info)
11971197
return -ENXIO;
11981198
ldev_num = ldev_info->ldev_num;
11991199
myrs_get_ldev_info(cs, ldev_num, ldev_info);
12001200
if (ldev_info->cc_active)
1201-
return snprintf(buf, 32, "checking block %zu of %zu\n",
1201+
return snprintf(buf, 64, "checking block %zu of %zu\n",
12021202
(size_t)ldev_info->cc_lba,
12031203
(size_t)ldev_info->cfg_devsize);
12041204
else
1205-
return snprintf(buf, 32, "not checking\n");
1205+
return snprintf(buf, 64, "not checking\n");
12061206
}
12071207

12081208
static ssize_t consistency_check_store(struct device *dev,

0 commit comments

Comments
 (0)