Skip to content

Commit 2f8d4e8

Browse files
author
Tobias Huschle
committed
s390/qeth: Convert sprintf/snprintf to scnprintf
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2160097 Upstream status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git Tested: by IBM Build-Info: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=52483305 Conflicts: None commit 74c05a3 Author: Thorsten Winkler <twinkler@linux.ibm.com> Date: Thu Feb 9 12:04:24 2023 +0100 s390/qeth: Convert sprintf/snprintf to scnprintf This LWN article explains the rationale for this change https: //lwn.net/Articles/69419/ Ie. snprintf() returns what *would* be the resulting length, while scnprintf() returns the actual length. Reported-by: Jules Irenge <jbi.octave@gmail.com> Reviewed-by: Alexandra Winter <wintera@linux.ibm.com> Signed-off-by: Thorsten Winkler <twinkler@linux.ibm.com> Signed-off-by: Alexandra Winter <wintera@linux.ibm.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Tobias Huschle <thuschle@redhat.com>
1 parent 2f233e7 commit 2f8d4e8

File tree

5 files changed

+42
-39
lines changed

5 files changed

+42
-39
lines changed

drivers/s390/net/qeth_core_main.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,9 +2801,11 @@ static void qeth_print_status_message(struct qeth_card *card)
28012801
* of the level OSA sets the first character to zero
28022802
* */
28032803
if (!card->info.mcl_level[0]) {
2804-
sprintf(card->info.mcl_level, "%02x%02x",
2805-
card->info.mcl_level[2],
2806-
card->info.mcl_level[3]);
2804+
scnprintf(card->info.mcl_level,
2805+
sizeof(card->info.mcl_level),
2806+
"%02x%02x",
2807+
card->info.mcl_level[2],
2808+
card->info.mcl_level[3]);
28072809
break;
28082810
}
28092811
fallthrough;
@@ -6090,7 +6092,7 @@ void qeth_dbf_longtext(debug_info_t *id, int level, char *fmt, ...)
60906092
if (!debug_level_enabled(id, level))
60916093
return;
60926094
va_start(args, fmt);
6093-
vsnprintf(dbf_txt_buf, sizeof(dbf_txt_buf), fmt, args);
6095+
vscnprintf(dbf_txt_buf, sizeof(dbf_txt_buf), fmt, args);
60946096
va_end(args);
60956097
debug_text_event(id, level, dbf_txt_buf);
60966098
}
@@ -6330,8 +6332,8 @@ static int qeth_core_probe_device(struct ccwgroup_device *gdev)
63306332
goto err_dev;
63316333
}
63326334

6333-
snprintf(dbf_name, sizeof(dbf_name), "qeth_card_%s",
6334-
dev_name(&gdev->dev));
6335+
scnprintf(dbf_name, sizeof(dbf_name), "qeth_card_%s",
6336+
dev_name(&gdev->dev));
63356337
card->debug = qeth_get_dbf_entry(dbf_name);
63366338
if (!card->debug) {
63376339
rc = qeth_add_dbf_entry(card, dbf_name);

drivers/s390/net/qeth_ethtool.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static void qeth_get_strings(struct net_device *dev, u32 stringset, u8 *data)
172172
qeth_add_stat_strings(&data, prefix, card_stats,
173173
CARD_STATS_LEN);
174174
for (i = 0; i < card->qdio.no_out_queues; i++) {
175-
snprintf(prefix, ETH_GSTRING_LEN, "tx%u ", i);
175+
scnprintf(prefix, ETH_GSTRING_LEN, "tx%u ", i);
176176
qeth_add_stat_strings(&data, prefix, txq_stats,
177177
TXQ_STATS_LEN);
178178
}
@@ -192,8 +192,8 @@ static void qeth_get_drvinfo(struct net_device *dev,
192192
sizeof(info->driver));
193193
strlcpy(info->fw_version, card->info.mcl_level,
194194
sizeof(info->fw_version));
195-
snprintf(info->bus_info, sizeof(info->bus_info), "%s/%s/%s",
196-
CARD_RDEV_ID(card), CARD_WDEV_ID(card), CARD_DDEV_ID(card));
195+
scnprintf(info->bus_info, sizeof(info->bus_info), "%s/%s/%s",
196+
CARD_RDEV_ID(card), CARD_WDEV_ID(card), CARD_DDEV_ID(card));
197197
}
198198

