diff mbox series

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

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

Commit Message

chenzhou Jan. 19, 2020, 12:41 p.m. UTC
The return value of snprintf may be greater than the size of
HNS3_DBG_READ_LEN, use scnprintf instead in hns3_dbg_cmd_read.

Signed-off-by: Chen Zhou <chenzhou10@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

tanhuazhong Jan. 20, 2020, 1:28 a.m. UTC | #1
On 2020/1/19 20:41, Chen Zhou wrote:
> The return value of snprintf may be greater than the size of
> HNS3_DBG_READ_LEN, use scnprintf instead in hns3_dbg_cmd_read.
> 
> Signed-off-by: Chen Zhou <chenzhou10@huawei.com>
> ---
>   drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
> index 6b328a2..8fad699 100644
> --- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
> @@ -297,7 +297,7 @@ static ssize_t hns3_dbg_cmd_read(struct file *filp, char __user *buffer,
>   	if (!buf)
>   		return -ENOMEM;
>   
> -	len = snprintf(buf, HNS3_DBG_READ_LEN, "%s\n",
> +	len = scnprintf(buf, HNS3_DBG_READ_LEN, "%s\n",
>   		       "Please echo help to cmd to get help information");

not align?

>   	uncopy_bytes = copy_to_user(buffer, buf, len);
>   
>
chenzhou Jan. 20, 2020, 2:37 a.m. UTC | #2
On 2020/1/20 9:28, tanhuazhong wrote:
> 
> 
> On 2020/1/19 20:41, Chen Zhou wrote:
>> The return value of snprintf may be greater than the size of
>> HNS3_DBG_READ_LEN, use scnprintf instead in hns3_dbg_cmd_read.
>>
>> Signed-off-by: Chen Zhou <chenzhou10@huawei.com>
>> ---
>>   drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
>> index 6b328a2..8fad699 100644
>> --- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
>> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
>> @@ -297,7 +297,7 @@ static ssize_t hns3_dbg_cmd_read(struct file *filp, char __user *buffer,
>>       if (!buf)
>>           return -ENOMEM;
>>   -    len = snprintf(buf, HNS3_DBG_READ_LEN, "%s\n",
>> +    len = scnprintf(buf, HNS3_DBG_READ_LEN, "%s\n",
>>                  "Please echo help to cmd to get help information");
> 
> not align?

Ok, i will fix in next version.

Thanks,
Chen Zhou

> 
>>       uncopy_bytes = copy_to_user(buffer, buf, len);
>>  
> 
> 
> .
>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index 6b328a2..8fad699 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -297,7 +297,7 @@  static ssize_t hns3_dbg_cmd_read(struct file *filp, char __user *buffer,
 	if (!buf)
 		return -ENOMEM;
 
-	len = snprintf(buf, HNS3_DBG_READ_LEN, "%s\n",
+	len = scnprintf(buf, HNS3_DBG_READ_LEN, "%s\n",
 		       "Please echo help to cmd to get help information");
 	uncopy_bytes = copy_to_user(buffer, buf, len);