From: Luo bin <luobin9@huawei.com>
To: <davem@davemloft.net>
Cc: <linux-kernel@vger.kernel.org>, <netdev@vger.kernel.org>,
<luoxianjun@huawei.com>, <yin.yinshi@huawei.com>,
<cloud.wangxiaoyun@huawei.com>, <chiqijun@huawei.com>
Subject: [PATCH net-next] hinic: fix strncpy output truncated compile warnings
Date: Thu, 6 Aug 2020 15:48:30 +0800 [thread overview]
Message-ID: <20200806074830.1375-1-luobin9@huawei.com> (raw)
fix the compile warnings of 'strncpy' output truncated before
terminating nul copying N bytes from a string of the same length
Signed-off-by: Luo bin <luobin9@huawei.com>
Reported-by: kernel test robot <lkp@intel.com>
---
drivers/net/ethernet/huawei/hinic/hinic_devlink.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_devlink.c b/drivers/net/ethernet/huawei/hinic/hinic_devlink.c
index c6adc776f3c8..1dc948c07b94 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_devlink.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_devlink.c
@@ -342,9 +342,9 @@ static int chip_fault_show(struct devlink_fmsg *fmsg,
level = event->event.chip.err_level;
if (level < FAULT_LEVEL_MAX)
- strncpy(level_str, fault_level[level], strlen(fault_level[level]));
+ strncpy(level_str, fault_level[level], strlen(fault_level[level]) + 1);
else
- strncpy(level_str, "Unknown", strlen("Unknown"));
+ strncpy(level_str, "Unknown", sizeof(level_str));
if (level == FAULT_LEVEL_SERIOUS_FLR) {
err = devlink_fmsg_u32_pair_put(fmsg, "Function level err func_id",
@@ -388,9 +388,9 @@ static int fault_report_show(struct devlink_fmsg *fmsg,
int err;
if (event->type < FAULT_TYPE_MAX)
- strncpy(type_str, fault_type[event->type], strlen(fault_type[event->type]));
+ strncpy(type_str, fault_type[event->type], strlen(fault_type[event->type]) + 1);
else
- strncpy(type_str, "Unknown", strlen("Unknown"));
+ strncpy(type_str, "Unknown", sizeof(type_str));
err = devlink_fmsg_string_pair_put(fmsg, "Fault type", type_str);
if (err)
--
2.17.1
next reply other threads:[~2020-08-06 11:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-06 7:48 Luo bin [this message]
2020-08-06 19:01 ` [PATCH net-next] hinic: fix strncpy output truncated compile warnings David Miller
2020-08-07 0:57 ` luobin (L)
2020-08-07 2:02 ` luobin (L)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200806074830.1375-1-luobin9@huawei.com \
--to=luobin9@huawei.com \
--cc=chiqijun@huawei.com \
--cc=cloud.wangxiaoyun@huawei.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=luoxianjun@huawei.com \
--cc=netdev@vger.kernel.org \
--cc=yin.yinshi@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).