Re: mainline build failure due to 281d0c962752 ("fortify: Add Clang support")

From: Linus Torvalds
Date: Wed Jun 22 2022 - 11:19:55 EST


On Wed, Jun 22, 2022 at 10:08 AM Sudip Mukherjee
<sudipm.mukherjee@xxxxxxxxx> wrote:
>
> Yeah, true. I had to check to find out its from the memcpy() in check_image_valid().

Funky but true - I can reproduce it, and just commenting out that
memcpy fixes the warning.

And I see nothing wrong with that code - it's copying a 'struct
fw_section_info_st' between two other structs that seem to have arrays
that are appropriately sized.

Replacing the memcpy() with just a structure assignment seems to get
rid of the warning, and seems to be a simple fix (patch attached), but
I don't understand why that memcpy() would warn.

This looks like a clang bug to me, but maybe I'm missing something.

Linus
drivers/net/ethernet/huawei/hinic/hinic_devlink.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/huawei/hinic/hinic_devlink.c b/drivers/net/ethernet/huawei/hinic/hinic_devlink.c
index 60ae8bfc5f69..1749d26f4bef 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_devlink.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_devlink.c
@@ -43,9 +43,7 @@ static bool check_image_valid(struct hinic_devlink_priv *priv, const u8 *buf,

for (i = 0; i < fw_image->fw_info.fw_section_cnt; i++) {
len += fw_image->fw_section_info[i].fw_section_len;
- memcpy(&host_image->image_section_info[i],
- &fw_image->fw_section_info[i],
- sizeof(struct fw_section_info_st));
+ host_image->image_section_info[i] = fw_image->fw_section_info[i];
}

if (len != fw_image->fw_len ||