[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 01/17] hw/rdma/vmw/pvrdma_cmd: Use correct struct in query_port()
|
From: |
Michael Tokarev |
|
Subject: |
[PULL 01/17] hw/rdma/vmw/pvrdma_cmd: Use correct struct in query_port() |
|
Date: |
Sat, 21 Oct 2023 15:05:03 +0300 |
From: Peter Maydell <peter.maydell@linaro.org>
In query_port() we pass the address of a local pvrdma_port_attr
struct to the rdma_query_backend_port() function. Unfortunately,
rdma_backend_query_port() wants a pointer to a struct ibv_port_attr,
and the two are not the same length.
Coverity spotted this (CID 1507146): pvrdma_port_attr is 48 bytes
long, and ibv_port_attr is 52 bytes, because it has a few extra
fields at the end.
Fortunately, all we do with the attrs struct after the call is to
read a few specific fields out of it which are all at the same
offsets in both structs, so we can simply make the local variable the
correct type. This also lets us drop the cast (which should have
been a bit of a warning flag that we were doing something wrong
here).
We do however need to add extra casts for the fields of the
struct that are enums: clang will complain about the implicit
cast to a different enum type otherwise.
Cc: qemu-stable@nongnu.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
hw/rdma/vmw/pvrdma_cmd.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/hw/rdma/vmw/pvrdma_cmd.c b/hw/rdma/vmw/pvrdma_cmd.c
index c6ed025982..d385d18d9c 100644
--- a/hw/rdma/vmw/pvrdma_cmd.c
+++ b/hw/rdma/vmw/pvrdma_cmd.c
@@ -129,23 +129,27 @@ static int query_port(PVRDMADev *dev, union
pvrdma_cmd_req *req,
{
struct pvrdma_cmd_query_port *cmd = &req->query_port;
struct pvrdma_cmd_query_port_resp *resp = &rsp->query_port_resp;
- struct pvrdma_port_attr attrs = {};
+ struct ibv_port_attr attrs = {};
if (cmd->port_num > MAX_PORTS) {
return -EINVAL;
}
- if (rdma_backend_query_port(&dev->backend_dev,
- (struct ibv_port_attr *)&attrs)) {
+ if (rdma_backend_query_port(&dev->backend_dev, &attrs)) {
return -ENOMEM;
}
memset(resp, 0, sizeof(*resp));
- resp->attrs.state = dev->func0->device_active ? attrs.state :
- PVRDMA_PORT_DOWN;
- resp->attrs.max_mtu = attrs.max_mtu;
- resp->attrs.active_mtu = attrs.active_mtu;
+ /*
+ * The state, max_mtu and active_mtu fields are enums; the values
+ * for pvrdma_port_state and pvrdma_mtu match those for
+ * ibv_port_state and ibv_mtu, so we can cast them safely.
+ */
+ resp->attrs.state = dev->func0->device_active ?
+ (enum pvrdma_port_state)attrs.state : PVRDMA_PORT_DOWN;
+ resp->attrs.max_mtu = (enum pvrdma_mtu)attrs.max_mtu;
+ resp->attrs.active_mtu = (enum pvrdma_mtu)attrs.active_mtu;
resp->attrs.phys_state = attrs.phys_state;
resp->attrs.gid_tbl_len = MIN(MAX_PORT_GIDS, attrs.gid_tbl_len);
resp->attrs.max_msg_sz = 1024;
--
2.39.2
- [PULL 00/17] Trivial patches for 2023-10-21, Michael Tokarev, 2023/10/21
- [PULL 01/17] hw/rdma/vmw/pvrdma_cmd: Use correct struct in query_port(),
Michael Tokarev <=
- [PULL 02/17] hw/ppc/ppc440_uc: Remove dead l2sram_update_mappings(), Michael Tokarev, 2023/10/21
- [PULL 03/17] MAINTAINERS: Cover hw/ppc/ppc440_uc.c with Sam460ex board, Michael Tokarev, 2023/10/21
- [PULL 05/17] MAINTAINERS: Add include/hw/intc/i8259.h to the PC chip section, Michael Tokarev, 2023/10/21
- [PULL 08/17] ppc/{bamboo, virtex_ml507}: Remove useless dependency on ppc405.h header, Michael Tokarev, 2023/10/21
- [PULL 10/17] MAINTAINERS: Adjust file list for PPC 4xx CPUs, Michael Tokarev, 2023/10/21
- [PULL 06/17] MAINTAINERS: Add docs/devel/ebpf_rss.rst to the EBPF section, Michael Tokarev, 2023/10/21
- [PULL 04/17] MAINTAINERS: Add the nios2 interrupt controller to the nios2 section, Michael Tokarev, 2023/10/21
- [PULL 09/17] MAINTAINERS: Adjust file list for PPC ref405ep machine, Michael Tokarev, 2023/10/21
- [PULL 07/17] MAINTAINERS: Fix a couple s390 paths, Michael Tokarev, 2023/10/21
- [PULL 11/17] MAINTAINERS: Adjust file list for PPC e500 machines, Michael Tokarev, 2023/10/21