Skip to content

Commit 4b9e043

Browse files
Qing Wanghcahca
authored andcommitted
s390: replace snprintf in show functions with sysfs_emit
show() must not use snprintf() when formatting the value to be returned to user space. Fix the coccicheck warnings: WARNING: use scnprintf or sprintf. Use sysfs_emit instead of scnprintf or sprintf makes more sense. Signed-off-by: Qing Wang <[email protected]> Acked-by: Vineeth Vijayan <[email protected]> Acked-by: Stefan Haberland <[email protected]> Link: https://lore.kernel.org/r/[email protected] [[email protected]: fix indentation] Signed-off-by: Heiko Carstens <[email protected]>
1 parent 9a39abb commit 4b9e043

File tree

3 files changed

+45
-45
lines changed

3 files changed

+45
-45
lines changed

drivers/s390/block/dasd_devmap.c

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ static ssize_t dasd_ff_show(struct device *dev, struct device_attribute *attr,
731731
ff_flag = (devmap->features & DASD_FEATURE_FAILFAST) != 0;
732732
else
733733
ff_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_FAILFAST) != 0;
734-
return snprintf(buf, PAGE_SIZE, ff_flag ? "1\n" : "0\n");
734+
return sysfs_emit(buf, ff_flag ? "1\n" : "0\n");
735735
}
736736

737737
static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr,
@@ -773,7 +773,7 @@ dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
773773
spin_unlock(&dasd_devmap_lock);
774774

775775
out:
776-
return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n");
776+
return sysfs_emit(buf, ro_flag ? "1\n" : "0\n");
777777
}
778778

779779
static ssize_t
@@ -834,7 +834,7 @@ dasd_erplog_show(struct device *dev, struct device_attribute *attr, char *buf)
834834
erplog = (devmap->features & DASD_FEATURE_ERPLOG) != 0;
835835
else
836836
erplog = (DASD_FEATURE_DEFAULT & DASD_FEATURE_ERPLOG) != 0;
837-
return snprintf(buf, PAGE_SIZE, erplog ? "1\n" : "0\n");
837+
return sysfs_emit(buf, erplog ? "1\n" : "0\n");
838838
}
839839

840840
static ssize_t
@@ -1033,13 +1033,13 @@ dasd_discipline_show(struct device *dev, struct device_attribute *attr,
10331033
dasd_put_device(device);
10341034
goto out;
10351035
} else {
1036-
len = snprintf(buf, PAGE_SIZE, "%s\n",
1037-
device->discipline->name);
1036+
len = sysfs_emit(buf, "%s\n",
1037+
device->discipline->name);
10381038
dasd_put_device(device);
10391039
return len;
10401040
}
10411041
out:
1042-
len = snprintf(buf, PAGE_SIZE, "none\n");
1042+
len = sysfs_emit(buf, "none\n");
10431043
return len;
10441044
}
10451045

@@ -1056,30 +1056,30 @@ dasd_device_status_show(struct device *dev, struct device_attribute *attr,
10561056
if (!IS_ERR(device)) {
10571057
switch (device->state) {
10581058
case DASD_STATE_NEW:
1059-
len = snprintf(buf, PAGE_SIZE, "new\n");
1059+
len = sysfs_emit(buf, "new\n");
10601060
break;
10611061
case DASD_STATE_KNOWN:
1062-
len = snprintf(buf, PAGE_SIZE, "detected\n");
1062+
len = sysfs_emit(buf, "detected\n");
10631063
break;
10641064
case DASD_STATE_BASIC:
1065-
len = snprintf(buf, PAGE_SIZE, "basic\n");
1065+
len = sysfs_emit(buf, "basic\n");
10661066
break;
10671067
case DASD_STATE_UNFMT:
1068-
len = snprintf(buf, PAGE_SIZE, "unformatted\n");
1068+
len = sysfs_emit(buf, "unformatted\n");
10691069
break;
10701070
case DASD_STATE_READY:
1071-
len = snprintf(buf, PAGE_SIZE, "ready\n");
1071+
len = sysfs_emit(buf, "ready\n");
10721072
break;
10731073
case DASD_STATE_ONLINE:
1074-
len = snprintf(buf, PAGE_SIZE, "online\n");
1074+
len = sysfs_emit(buf, "online\n");
10751075
break;
10761076
default:
1077-
len = snprintf(buf, PAGE_SIZE, "no stat\n");
1077+
len = sysfs_emit(buf, "no stat\n");
10781078
break;
10791079
}
10801080
dasd_put_device(device);
10811081
} else
1082-
len = snprintf(buf, PAGE_SIZE, "unknown\n");
1082+
len = sysfs_emit(buf, "unknown\n");
10831083
return len;
10841084
}
10851085

