From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: Re: [PATCH v4 1/8] net/mvneta: add neta PMD skeleton Date: Wed, 19 Sep 2018 09:28:09 -0700 Message-ID: <20180919092809.7ccde128@xeon-e3> References: <1535720386-18775-1-git-send-email-amo@semihalf.com> <1537369294-17099-1-git-send-email-amo@semihalf.com> <1537369294-17099-2-git-send-email-amo@semihalf.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: dev@dpdk.org, mw@semihalf.com, zr@semihalf.com, tdu@semihalf.com, nadavh@marvell.com To: Andrzej Ostruszka Return-path: Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by dpdk.org (Postfix) with ESMTP id 8E76F5F38 for ; Wed, 19 Sep 2018 18:28:20 +0200 (CEST) Received: by mail-pg1-f194.google.com with SMTP id t84-v6so2997202pgb.5 for ; Wed, 19 Sep 2018 09:28:20 -0700 (PDT) In-Reply-To: <1537369294-17099-2-git-send-email-amo@semihalf.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Wed, 19 Sep 2018 17:01:27 +0200 Andrzej Ostruszka 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. > +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. > + return ret; > +}