[PATCH 3/5] util: netdev: Dynamically allocate 'struct nlattr' in virNetDevSwitchdevFeature

Peter Krempa pkrempa at redhat.com
Thu Sep 8 12:25:02 UTC 2022


At time of writing DEVLINK_ATTR_MAX equals to 176, thus the stack'd size
of the pointer array is almost 1.4kiB. Allocate it dynamically.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/util/virnetdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 6c6f6dee42..66cfc5d781 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -3210,7 +3210,7 @@ virNetDevSwitchdevFeature(const char *ifname,
     struct nl_msg *nl_msg = NULL;
     g_autofree struct nlmsghdr *resp = NULL;
     unsigned int recvbuflen;
-    struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {NULL, };
+    g_autofree struct nlattr **tb = g_new0(struct nlattr *, DEVLINK_ATTR_MAX + 1);
     g_autoptr(virPCIDevice) pci_device_ptr = NULL;
     struct genlmsghdr gmsgh = {
         .cmd = DEVLINK_CMD_ESWITCH_GET,
-- 
2.37.1



More information about the libvir-list mailing list