Hi Reshma, > -----Original Message----- > From: Pattan, Reshma > Sent: Wednesday, September 28, 2016 4:04 PM > To: Kerlin, MarcinX <marcinx.kerlin at intel.com>; dev at dpdk.org > Cc: De Lara Guarch, Pablo <pablo.de.lara.guarch at intel.com>; > thomas.monjalon at 6wind.com; Kerlin, MarcinX <marcinx.kerlin at intel.com> > Subject: RE: [dpdk-dev] [PATCH v4 1/2] librte_ether: add protection against > overwrite device data > > > > > -----Original Message----- > > From: dev [mailto:dev-bounces at dpdk.org] On Behalf Of Marcin Kerlin > > Sent: Tuesday, September 27, 2016 12:13 PM > > To: dev at dpdk.org > > Cc: De Lara Guarch, Pablo <pablo.de.lara.guarch at intel.com>; > > thomas.monjalon at 6wind.com; Kerlin, MarcinX <marcinx.kerlin at intel.com> > > Subject: [dpdk-dev] [PATCH v4 1/2] librte_ether: add protection > > against overwrite device data > > > > +int > > +rte_eth_dev_release_dev_data(uint8_t port_id) { > > + char device[RTE_ETH_NAME_MAX_LEN]; > > + struct rte_eth_dev_data *eth_dev_data = NULL; > > + > > + > > @@ -631,6 +691,8 @@ int > > rte_eth_dev_detach(uint8_t port_id, char *name) { > > struct rte_pci_addr addr; > > + struct rte_eth_dev_data *eth_dev_data = NULL; > > + char device[RTE_ETH_NAME_MAX_LEN]; > > int ret = -1; > > > > if (name == NULL) { > > @@ -642,6 +704,15 @@ rte_eth_dev_detach(uint8_t port_id, char *name) > > if (rte_eth_dev_is_detachable(port_id)) > > goto err; > > > > + /* get device name by port id */ > > + if (rte_eth_dev_get_name_by_port(port_id, device)) > > + goto err; > > + > > + /* look for an entry in the shared device data */ > > + eth_dev_data = rte_eth_dev_get_dev_data_by_name(device); > > + if (eth_dev_data == NULL) > > + goto err; > > + > > if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) { > > ret = rte_eth_dev_get_addr_by_port(port_id, &addr); > > if (ret < 0) > > @@ -661,6 +732,9 @@ rte_eth_dev_detach(uint8_t port_id, char *name) > > goto err; > > } > > > > + /* clear an entry in the shared device data */ > > + memset(eth_dev_data, 0, sizeof(struct rte_eth_dev_data)); > > + > > return 0; > > > > In this function, the new code chunks together is nothing but the function " > rte_eth_dev_release_dev_data()". > So u can call the function itself rather than a duplicate code.
It was intentional, reason: If I call function in place: (1) beginning: then I lose device name for function below rte_eth_dev_detach_vdev (1.1): a) this is important for drivers that hold name in shared rte_eth_dev_data[] b) not important for drivers that prepare own rte_eth_dev_data e.g pcap (rte_eth_pcap.c, line 816) (2) end: then I lose device name for my function rte_eth_dev_release_dev_data, because in the above function rte_eth_dev_detach_vdev (1.1) for e.g pcap is call rte_free(eth_dev->data) which removes me a pointer to the name (rte_eth_pcap.c, line 1079). rte_eth_dev_detach (uint8_t port_id, char *name){ ... (1) rte_eth_dev_release_dev_data(port_id); if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) { ret = rte_eth_dev_get_addr_by_port(port_id, &addr); if (ret < 0) goto err; ret = rte_eth_dev_detach_pdev(port_id, &addr); if (ret < 0) goto err; snprintf(name, RTE_ETH_NAME_MAX_LEN, "%04x:%02x:%02x.%d", addr.domain, addr.bus, addr.devid, addr.function); } else { (1.1) ret = rte_eth_dev_detach_vdev(port_id, name); if (ret < 0) goto err; } (2) rte_eth_dev_release_dev_data(port_id); ... } This is reason why I keep name at the beginning but I release the name at the end function after detach. At this point I do not see how the code directly replace by one function call. Regards, Marcin > > Thanks, > Reshma