@@ -1120,15 +1120,15 @@ static ssize_t dasd_vendor_show(struct device *dev,
11201120
device = dasd_device_from_cdev(to_ccwdev(dev));
11211121
vendor = "";
11221122
if (IS_ERR(device))
1123-
return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
1123+
return sysfs_emit(buf, "%s\n", vendor);
11241124

11251125
if (device->discipline && device->discipline->get_uid &&
11261126
!device->discipline->get_uid(device, &uid))
11271127
vendor = uid.vendor;
11281128

11291129
dasd_put_device(device);
11301130

1131-
return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
1131+
return sysfs_emit(buf, "%s\n", vendor);
11321132
}
11331133

11341134
static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
@@ -1148,7 +1148,7 @@ dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
11481148
device = dasd_device_from_cdev(to_ccwdev(dev));
11491149
uid_string[0] = 0;
11501150
if (IS_ERR(device))
1151-
return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
1151+
return sysfs_emit(buf, "%s\n", uid_string);
11521152

11531153
if (device->discipline && device->discipline->get_uid &&
11541154
!device->discipline->get_uid(device, &uid)) {
@@ -1183,7 +1183,7 @@ dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
11831183
}
11841184
dasd_put_device(device);
11851185

1186-
return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
1186+
return sysfs_emit(buf, "%s\n", uid_string);
11871187
}
11881188
static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL);
11891189

@@ -1201,7 +1201,7 @@ dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf)
12011201
eer_flag = dasd_eer_enabled(devmap->device);
12021202
else
12031203
eer_flag = 0;
1204-
return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n");
1204+
return sysfs_emit(buf, eer_flag ? "1\n" : "0\n");
12051205
}
12061206

12071207
static ssize_t
@@ -1243,7 +1243,7 @@ dasd_expires_show(struct device *dev, struct device_attribute *attr, char *buf)
12431243
device = dasd_device_from_cdev(to_ccwdev(dev));
12441244
if (IS_ERR(device))
12451245
return -ENODEV;
1246-
len = snprintf(buf, PAGE_SIZE, "%lu\n", device->default_expires);
1246+
len = sysfs_emit(buf, "%lu\n", device->default_expires);
12471247
dasd_put_device(device);
12481248
return len;
12491249
}
@@ -1283,7 +1283,7 @@ dasd_retries_show(struct device *dev, struct device_attribute *attr, char *buf)
12831283
device = dasd_device_from_cdev(to_ccwdev(dev));
12841284
if (IS_ERR(device))
12851285
return -ENODEV;
1286-
len = snprintf(buf, PAGE_SIZE, "%lu\n", device->default_retries);
1286+
len = sysfs_emit(buf, "%lu\n", device->default_retries);
12871287
dasd_put_device(device);
12881288
return len;
12891289
}
@@ -1324,7 +1324,7 @@ dasd_timeout_show(struct device *dev, struct device_attribute *attr,
13241324
device = dasd_device_from_cdev(to_ccwdev(dev));
13251325
if (IS_ERR(device))
13261326
return -ENODEV;
1327-
len = snprintf(buf, PAGE_SIZE, "%lu\n", device->blk_timeout);
1327+
len = sysfs_emit(buf, "%lu\n", device->blk_timeout);
13281328
dasd_put_device(device);
13291329
return len;
13301330
}
@@ -1398,11 +1398,11 @@ static ssize_t dasd_hpf_show(struct device *dev, struct device_attribute *attr,
13981398
return -ENODEV;
13991399
if (!device->discipline || !device->discipline->hpf_enabled) {
14001400
dasd_put_device(device);
1401-
return snprintf(buf, PAGE_SIZE, "%d\n", dasd_nofcx);
1401+
return sysfs_emit(buf, "%d\n", dasd_nofcx);
14021402
}
14031403
hpf = device->discipline->hpf_enabled(device);
14041404
dasd_put_device(device);
1405-
return snprintf(buf, PAGE_SIZE, "%d\n", hpf);
1405+
return sysfs_emit(buf, "%d\n", hpf);
14061406
}
14071407

