From: "luobin (L)" <luobin9@huawei.com>
To: David Miller <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: Re: [PATCH net-next] hinic: fix strncpy output truncated compile warnings
Date: Fri, 7 Aug 2020 10:02:48 +0800 [thread overview]
Message-ID: <16468b06-3aaf-c871-820e-7ad41b952dd4@huawei.com> (raw)
In-Reply-To: <7f9e241e-3ad6-b250-11b1-a16d1dc2df68@huawei.com>
On 2020/8/7 8:57, luobin (L) wrote:
> On 2020/8/7 3:01, David Miller wrote:
>> From: Luo bin <luobin9@huawei.com>
>> Date: Thu, 6 Aug 2020 15:48:30 +0800
>>
>>> 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) {
>>
>> Please fix these cases consistently, either use the strlen()+1 pattern
>> or the "sizeof(destination)" one.
>>
>> Probably sizeof(destination) is best.
>> .
>>
> Will fix. Thanks. Level_str array is initialized to zero, so can't use the strlen()+1 pattern, I'll
> use strlen()+1 consistently.
>
I have tried to use 'sizeof(level_str)' instead of 'strlen(fault_level[level]) + 1', but this will lead
to following compile warning:
In function ‘strncpy’,
inlined from ‘chip_fault_show’ at drivers/net/ethernet/huawei/hinic/hinic_devlink.c:345:3:
./include/linux/string.h:297:30: warning: ‘__builtin_strncpy’ specified bound 17 equals destination size [-Wstringop-truncation]
297 | #define __underlying_strncpy __builtin_strncpy
So I will use the strlen()+1 pattern consistently.
prev parent reply other threads:[~2020-08-07 2:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-06 7:48 [PATCH net-next] hinic: fix strncpy output truncated compile warnings Luo bin
2020-08-06 19:01 ` David Miller
2020-08-07 0:57 ` luobin (L)
2020-08-07 2:02 ` luobin (L) [this message]
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=16468b06-3aaf-c871-820e-7ad41b952dd4@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