diff mbox series

[-next] net: hns3: replace snprintf with scnprintf in hns3_update_strings

Message ID 20200119124053.30262-1-chenzhou10@huawei.com
State Changes Requested
Delegated to: David Miller
Headers show
Series [-next] net: hns3: replace snprintf with scnprintf in hns3_update_strings | expand

Commit Message

chenzhou Jan. 19, 2020, 12:40 p.m. UTC
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>
---
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

tanhuazhong Jan. 20, 2020, 1:27 a.m. UTC | #1
On 2020/1/19 20:40, Chen Zhou wrote:
> 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>
> ---
>   drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
> index 6e0212b..fa01888 100644
> --- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
> @@ -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?

> -			n1 = min_t(uint, n1, MAX_PREFIX_SIZE - 1);
>   			size_left = (ETH_GSTRING_LEN - 1) - n1;
>   
>   			/* now, concatenate the stats string to it */
>
chenzhou Jan. 20, 2020, 2:38 a.m. UTC | #2
On 2020/1/20 9:27, tanhuazhong wrote:
> 
> 
> On 2020/1/19 20:40, Chen Zhou wrote:
>> 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>
>> ---
>>   drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 3 +--
>>   1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
>> index 6e0212b..fa01888 100644
>> --- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
>> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
>> @@ -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

> 
>> -            n1 = min_t(uint, n1, MAX_PREFIX_SIZE - 1);
>>               size_left = (ETH_GSTRING_LEN - 1) - n1;
>>                 /* now, concatenate the stats string to it */
>>
> 
> 
> .
>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index 6e0212b..fa01888 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -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 */