14081408
static DEVICE_ATTR(hpf, 0444, dasd_hpf_show, NULL);
@@ -1416,13 +1416,13 @@ static ssize_t dasd_reservation_policy_show(struct device *dev,
14161416

14171417
devmap = dasd_find_busid(dev_name(dev));
14181418
if (IS_ERR(devmap)) {
1419-
rc = snprintf(buf, PAGE_SIZE, "ignore\n");
1419+
rc = sysfs_emit(buf, "ignore\n");
14201420
} else {
14211421
spin_lock(&dasd_devmap_lock);
14221422
if (devmap->features & DASD_FEATURE_FAILONSLCK)
1423-
rc = snprintf(buf, PAGE_SIZE, "fail\n");
1423+
rc = sysfs_emit(buf, "fail\n");
14241424
else
1425-
rc = snprintf(buf, PAGE_SIZE, "ignore\n");
1425+
rc = sysfs_emit(buf, "ignore\n");
14261426
spin_unlock(&dasd_devmap_lock);
14271427
}
14281428
return rc;
@@ -1457,14 +1457,14 @@ static ssize_t dasd_reservation_state_show(struct device *dev,
14571457

14581458
device = dasd_device_from_cdev(to_ccwdev(dev));
14591459
if (IS_ERR(device))
1460-
return snprintf(buf, PAGE_SIZE, "none\n");
1460+
return sysfs_emit(buf, "none\n");
14611461

14621462
if (test_bit(DASD_FLAG_IS_RESERVED, &device->flags))
1463-
rc = snprintf(buf, PAGE_SIZE, "reserved\n");
1463+
rc = sysfs_emit(buf, "reserved\n");
14641464
else if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags))
1465-
rc = snprintf(buf, PAGE_SIZE, "lost\n");
1465+
rc = sysfs_emit(buf, "lost\n");
14661466
else
1467-
rc = snprintf(buf, PAGE_SIZE, "none\n");
1467+
rc = sysfs_emit(buf, "none\n");
14681468
dasd_put_device(device);
14691469
return rc;
14701470
}
@@ -1531,7 +1531,7 @@ dasd_path_threshold_show(struct device *dev,
15311531
device = dasd_device_from_cdev(to_ccwdev(dev));
15321532
if (IS_ERR(device))
15331533
return -ENODEV;
1534-
len = snprintf(buf, PAGE_SIZE, "%lu\n", device->path_thrhld);
1534+
len = sysfs_emit(buf, "%lu\n", device->path_thrhld);
15351535
dasd_put_device(device);
15361536
return len;
15371537
}
@@ -1578,7 +1578,7 @@ dasd_path_autodisable_show(struct device *dev,
15781578
else
15791579
flag = (DASD_FEATURE_DEFAULT &
15801580
DASD_FEATURE_PATH_AUTODISABLE) != 0;
1581-
return snprintf(buf, PAGE_SIZE, flag ? "1\n" : "0\n");
1581+
return sysfs_emit(buf, flag ? "1\n" : "0\n");
15821582
}
15831583

