From: Chen Zhou chenzhou10@huawei.com
mainline inclusion from mainline-v5.6-rc1 commit bea5416561b1b997adbe3a04a5665e647c589a13 category: feature bugzilla: NA CVE: NA
----------------------------
snprintf returns the number of bytes that would be written, which may be greater than 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. Milldder davem@davemloft.net Signed-off-by: Yonglong Liu liuyonglong@huawei.com Reviewed-by: Junxin Chen chenjunxin1@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c index bc1aa74b039fd..1bebeb3bbdf04 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c @@ -445,9 +445,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 */