Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: hns3: tracing: fix hclgevf trace event strings

The __string() and __assign_str() helper macros of the TRACE_EVENT() macro
are going through some optimizations where only the source string of
__string() will be used and the __assign_str() source will be ignored and
later removed.

To make sure that there's no issues, a new check is added between the
__string() src argument and the __assign_str() src argument that does a
strcmp() to make sure they are the same string.

The hclgevf trace events have:

__assign_str(devname, &hdev->nic.kinfo.netdev->name);

Which triggers the warning:

hclgevf_trace.h:34:39: error: passing argument 1 of ‘strcmp’ from incompatible pointer type [-Werror=incompatible-pointer-types]
34 | __assign_str(devname, &hdev->nic.kinfo.netdev->name);
[..]
arch/x86/include/asm/string_64.h:75:24: note: expected ‘const char *’ but argument is of type ‘char (*)[16]’
75 | int strcmp(const char *cs, const char *ct);
| ~~~~~~~~~~~~^~

Because __assign_str() now has:

WARN_ON_ONCE(__builtin_constant_p(src) ? \
strcmp((src), __data_offsets.dst##_ptr_) : \
(src) != __data_offsets.dst##_ptr_); \

The problem is the '&' on hdev->nic.kinfo.netdev->name. That's because
that name is:

char name[IFNAMSIZ]

Where passing an address '&' of a char array is not compatible with strcmp().

The '&' is not necessary, remove it.

Link: https://lore.kernel.org/linux-trace-kernel/20240313093454.3909afe7@gandalf.local.home

Cc: netdev <netdev@vger.kernel.org>
Cc: Yisen Zhuang <yisen.zhuang@huawei.com>
Cc: Salil Mehta <salil.mehta@huawei.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Yufeng Mo <moyufeng@huawei.com>
Cc: Huazhong Tan <tanhuazhong@huawei.com>
Cc: stable@vger.kernel.org
Acked-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Jijie Shao <shaojijie@huawei.com>
Fixes: d8355240cf8fb ("net: hns3: add trace event support for PF/VF mailbox")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

+8 -8
+4 -4
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_trace.h
··· 24 24 __field(u8, code) 25 25 __field(u8, subcode) 26 26 __string(pciname, pci_name(hdev->pdev)) 27 - __string(devname, &hdev->vport[0].nic.kinfo.netdev->name) 27 + __string(devname, hdev->vport[0].nic.kinfo.netdev->name) 28 28 __array(u32, mbx_data, PF_GET_MBX_LEN) 29 29 ), 30 30 ··· 33 33 __entry->code = req->msg.code; 34 34 __entry->subcode = req->msg.subcode; 35 35 __assign_str(pciname, pci_name(hdev->pdev)); 36 - __assign_str(devname, &hdev->vport[0].nic.kinfo.netdev->name); 36 + __assign_str(devname, hdev->vport[0].nic.kinfo.netdev->name); 37 37 memcpy(__entry->mbx_data, req, 38 38 sizeof(struct hclge_mbx_vf_to_pf_cmd)); 39 39 ), ··· 56 56 __field(u8, vfid) 57 57 __field(u16, code) 58 58 __string(pciname, pci_name(hdev->pdev)) 59 - __string(devname, &hdev->vport[0].nic.kinfo.netdev->name) 59 + __string(devname, hdev->vport[0].nic.kinfo.netdev->name) 60 60 __array(u32, mbx_data, PF_SEND_MBX_LEN) 61 61 ), 62 62 ··· 64 64 __entry->vfid = req->dest_vfid; 65 65 __entry->code = le16_to_cpu(req->msg.code); 66 66 __assign_str(pciname, pci_name(hdev->pdev)); 67 - __assign_str(devname, &hdev->vport[0].nic.kinfo.netdev->name); 67 + __assign_str(devname, hdev->vport[0].nic.kinfo.netdev->name); 68 68 memcpy(__entry->mbx_data, req, 69 69 sizeof(struct hclge_mbx_pf_to_vf_cmd)); 70 70 ),
+4 -4
drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_trace.h
··· 23 23 __field(u8, vfid) 24 24 __field(u16, code) 25 25 __string(pciname, pci_name(hdev->pdev)) 26 - __string(devname, &hdev->nic.kinfo.netdev->name) 26 + __string(devname, hdev->nic.kinfo.netdev->name) 27 27 __array(u32, mbx_data, VF_GET_MBX_LEN) 28 28 ), 29 29 ··· 31 31 __entry->vfid = req->dest_vfid; 32 32 __entry->code = le16_to_cpu(req->msg.code); 33 33 __assign_str(pciname, pci_name(hdev->pdev)); 34 - __assign_str(devname, &hdev->nic.kinfo.netdev->name); 34 + __assign_str(devname, hdev->nic.kinfo.netdev->name); 35 35 memcpy(__entry->mbx_data, req, 36 36 sizeof(struct hclge_mbx_pf_to_vf_cmd)); 37 37 ), ··· 55 55 __field(u8, code) 56 56 __field(u8, subcode) 57 57 __string(pciname, pci_name(hdev->pdev)) 58 - __string(devname, &hdev->nic.kinfo.netdev->name) 58 + __string(devname, hdev->nic.kinfo.netdev->name) 59 59 __array(u32, mbx_data, VF_SEND_MBX_LEN) 60 60 ), 61 61 ··· 64 64 __entry->code = req->msg.code; 65 65 __entry->subcode = req->msg.subcode; 66 66 __assign_str(pciname, pci_name(hdev->pdev)); 67 - __assign_str(devname, &hdev->nic.kinfo.netdev->name); 67 + __assign_str(devname, hdev->nic.kinfo.netdev->name); 68 68 memcpy(__entry->mbx_data, req, 69 69 sizeof(struct hclge_mbx_vf_to_pf_cmd)); 70 70 ),