15841584
static ssize_t
@@ -1616,7 +1616,7 @@ dasd_path_interval_show(struct device *dev,
16161616
device = dasd_device_from_cdev(to_ccwdev(dev));
16171617
if (IS_ERR(device))
16181618
return -ENODEV;
1619-
len = snprintf(buf, PAGE_SIZE, "%lu\n", device->path_interval);
1619+
len = sysfs_emit(buf, "%lu\n", device->path_interval);
16201620
dasd_put_device(device);
16211621
return len;
16221622
}
@@ -1662,9 +1662,9 @@ dasd_device_fcs_show(struct device *dev, struct device_attribute *attr,
16621662
return -ENODEV;
16631663
fc_sec = dasd_path_get_fcs_device(device);
16641664
if (fc_sec == -EINVAL)
1665-
rc = snprintf(buf, PAGE_SIZE, "Inconsistent\n");
1665+
rc = sysfs_emit(buf, "Inconsistent\n");
16661666
else
1667-
rc = snprintf(buf, PAGE_SIZE, "%s\n", dasd_path_get_fcs_str(fc_sec));
1667+
rc = sysfs_emit(buf, "%s\n", dasd_path_get_fcs_str(fc_sec));
16681668
dasd_put_device(device);
16691669

16701670
return rc;
@@ -1677,7 +1677,7 @@ dasd_path_fcs_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
16771677
struct dasd_path *path = to_dasd_path(kobj);
16781678
unsigned int fc_sec = path->fc_security;
16791679

1680-
return snprintf(buf, PAGE_SIZE, "%s\n", dasd_path_get_fcs_str(fc_sec));
1680+
return sysfs_emit(buf, "%s\n", dasd_path_get_fcs_str(fc_sec));
16811681
}
16821682

16831683
static struct kobj_attribute path_fcs_attribute =
@@ -1698,7 +1698,7 @@ static ssize_t dasd_##_name##_show(struct device *dev, \
16981698
val = _func(device); \
16991699
dasd_put_device(device); \
17001700
\
1701-
return snprintf(buf, PAGE_SIZE, "%d\n", val); \
1701+
return sysfs_emit(buf, "%d\n", val); \
17021702
} \
17031703
static DEVICE_ATTR(_name, 0444, dasd_##_name##_show, NULL); \
17041704

drivers/s390/char/raw3270.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,24 +1047,24 @@ raw3270_probe (struct ccw_device *cdev)
10471047
static ssize_t
10481048
raw3270_model_show(struct device *dev, struct device_attribute *attr, char *buf)
10491049
{
1050-
return snprintf(buf, PAGE_SIZE, "%i\n",
1051-
((struct raw3270 *) dev_get_drvdata(dev))->model);
1050+
return sysfs_emit(buf, "%i\n",
1051+
((struct raw3270 *)dev_get_drvdata(dev))->model);
10521052
}
10531053
static DEVICE_ATTR(model, 0444, raw3270_model_show, NULL);
10541054

10551055
static ssize_t
10561056
raw3270_rows_show(struct device *dev, struct device_attribute *attr, char *buf)
10571057
{
1058-
return snprintf(buf, PAGE_SIZE, "%i\n",
1059-
((struct raw3270 *) dev_get_drvdata(dev))->rows);
1058+
return sysfs_emit(buf, "%i\n",
1059+
((struct raw3270 *)dev_get_drvdata(dev))->rows);
10601060
}
10611061
static DEVICE_ATTR(rows, 0444, raw3270_rows_show, NULL);
10621062

10631063
static ssize_t
10641064
raw3270_columns_show(struct device *dev, struct device_attribute *attr, char *buf)
10651065
{
1066-
return snprintf(buf, PAGE_SIZE, "%i\n",
1067-
((struct raw3270 *) dev_get_drvdata(dev))->cols);
1066+
return sysfs_emit(buf, "%i\n",
1067+
((struct raw3270 *)dev_get_drvdata(dev))->cols);
10681068
}
10691069
static DEVICE_ATTR(columns, 0444, raw3270_columns_show, NULL);
10701070

drivers/s390/cio/chp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static ssize_t chp_configure_show(struct device *dev,
285285
if (status < 0)
286286
return status;
287287

288-
return snprintf(buf, PAGE_SIZE, "%d\n", status);
288+
return sysfs_emit(buf, "%d\n", status);
289289
}
290290

291291
static int cfg_wait_idle(void);

0 commit comments

Comments
 (0)