From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qc0-f177.google.com (mail-qc0-f177.google.com [209.85.216.177]) by dpdk.org (Postfix) with ESMTP id AC59CB38D for ; Thu, 11 Jun 2015 00:06:27 +0200 (CEST) Received: by qchs1 with SMTP id s1so1487854qch.2 for ; Wed, 10 Jun 2015 15:06:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rqAAZJLpf9C3bax53PLw+r+gXuslaJJTqJr/1ENDAIg=; b=KAqG6kMAFQYJmVDihkQD6nMeeHljstJDKcfRZqZ0JtPqF4aiPO+QrooRjR1U1kY6DL RbqbggxaRCZbovlyKEzS4XRsjm2pNOpwSexDRspdLq9T0jjsbYUEgqO6oe5cRBmzVmsb fYyQDQAhA121pwjYyzThAIR6QD81ugphmoHo1YhXpZHlAVjZVRXObES85IGUakscPe0c PA2rfGCz3LPhUxVDkOV2MGClZLnqU6KY5qNll972Tc8Cvx/PmMkUFwVqZ2cu0bM9Wb3H HqmIICRPWg3nYELR/hwaPoCXSN0pkfMEnXHG5k2xar/And7XoCGCQ6anhR2LeJBF2B09 MrkQ== X-Gm-Message-State: ALoCoQlvEfcr115Mu2KbaWYsntLqglNnjAn4FrhCokD4rsflHltLhSjrSeD5mJrf42Ni79poNisn X-Received: by 10.140.49.11 with SMTP id p11mr6994069qga.60.1433973987270; Wed, 10 Jun 2015 15:06:27 -0700 (PDT) Received: from urahara.home.lan (static-50-53-82-155.bvtn.or.frontiernet.net. [50.53.82.155]) by mx.google.com with ESMTPSA id g92sm4748995qgf.20.2015.06.10.15.06.25 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Jun 2015 15:06:26 -0700 (PDT) From: Stephen Hemminger To: declan.doherty@intel.com Date: Wed, 10 Jun 2015 15:06:25 -0700 Message-Id: <1433973985-17940-3-git-send-email-stephen@networkplumber.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1433973985-17940-1-git-send-email-stephen@networkplumber.org> References: <1433973985-17940-1-git-send-email-stephen@networkplumber.org> Cc: dev@dpdk.org, Stephen Hemminger Subject: [dpdk-dev] [PATCH 2/2] bonding: fix name and port validation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Jun 2015 22:06:28 -0000 From: Stephen Hemminger Cleanup the code in bonding that checks ports. * Use standard rte_eth_dev_is_valid_port * Change name of driver string to avoid variable namespace conflicts * Get rid of unnecessary string comparison stuff. A simple pointer check is enough here. * Get rid of unnecessary assignment of driver_name, it is already done by common code. * Don't generate unnecessary log messages on error. Signed-off-by: Stephen Hemminger --- drivers/net/bonding/rte_eth_bond_api.c | 47 ++++++------------------------ drivers/net/bonding/rte_eth_bond_pmd.c | 1 - drivers/net/bonding/rte_eth_bond_private.h | 4 +-- 3 files changed, 11 insertions(+), 41 deletions(-) diff --git a/drivers/net/bonding/rte_eth_bond_api.c b/drivers/net/bonding/rte_eth_bond_api.c index d4caa83..6d8597a 100644 --- a/drivers/net/bonding/rte_eth_bond_api.c +++ b/drivers/net/bonding/rte_eth_bond_api.c @@ -45,59 +45,30 @@ #define DEFAULT_POLLING_INTERVAL_10_MS (10) int -valid_bonded_ethdev(struct rte_eth_dev *eth_dev) +valid_bonded_ethdev(const struct rte_eth_dev *eth_dev) { - size_t len; - /* Check valid pointer */ - if (eth_dev->driver->pci_drv.name == NULL || driver_name == NULL) - return -1; - - /* Check string lengths are equal */ - len = strlen(driver_name); - if (strlen(eth_dev->driver->pci_drv.name) != len) - return -1; - - /* Compare strings */ - return strncmp(eth_dev->driver->pci_drv.name, driver_name, len); -} - -int -valid_port_id(uint8_t port_id) -{ - /* Verify that port id is valid */ - int ethdev_count = rte_eth_dev_count(); - if (port_id >= ethdev_count) { - RTE_BOND_LOG(ERR, "Port Id %d is greater than rte_eth_dev_count %d", - port_id, ethdev_count); + if (eth_dev->driver->pci_drv.name == NULL) return -1; - } - return 0; + /* return 0 if driver name matches */ + return eth_dev->driver->pci_drv.name != pmd_bond_driver_name; } int valid_bonded_port_id(uint8_t port_id) { - /* Verify that port id's are valid */ - if (valid_port_id(port_id)) + if (!rte_eth_dev_is_valid_port(port_id)) return -1; - /* Verify that bonded_port_id refers to a bonded port */ - if (valid_bonded_ethdev(&rte_eth_devices[port_id])) { - RTE_BOND_LOG(ERR, "Specified port Id %d is not a bonded eth_dev device", - port_id); - return -1; - } - - return 0; + return valid_bonded_ethdev(&rte_eth_devices[port_id]); } int valid_slave_port_id(uint8_t port_id) { /* Verify that port id's are valid */ - if (valid_port_id(port_id)) + if (!rte_eth_dev_is_valid_port(port_id)) return -1; /* Verify that port_id refers to a non bonded port */ @@ -192,7 +163,7 @@ number_of_sockets(void) return ++sockets; } -const char *driver_name = "Link Bonding PMD"; +const char *pmd_bond_driver_name = "Link Bonding PMD"; int rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id) @@ -259,7 +230,7 @@ rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id) } pci_dev->numa_node = socket_id; - pci_drv->name = driver_name; + pci_drv->name = pmd_bond_driver_name; eth_dev->driver = eth_drv; eth_dev->data->dev_private = internals; diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c index 8bad2e1..034e60b 100644 --- a/drivers/net/bonding/rte_eth_bond_pmd.c +++ b/drivers/net/bonding/rte_eth_bond_pmd.c @@ -1556,7 +1556,6 @@ bond_ethdev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) { struct bond_dev_private *internals = dev->data->dev_private; - dev_info->driver_name = driver_name; dev_info->max_mac_addrs = 1; dev_info->max_rx_pktlen = (uint32_t)2048; diff --git a/drivers/net/bonding/rte_eth_bond_private.h b/drivers/net/bonding/rte_eth_bond_private.h index 45e5c65..c531e87 100644 --- a/drivers/net/bonding/rte_eth_bond_private.h +++ b/drivers/net/bonding/rte_eth_bond_private.h @@ -62,7 +62,7 @@ extern const char *pmd_bond_init_valid_arguments[]; -extern const char *driver_name; +extern const char *pmd_bond_driver_name; /** Port Queue Mapping Structure */ struct bond_rx_queue { @@ -162,7 +162,7 @@ struct bond_dev_private { extern struct eth_dev_ops default_dev_ops; int -valid_bonded_ethdev(struct rte_eth_dev *eth_dev); +valid_bonded_ethdev(const struct rte_eth_dev *eth_dev); /* Search given slave array to find possition of given id. * Return slave pos or slaves_count if not found. */ -- 2.1.4