Skip to contentSkip to conversation

net: hns3: replace snprintf with scnprintf in hns3_update_strings

PATCH In review Chen Zhou 2 participants 3 messages Jan 19, 2020 – Jan 20, 2020

Subsystems (4)
lore
Share & tools
lore

Chen Zhou

author
#0 lore raw

PATCH 1/1 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.

---
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +1 -2
index 6e0212b..fa01888 100644
@@ -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_",
+			n1 = scnprintf(data, MAX_PREFIX_SIZE, "%s%d_",
 				      prefix, i);
-			n1 = min_t(uint, n1, MAX_PREFIX_SIZE - 1);
 			size_left = (ETH_GSTRING_LEN - 1) - n1;
 
 			/* now, concatenate the stats string to it */
Signature · 1 line
2.7.4
#1 lore raw
Quoted 17 lines · Chen Zhou

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.

---
  drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +0 -0
index 6e0212b..fa01888 100644

drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c static void *hns3_update_strings(u8 *data, const struct hns3_stats *stats, · line 427

Quoted 6 lines
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +1 -1
@@ -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_",
+			n1 = scnprintf(data, MAX_PREFIX_SIZE, "%s%d_",
  				      prefix, i);

not align?

Quoted 5 lines
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +0 -1
-			n1 = min_t(uint, n1, MAX_PREFIX_SIZE - 1);
  			size_left = (ETH_GSTRING_LEN - 1) - n1;
 
  			/* now, concatenate the stats string to it */
author
#2 lore raw
Quoted 15 lines · tanhuazhong
Quoted 12 lines · Chen Zhou

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.

---
  drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 12 lines

drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c static void *hns3_update_strings(u8 *data, const struct hns3_stats *stats, · line 426

Quoted 10 lines
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +1 -1
index 6e0212b..fa01888 100644
@@ -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_",
+            n1 = scnprintf(data, MAX_PREFIX_SIZE, "%s%d_",
                        prefix, i);

not align?

Ok, I will fix it in next version.

Thanks,
Chen Zhou

Quoted 9 lines

drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c static void *hns3_update_strings(u8 *data, const struct hns3_stats *stats,

Quoted 5 lines
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +0 -1
-            n1 = min_t(uint, n1, MAX_PREFIX_SIZE - 1);
              size_left = (ETH_GSTRING_LEN - 1) - n1;
                /* now, concatenate the stats string to it */
 

.