[dpdk-dev] [PATCH v4 1/8] net/mvneta: add neta PMD skeleton

Andrzej Ostruszka amo at semihalf.com
Thu Sep 20 09:57:57 CEST 2018


On 19.09.2018 18:28, Stephen Hemminger wrote:
> On Wed, 19 Sep 2018 17:01:27 +0200
> Andrzej Ostruszka <amo at semihalf.com> wrote:
> 
>> +/**
>> + * Create private device structure.
>> + *
>> + * @param dev_name
>> + *   Pointer to the port name passed in the initialization parameters.
>> + *
>> + * @return
>> + *   Pointer to the newly allocated private device structure.
>> + */
>> +static struct mvneta_priv *
>> +mvneta_priv_create(const char *dev_name)
>> +{
>> +	struct mvneta_priv *priv;
>> +
>> +	priv = rte_zmalloc_socket(dev_name, sizeof(*priv), 0, rte_socket_id());
>> +	if (!priv)
>> +		return NULL;
>> +
>> +	return priv;
>> +}
> 
> Why make this a function, it really doesn't add anything over just doing it inline.

True.  Removed it.

>> +static int
>> +mvneta_eth_dev_create(struct rte_vdev_device *vdev, const char *name)
>> +{
>> +	int ret, fd = socket(AF_INET, SOCK_DGRAM, 0);
>> +	struct rte_eth_dev *eth_dev;
>> +	struct mvneta_priv *priv;
>> +	struct ifreq req;
>> +
>> +	eth_dev = rte_eth_dev_allocate(name);
>> +	if (!eth_dev)
>> +		return -ENOMEM;
>> +
>> +	priv = mvneta_priv_create(name);
>> +
>> +	if (!priv) {
> 
> nit: no blank line needed.
> 
>> +		ret = -ENOMEM;
>> +		goto out_free_dev;
> 
> You have error goto's backwards.
> 
>> +	}
>> +
>> +	eth_dev->data->mac_addrs =
>> +		rte_zmalloc("mac_addrs",
>> +			    ETHER_ADDR_LEN * MVNETA_MAC_ADDRS_MAX, 0);
>> +	if (!eth_dev->data->mac_addrs) {
>> +		MVNETA_LOG(ERR, "Failed to allocate space for eth addrs");
>> +		ret = -ENOMEM;
>> +		goto out_free_priv;
>> +	}
>> +
>> +	memset(&req, 0, sizeof(req));
>> +	strcpy(req.ifr_name, name);
> 
> 
> 
>> +out_free_mac:
>> +	rte_free(eth_dev->data->mac_addrs);
>> +out_free_dev:
>> +	rte_eth_dev_release_port(eth_dev);
>> +out_free_priv:
>> +	rte_free(priv);
> 
> These are backwards: out_free_priv is called if ioctl fails and will
> leak eth_dev port.

Good catch - 'out_free_priv' should go before 'out_free_dev'!  Thank
you.  The problem is not for the case of ioctl failure but I guess that
is just a wording lapsus.

Best regards
Andrzej


More information about the dev mailing list