199199
static void qeth_get_channels(struct net_device *dev,

drivers/s390/net/qeth_l2_main.c

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,37 +1255,38 @@ static void qeth_bridge_emit_host_event(struct qeth_card *card,
12551255

12561256
switch (evtype) {
12571257
case anev_reg_unreg:
1258-
snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1259-
(code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1260-
? "deregister" : "register");
1258+
scnprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1259+
(code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1260+
? "deregister" : "register");
12611261
env[i] = str[i]; i++;
12621262
if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
1263-
snprintf(str[i], sizeof(str[i]), "VLAN=%d",
1264-
addr_lnid->lnid);
1263+
scnprintf(str[i], sizeof(str[i]), "VLAN=%d",
1264+
addr_lnid->lnid);
12651265
env[i] = str[i]; i++;
12661266
}
12671267
if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
1268-
snprintf(str[i], sizeof(str[i]), "MAC=%pM",
1269-
addr_lnid->mac);
1268+
scnprintf(str[i], sizeof(str[i]), "MAC=%pM",
1269+
addr_lnid->mac);
12701270
env[i] = str[i]; i++;
12711271
}
1272-
snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1273-
token->cssid, token->ssid, token->devnum);
1272+
scnprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1273+
token->cssid, token->ssid, token->devnum);
12741274
env[i] = str[i]; i++;
1275-
snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1275+
scnprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
12761276
env[i] = str[i]; i++;
1277-
snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1278-
token->chpid);
1277+
scnprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1278+
token->chpid);
12791279
env[i] = str[i]; i++;
1280-
snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1280+
scnprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x",
1281+
token->chid);
12811282
env[i] = str[i]; i++;
12821283
break;
12831284
case anev_abort:
1284-
snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1285+
scnprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
12851286
env[i] = str[i]; i++;
12861287
break;
12871288
case anev_reset:
1288-
snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1289+
scnprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
12891290
env[i] = str[i]; i++;
12901291
break;
12911292
}
@@ -1314,17 +1315,17 @@ static void qeth_bridge_state_change_worker(struct work_struct *work)
13141315
NULL
13151316
};
13161317

1317-
snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1318-
snprintf(env_role, sizeof(env_role), "ROLE=%s",
1319-
(data->role == QETH_SBP_ROLE_NONE) ? "none" :
1320-
(data->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1321-
(data->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1322-
"<INVALID>");
1323-
snprintf(env_state, sizeof(env_state), "STATE=%s",
1324-
(data->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1325-
(data->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1326-
(data->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1327-
"<INVALID>");
1318+
scnprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1319+
scnprintf(env_role, sizeof(env_role), "ROLE=%s",
1320+
(data->role == QETH_SBP_ROLE_NONE) ? "none" :
1321+
(data->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1322+
(data->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1323+
"<INVALID>");
1324+
scnprintf(env_state, sizeof(env_state), "STATE=%s",
1325+
(data->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1326+
(data->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1327+
(data->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1328+
"<INVALID>");
13281329
kobject_uevent_env(&data->card->gdev->dev.kobj,
13291330
KOBJ_CHANGE, env);
13301331
kfree(data);

drivers/s390/net/qeth_l3_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ int qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const u8 *addr,
4747
char *buf)
4848
{
4949
if (proto == QETH_PROT_IPV4)
50-
return sprintf(buf, "%pI4", addr);
50+
return scnprintf(buf, INET_ADDRSTRLEN, "%pI4", addr);
5151
else
52-
return sprintf(buf, "%pI6", addr);
52+
return scnprintf(buf, INET6_ADDRSTRLEN, "%pI6", addr);
5353
}
5454

5555
static struct qeth_ipaddr *qeth_l3_find_addr_by_ip(struct qeth_card *card,

drivers/s390/net/qeth_l3_sys.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ static ssize_t qeth_l3_dev_hsuid_store(struct device *dev,
252252
goto out;
253253
}
254254

255-
snprintf(card->options.hsuid, sizeof(card->options.hsuid),
256-
"%-8s", tmp);
255+
scnprintf(card->options.hsuid, sizeof(card->options.hsuid),
256+
"%-8s", tmp);
257257
ASCEBC(card->options.hsuid, 8);
258258
memcpy(card->dev->perm_addr, card->options.hsuid, 9);
259259

0 commit comments

Comments
 (0)