Skip to contentSkip to conversation

virtio: fix size of mac_addrs array in virtio ports

PATCH Superseded David Marchand 3 participants 4 messages Oct 29, 2015 – Nov 3, 2015 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio: fix size of mac_addrs array in virtio ports

From: Ivan Boule <[email protected]>

Make the virtio PMD allocate the array of unicast MAC addresses with the maximum of entries (VIRTIO_MAX_MAC_ADDRS) that it exports.

---
 drivers/net/virtio/virtio_ethdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_ethdev.c +2 -2
index 12fcc23..79a97c3 100644
@@ -1175,11 +1175,11 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 	}
 
 	/* Allocate memory for storing MAC addresses */
-	eth_dev->data->mac_addrs = rte_zmalloc("virtio", ETHER_ADDR_LEN, 0);
+	eth_dev->data->mac_addrs = rte_zmalloc("virtio", VIRTIO_MAX_MAC_ADDRS * ETHER_ADDR_LEN, 0);
 	if (eth_dev->data->mac_addrs == NULL) {
 		PMD_INIT_LOG(ERR,
 			"Failed to allocate %d bytes needed to store MAC addresses",
-			ETHER_ADDR_LEN);
+			VIRTIO_MAX_MAC_ADDRS * ETHER_ADDR_LEN);
 		return -ENOMEM;
 	}
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 16 lines · David Marchand

From: Ivan Boule <[email protected]>

Make the virtio PMD allocate the array of unicast MAC addresses with the maximum of entries (VIRTIO_MAX_MAC_ADDRS) that it exports.

---
 drivers/net/virtio/virtio_ethdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_ethdev.c +0 -0
index 12fcc23..79a97c3 100644

drivers/net/virtio/virtio_ethdev.c eth_virtio_dev_init(struct rte_eth_dev *eth_dev) · line 1178

Quoted 5 lines
drivers/net/virtio/virtio_ethdev.c +1 -1
@@ -1175,11 +1175,11 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 	}
 
 	/* Allocate memory for storing MAC addresses */
-	eth_dev->data->mac_addrs = rte_zmalloc("virtio", ETHER_ADDR_LEN, 0);
+	eth_dev->data->mac_addrs = rte_zmalloc("virtio", VIRTIO_MAX_MAC_ADDRS * ETHER_ADDR_LEN, 0);

Looks good to me, except that you should try to limit it to 80 chars.

	--yliu
Quoted 10 lines
drivers/net/virtio/virtio_ethdev.c +1 -1
 	if (eth_dev->data->mac_addrs == NULL) {
 		PMD_INIT_LOG(ERR,
 			"Failed to allocate %d bytes needed to store MAC addresses",
-			ETHER_ADDR_LEN);
+			VIRTIO_MAX_MAC_ADDRS * ETHER_ADDR_LEN);
 		return -ENOMEM;
 	}
 
Signature · 1 line
1.9.1
#2 lore raw

PATCH v2 1/1 virtio: fix size of mac_addrs array in virtio ports

In reply to David Marchand

From: Ivan Boule <[email protected]>

Make the virtio PMD allocate the array of unicast MAC addresses with the maximum of entries (VIRTIO_MAX_MAC_ADDRS) that it exports.

---
Changes since v1:
* fix checkpatch warning (thanks Yuanhan)

 drivers/net/virtio/virtio_ethdev.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_ethdev.c +3 -2
index 12fcc23..636b182 100644
@@ -1163,6 +1163,7 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 	struct virtio_net_config *config;
 	struct virtio_net_config local_config;
 	struct rte_pci_device *pci_dev;
+	const size_t mac_array_size = VIRTIO_MAX_MAC_ADDRS * ETHER_ADDR_LEN;
 
 	RTE_BUILD_BUG_ON(RTE_PKTMBUF_HEADROOM < sizeof(struct virtio_net_hdr));
 
@@ -1175,11 +1176,11 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 	}
 
 	/* Allocate memory for storing MAC addresses */
-	eth_dev->data->mac_addrs = rte_zmalloc("virtio", ETHER_ADDR_LEN, 0);
+	eth_dev->data->mac_addrs = rte_zmalloc("virtio", mac_array_size, 0);
 	if (eth_dev->data->mac_addrs == NULL) {
 		PMD_INIT_LOG(ERR,
 			"Failed to allocate %d bytes needed to store MAC addresses",
-			ETHER_ADDR_LEN);
+			mac_array_size);
 		return -ENOMEM;
 	}
 
Signature · 1 line
1.9.1