Overwrite dev date by no primary process would cause
segment fault issue to primary proccess during receive pkt

Signed-off-by: Haibo Zhang <zhanghai...@huawei.com>
---
 lib/librte_ether/rte_ethdev.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 9dea1f1..e25f056 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -212,12 +212,15 @@ struct rte_eth_dev *
 
        eth_dev = &rte_eth_devices[port_id];
        eth_dev->data = &rte_eth_dev_data[port_id];
-       memset(eth_dev->data, 0, sizeof(*eth_dev->data));
-       snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
-       eth_dev->data->port_id = port_id;
-       eth_dev->data->mtu = ETHER_MTU;
-       TAILQ_INIT(&(eth_dev->link_intr_cbs));
+       if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+               memset(eth_dev->data, 0, sizeof(*eth_dev->data));
+               snprintf(eth_dev->data->name,
+                       sizeof(eth_dev->data->name), "%s", name);
+               eth_dev->data->port_id = port_id;
+               eth_dev->data->mtu = ETHER_MTU;
+       }
 
+       TAILQ_INIT(&(eth_dev->link_intr_cbs));
        eth_dev->attached = DEV_ATTACHED;
        eth_dev_last_created_port = port_id;
        nb_ports++;
-- 
1.8.3.1

Reply via email to