]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
net: hns3: replace snprintf with scnprintf in hns3_update_strings
authorChen Zhou <chenzhou10@huawei.com>
Mon, 20 Jan 2020 12:50:33 +0000 (20:50 +0800)
committerDavid S. Miller <davem@davemloft.net>
Tue, 21 Jan 2020 09:48:40 +0000 (10:48 +0100)
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: Chen Zhou <chenzhou10@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c

index 6e0212b79438a21ff02fa5b9054edb13be58e8a0..c03856e63320234b2d0659cd85b6a624673c2cfe 100644 (file)
@@ -423,9 +423,8 @@ static void *hns3_update_strings(u8 *data, const struct hns3_stats *stats,
                        data[ETH_GSTRING_LEN - 1] = '\0';
 
                        /* first, prepend the prefix string */
-                       n1 = snprintf(data, MAX_PREFIX_SIZE, "%s%d_",
-                                     prefix, i);
-                       n1 = min_t(uint, n1, MAX_PREFIX_SIZE - 1);
+                       n1 = scnprintf(data, MAX_PREFIX_SIZE, "%s%d_",
+                                      prefix, i);
                        size_left = (ETH_GSTRING_LEN - 1) - n1;
 
                        /* now, concatenate the stats string to it */