From: Michael Tokarev Date: Thu, 23 Oct 2025 13:53:09 +0000 (+0300) Subject: hw/net/virtio-net: make VirtIONet.vlans an array instead of a pointer X-Git-Tag: v10.2.0-rc1~41^2~20 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3a9cd2a4a1571266dea37398de04f650c2a72d86;p=thirdparty%2Fqemu.git hw/net/virtio-net: make VirtIONet.vlans an array instead of a pointer This field is a fixed-size buffer (number of elements is MAX_VLAN, known at build time). There's no need to allocate it dynamically, it can be made an integral part of VirtIONet structure. This field is the only user of VMSTATE_BUFFER_POINTER_UNSAFE() macro. Reviewed-by: Akihiko Odaki Tested-by: Lei Yang Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Michael Tokarev Message-ID: <20251023135316.31128-2-mjt@tls.msk.ru> Signed-off-by: Philippe Mathieu-Daudé --- diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 33116712eb..17ed0ef919 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -986,7 +986,7 @@ static void virtio_net_set_features(VirtIODevice *vdev, virtio_has_feature_ex(vdev->guest_features_ex, VIRTIO_NET_F_CTRL_VLAN)) { bool vlan = virtio_has_feature_ex(features, VIRTIO_NET_F_CTRL_VLAN); - memset(n->vlans, vlan ? 0 : 0xff, MAX_VLAN >> 3); + memset(n->vlans, vlan ? 0 : 0xff, sizeof(n->vlans)); } if (virtio_has_feature_ex(features, VIRTIO_NET_F_STANDBY)) { @@ -3600,7 +3600,8 @@ static const VMStateDescription vmstate_virtio_net_device = { * buffer; hold onto your endiannesses; it's actually used as a bitmap * but based on the uint. */ - VMSTATE_BUFFER_POINTER_UNSAFE(vlans, VirtIONet, 0, MAX_VLAN >> 3), + VMSTATE_BUFFER_UNSAFE(vlans, VirtIONet, 0, + sizeof(typeof_field(VirtIONet, vlans))), VMSTATE_WITH_TMP(VirtIONet, struct VirtIONetMigTmp, vmstate_virtio_net_has_vnet), VMSTATE_UINT8(mac_table.multi_overflow, VirtIONet), @@ -4018,8 +4019,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) n->mac_table.macs = g_malloc0(MAC_TABLE_ENTRIES * ETH_ALEN); - n->vlans = g_malloc0(MAX_VLAN >> 3); - memset(n->vlans, 0xff, MAX_VLAN >> 3); + memset(n->vlans, 0xff, sizeof(n->vlans)); nc = qemu_get_queue(n->nic); nc->rxfilter_notify_enabled = 1; @@ -4068,7 +4068,6 @@ static void virtio_net_device_unrealize(DeviceState *dev) n->netclient_type = NULL; g_free(n->mac_table.macs); - g_free(n->vlans); if (n->failover) { qobject_unref(n->primary_opts); diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 5b8ab7bda7..f708355306 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -202,7 +202,7 @@ struct VirtIONet { uint8_t uni_overflow; uint8_t *macs; } mac_table; - uint32_t *vlans; + uint32_t vlans[MAX_VLAN]; virtio_net_conf net_conf; NICConf nic_conf; DeviceState *qdev;