Commit bea54165 authored by Chen Zhou's avatar Chen Zhou Committed by David S. Miller

net: hns3: replace snprintf with scnprintf in hns3_update_strings

snprintf returns the number of bytes that would be written, which may be
greater than the the actual length to be written. Here use extra code to
handle this.

scnprintf returns the number of bytes that was actually written, just use
scnprintf to simplify the code.
Signed-off-by: default avatarChen Zhou <chenzhou10@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 49e211c0
...@@ -423,9 +423,8 @@ static void *hns3_update_strings(u8 *data, const struct hns3_stats *stats, ...@@ -423,9 +423,8 @@ static void *hns3_update_strings(u8 *data, const struct hns3_stats *stats,
data[ETH_GSTRING_LEN - 1] = '\0'; data[ETH_GSTRING_LEN - 1] = '\0';
/* first, prepend the prefix string */ /* first, prepend the prefix string */
n1 = snprintf(data, MAX_PREFIX_SIZE, "%s%d_", n1 = scnprintf(data, MAX_PREFIX_SIZE, "%s%d_",
prefix, i); prefix, i);
n1 = min_t(uint, n1, MAX_PREFIX_SIZE - 1);
size_left = (ETH_GSTRING_LEN - 1) - n1; size_left = (ETH_GSTRING_LEN - 1) - n1;
/* now, concatenate the stats string to it */ /* now, concatenate the stats string to it */
......
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