2020-01-20 12:55:51

by chenzhou

[permalink] [raw]
Subject: [PATCH -next v2] net: hns3: replace snprintf with scnprintf in hns3_dbg_cmd_read

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 <[email protected]>
---

changes in v2:
- fix checkpatch style problem.

---
drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index 6b328a2..92ee1f5 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -297,8 +297,8 @@ 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",
- "Please echo help to cmd to get help information");
+ 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);

kfree(buf);
--
2.7.4


2020-01-21 09:50:17

by David Miller

[permalink] [raw]
Subject: Re: [PATCH -next v2] net: hns3: replace snprintf with scnprintf in hns3_dbg_cmd_read

From: Chen Zhou <[email protected]>
Date: Mon, 20 Jan 2020 20:49:43 +0800

> 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 <[email protected]>
> ---
>
> changes in v2:
> - fix checkpatch style problem.

Both conversion patches applied, thank you.