Commit 74c05a38 authored by Thorsten Winkler's avatar Thorsten Winkler Committed by Jakub Kicinski

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: default avatarJules Irenge <jbi.octave@gmail.com>
Reviewed-by: default avatarAlexandra Winter <wintera@linux.ibm.com>
Signed-off-by: default avatarThorsten Winkler <twinkler@linux.ibm.com>
Signed-off-by: default avatarAlexandra Winter <wintera@linux.ibm.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent dde8769b
...@@ -2801,9 +2801,11 @@ static void qeth_print_status_message(struct qeth_card *card) ...@@ -2801,9 +2801,11 @@ static void qeth_print_status_message(struct qeth_card *card)
* of the level OSA sets the first character to zero * of the level OSA sets the first character to zero
* */ * */
if (!card->info.mcl_level[0]) { if (!card->info.mcl_level[0]) {
sprintf(card->info.mcl_level, "%02x%02x", scnprintf(card->info.mcl_level,
card->info.mcl_level[2], sizeof(card->info.mcl_level),
card->info.mcl_level[3]); "%02x%02x",
card->info.mcl_level[2],
card->info.mcl_level[3]);
break; break;
} }
fallthrough; fallthrough;
...@@ -6090,7 +6092,7 @@ void qeth_dbf_longtext(debug_info_t *id, int level, char *fmt, ...) ...@@ -6090,7 +6092,7 @@ void qeth_dbf_longtext(debug_info_t *id, int level, char *fmt, ...)
if (!debug_level_enabled(id, level)) if (!debug_level_enabled(id, level))
return; return;
va_start(args, fmt); va_start(args, fmt);
vsnprintf(dbf_txt_buf, sizeof(dbf_txt_buf), fmt, args); vscnprintf(dbf_txt_buf, sizeof(dbf_txt_buf), fmt, args);
va_end(args); va_end(args);
debug_text_event(id, level, dbf_txt_buf); debug_text_event(id, level, dbf_txt_buf);
} }
...@@ -6330,8 +6332,8 @@ static int qeth_core_probe_device(struct ccwgroup_device *gdev) ...@@ -6330,8 +6332,8 @@ static int qeth_core_probe_device(struct ccwgroup_device *gdev)
goto err_dev; goto err_dev;
} }
snprintf(dbf_name, sizeof(dbf_name), "qeth_card_%s", scnprintf(dbf_name, sizeof(dbf_name), "qeth_card_%s",
dev_name(&gdev->dev)); dev_name(&gdev->dev));
card->debug = qeth_get_dbf_entry(dbf_name); card->debug = qeth_get_dbf_entry(dbf_name);
if (!card->debug) { if (!card->debug) {
rc = qeth_add_dbf_entry(card, dbf_name); rc = qeth_add_dbf_entry(card, dbf_name);
......
...@@ -172,7 +172,7 @@ static void qeth_get_strings(struct net_device *dev, u32 stringset, u8 *data) ...@@ -172,7 +172,7 @@ static void qeth_get_strings(struct net_device *dev, u32 stringset, u8 *data)
qeth_add_stat_strings(&data, prefix, card_stats, qeth_add_stat_strings(&data, prefix, card_stats,
CARD_STATS_LEN); CARD_STATS_LEN);
for (i = 0; i < card->qdio.no_out_queues; i++) { for (i = 0; i < card->qdio.no_out_queues; i++) {
snprintf(prefix, ETH_GSTRING_LEN, "tx%u ", i); scnprintf(prefix, ETH_GSTRING_LEN, "tx%u ", i);
qeth_add_stat_strings(&data, prefix, txq_stats, qeth_add_stat_strings(&data, prefix, txq_stats,
TXQ_STATS_LEN); TXQ_STATS_LEN);
} }
...@@ -192,8 +192,8 @@ static void qeth_get_drvinfo(struct net_device *dev, ...@@ -192,8 +192,8 @@ static void qeth_get_drvinfo(struct net_device *dev,
sizeof(info->driver)); sizeof(info->driver));
strscpy(info->fw_version, card->info.mcl_level, strscpy(info->fw_version, card->info.mcl_level,
sizeof(info->fw_version)); sizeof(info->fw_version));
snprintf(info->bus_info, sizeof(info->bus_info), "%s/%s/%s", scnprintf(info->bus_info, sizeof(info->bus_info), "%s/%s/%s",
CARD_RDEV_ID(card), CARD_WDEV_ID(card), CARD_DDEV_ID(card)); CARD_RDEV_ID(card), CARD_WDEV_ID(card), CARD_DDEV_ID(card));
} }
static void qeth_get_channels(struct net_device *dev, static void qeth_get_channels(struct net_device *dev,
......
...@@ -1255,37 +1255,38 @@ static void qeth_bridge_emit_host_event(struct qeth_card *card, ...@@ -1255,37 +1255,38 @@ static void qeth_bridge_emit_host_event(struct qeth_card *card,
switch (evtype) { switch (evtype) {
case anev_reg_unreg: case anev_reg_unreg:
snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s", scnprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
(code & IPA_ADDR_CHANGE_CODE_REMOVAL) (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
? "deregister" : "register"); ? "deregister" : "register");
env[i] = str[i]; i++; env[i] = str[i]; i++;
if (code & IPA_ADDR_CHANGE_CODE_VLANID) { if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
snprintf(str[i], sizeof(str[i]), "VLAN=%d", scnprintf(str[i], sizeof(str[i]), "VLAN=%d",
addr_lnid->lnid); addr_lnid->lnid);
env[i] = str[i]; i++; env[i] = str[i]; i++;
} }
if (code & IPA_ADDR_CHANGE_CODE_MACADDR) { if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
snprintf(str[i], sizeof(str[i]), "MAC=%pM", scnprintf(str[i], sizeof(str[i]), "MAC=%pM",
addr_lnid->mac); addr_lnid->mac);
env[i] = str[i]; i++; env[i] = str[i]; i++;
} }
snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x", scnprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
token->cssid, token->ssid, token->devnum); token->cssid, token->ssid, token->devnum);
env[i] = str[i]; i++; env[i] = str[i]; i++;
snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid); scnprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
env[i] = str[i]; i++; env[i] = str[i]; i++;
snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x", scnprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
token->chpid); token->chpid);
env[i] = str[i]; i++; env[i] = str[i]; i++;
snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid); scnprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x",
token->chid);
env[i] = str[i]; i++; env[i] = str[i]; i++;
break; break;
case anev_abort: case anev_abort:
snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort"); scnprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
env[i] = str[i]; i++; env[i] = str[i]; i++;
break; break;
case anev_reset: case anev_reset:
snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset"); scnprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
env[i] = str[i]; i++; env[i] = str[i]; i++;
break; break;
} }
...@@ -1314,17 +1315,17 @@ static void qeth_bridge_state_change_worker(struct work_struct *work) ...@@ -1314,17 +1315,17 @@ static void qeth_bridge_state_change_worker(struct work_struct *work)
NULL NULL
}; };
snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange"); scnprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
snprintf(env_role, sizeof(env_role), "ROLE=%s", scnprintf(env_role, sizeof(env_role), "ROLE=%s",
(data->role == QETH_SBP_ROLE_NONE) ? "none" : (data->role == QETH_SBP_ROLE_NONE) ? "none" :
(data->role == QETH_SBP_ROLE_PRIMARY) ? "primary" : (data->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
(data->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" : (data->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
"<INVALID>"); "<INVALID>");
snprintf(env_state, sizeof(env_state), "STATE=%s", scnprintf(env_state, sizeof(env_state), "STATE=%s",
(data->state == QETH_SBP_STATE_INACTIVE) ? "inactive" : (data->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
(data->state == QETH_SBP_STATE_STANDBY) ? "standby" : (data->state == QETH_SBP_STATE_STANDBY) ? "standby" :
(data->state == QETH_SBP_STATE_ACTIVE) ? "active" : (data->state == QETH_SBP_STATE_ACTIVE) ? "active" :
"<INVALID>"); "<INVALID>");
kobject_uevent_env(&data->card->gdev->dev.kobj, kobject_uevent_env(&data->card->gdev->dev.kobj,
KOBJ_CHANGE, env); KOBJ_CHANGE, env);
kfree(data); kfree(data);
......
...@@ -47,9 +47,9 @@ int qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const u8 *addr, ...@@ -47,9 +47,9 @@ int qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const u8 *addr,
char *buf) char *buf)
{ {
if (proto == QETH_PROT_IPV4) if (proto == QETH_PROT_IPV4)
return sprintf(buf, "%pI4", addr); return scnprintf(buf, INET_ADDRSTRLEN, "%pI4", addr);
else else
return sprintf(buf, "%pI6", addr); return scnprintf(buf, INET6_ADDRSTRLEN, "%pI6", addr);
} }
static struct qeth_ipaddr *qeth_l3_find_addr_by_ip(struct qeth_card *card, static struct qeth_ipaddr *qeth_l3_find_addr_by_ip(struct qeth_card *card,
......
...@@ -252,8 +252,8 @@ static ssize_t qeth_l3_dev_hsuid_store(struct device *dev, ...@@ -252,8 +252,8 @@ static ssize_t qeth_l3_dev_hsuid_store(struct device *dev,
goto out; goto out;
} }
snprintf(card->options.hsuid, sizeof(card->options.hsuid), scnprintf(card->options.hsuid, sizeof(card->options.hsuid),
"%-8s", tmp); "%-8s", tmp);
ASCEBC(card->options.hsuid, 8); ASCEBC(card->options.hsuid, 8);
memcpy(card->dev->perm_addr, card->options.hsuid, 9); memcpy(card->dev->perm_addr, card->options.hsuid, 9);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment