Skip to content

Commit f7cf224

Browse files
hcahcaaxboe
authored andcommitted
s390/dasd: fix string length handling
Building dasd_eckd.o with latest clang reveals this bug: CC drivers/s390/block/dasd_eckd.o drivers/s390/block/dasd_eckd.c:1082:3: warning: 'snprintf' will always be truncated; specified size is 1, but format string expands to at least 11 [-Wfortify-source] 1082 | snprintf(print_uid, sizeof(*print_uid), | ^ drivers/s390/block/dasd_eckd.c:1087:3: warning: 'snprintf' will always be truncated; specified size is 1, but format string expands to at least 10 [-Wfortify-source] 1087 | snprintf(print_uid, sizeof(*print_uid), | ^ Fix this by moving and using the existing UID_STRLEN for the arrays that are being written to. Also rename UID_STRLEN to DASD_UID_STRLEN to clarify its scope. Fixes: 2359696 ("s390/dasd: split up dasd_eckd_read_conf") Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com> Tested-by: Nick Desaulniers <ndesaulniers@google.com> # build Reported-by: Nathan Chancellor <nathan@kernel.org> Closes: ClangBuiltLinux#1923 Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> Link: https://lore.kernel.org/r/20230828153142.2843753-2-hca@linux.ibm.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 1a721de commit f7cf224

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

drivers/s390/block/dasd_devmap.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,16 +1378,12 @@ static ssize_t dasd_vendor_show(struct device *dev,
13781378

13791379
static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
13801380

1381-
#define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
1382-
/* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\
1383-
/* vduit */ 32 + 1)
1384-
13851381
static ssize_t
13861382
dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
13871383
{
1384+
char uid_string[DASD_UID_STRLEN];
13881385
struct dasd_device *device;
13891386
struct dasd_uid uid;
1390-
char uid_string[UID_STRLEN];
13911387
char ua_string[3];
13921388

13931389
device = dasd_device_from_cdev(to_ccwdev(dev));

drivers/s390/block/dasd_eckd.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,12 +1079,12 @@ static void dasd_eckd_get_uid_string(struct dasd_conf *conf,
10791079

10801080
create_uid(conf, &uid);
10811081
if (strlen(uid.vduit) > 0)
1082-
snprintf(print_uid, sizeof(*print_uid),
1082+
snprintf(print_uid, DASD_UID_STRLEN,
10831083
"%s.%s.%04x.%02x.%s",
10841084
uid.vendor, uid.serial, uid.ssid,
10851085
uid.real_unit_addr, uid.vduit);
10861086
else
1087-
snprintf(print_uid, sizeof(*print_uid),
1087+
snprintf(print_uid, DASD_UID_STRLEN,
10881088
"%s.%s.%04x.%02x",
10891089
uid.vendor, uid.serial, uid.ssid,
10901090
uid.real_unit_addr);
@@ -1093,8 +1093,8 @@ static void dasd_eckd_get_uid_string(struct dasd_conf *conf,
10931093
static int dasd_eckd_check_cabling(struct dasd_device *device,
10941094
void *conf_data, __u8 lpm)
10951095
{
1096+
char print_path_uid[DASD_UID_STRLEN], print_device_uid[DASD_UID_STRLEN];
10961097
struct dasd_eckd_private *private = device->private;
1097-
char print_path_uid[60], print_device_uid[60];
10981098
struct dasd_conf path_conf;
10991099

11001100
path_conf.data = conf_data;
@@ -1293,9 +1293,9 @@ static void dasd_eckd_path_available_action(struct dasd_device *device,
12931293
__u8 path_rcd_buf[DASD_ECKD_RCD_DATA_SIZE];
12941294
__u8 lpm, opm, npm, ppm, epm, hpfpm, cablepm;
12951295
struct dasd_conf_data *conf_data;
1296+
char print_uid[DASD_UID_STRLEN];
12961297
struct dasd_conf path_conf;
12971298
unsigned long flags;
1298-
char print_uid[60];
12991299
int rc, pos;
13001300

13011301
opm = 0;
@@ -5855,8 +5855,8 @@ static void dasd_eckd_dump_sense(struct dasd_device *device,
58555855
static int dasd_eckd_reload_device(struct dasd_device *device)
58565856
{
58575857
struct dasd_eckd_private *private = device->private;
5858+
char print_uid[DASD_UID_STRLEN];
58585859
int rc, old_base;
5859-
char print_uid[60];
58605860
struct dasd_uid uid;
58615861
unsigned long flags;
58625862

drivers/s390/block/dasd_int.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ struct dasd_uid {
259259
char vduit[33];
260260
};
261261

262+
#define DASD_UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 + \
263+
/* SSID */ 4 + 1 + /* unit addr */ 2 + 1 + \
264+
/* vduit */ 32 + 1)
265+
262266
/*
263267
* PPRC Status data
264268
*/

0 commit comments

Comments
 (0)