From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f170.google.com (mail-pf0-f170.google.com [209.85.192.170]) by dpdk.org (Postfix) with ESMTP id 86B262C58 for ; Tue, 10 Jan 2017 00:30:32 +0100 (CET) Received: by mail-pf0-f170.google.com with SMTP id 127so35401216pfg.1 for ; Mon, 09 Jan 2017 15:30:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ll5hobA9YlVZ+2TnLuNUJ+6wePQoasNE6xL56Vqs12Q=; b=cmR8+ArkmLWeYNKLzEAI6RI1liy/Mj53DoYJIJwig3hNYLBxVo9ocALz2bWdh5nbTL U0ZR0QYt9geYp/i+I1sZ2FB5lFZvFo50uyEJ50lekKue8lO5xUIH6Je+pGWA13pC9AXA tgQVX8f4uaZL0E5IrQmIJ+9/d4CImL9+vTg/uWHw2Y0jXK6ZvrP7UxIBgq9aiWFd4RPi 1CD/x9Wh7z+9TGOJujiRFiv5cJ9EyKeH8UTYsVGUkPcn6CSvOI0T8isYaSRocExtzccc FO+IkbmQym6XsUO2MytU44zC3U7Vti15qq1GXy9XHQ8B+wmbcoycWjm+ggj0JeXGOT0I l/pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ll5hobA9YlVZ+2TnLuNUJ+6wePQoasNE6xL56Vqs12Q=; b=tBauq9BYtxI6vuwhdCA8ohf032/Pe6S/KPVlkB9ussqUV84aBLRdz/PBrWrDK61xTY QacKbKt8TAsqxxIYKQ33vrvT38ADNs0Js3jfWXIAqHk0Tay1uAXKwDEblNd0q0PIGevQ 8LFV5XOak/rWMT2tqki6wF02Cw8vpGgwtME5e6Caa+LWEKsfxs5BdPm7Fc7x0KF1yihg qjiE5OkB8CPYEqJfyd88+oXOOKAd+Pvw/Jd8Pt74zS/4/NZHWGm9sV9xMrDCqST8Ava8 SWCCSwF284HSSiR8HyhaZPIU0CoL/ItdufOWRWC+Kwl35KD4D3//g+f8L3Fy948JyoVW F3cA== X-Gm-Message-State: AIkVDXI8IdYXCOpq1/RNDaXhgxZS10XEPCscWqBaQGhIIMSQ/MY2mP6qSqo2waEvGaUWeg== X-Received: by 10.99.199.69 with SMTP id v5mr306269pgg.90.1484004631769; Mon, 09 Jan 2017 15:30:31 -0800 (PST) Received: from xeon-e3.wavecable.com (204-195-18-65.wavecable.com. [204.195.18.65]) by smtp.gmail.com with ESMTPSA id s78sm12658pfk.82.2017.01.09.15.30.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Jan 2017 15:30:30 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Mon, 9 Jan 2017 15:30:17 -0800 Message-Id: <20170109233022.31154-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170109233022.31154-1-stephen@networkplumber.org> References: <20170109233022.31154-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH 2/7] ethdev: reduce goto's in attach/detach X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Jan 2017 23:30:32 -0000 Extra goto's to just a return are unnecessary. Don't do unnecessary initialization. Propgate return value. Signed-off-by: Stephen Hemminger --- lib/librte_ether/rte_ethdev.c | 52 +++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 9dea1f15..2bd7db6d 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -419,18 +419,17 @@ rte_eth_dev_is_detachable(uint8_t port_id) int rte_eth_dev_attach(const char *devargs, uint8_t *port_id) { - int ret = -1; int current = rte_eth_dev_count(); char *name = NULL; char *args = NULL; + int ret; - if ((devargs == NULL) || (port_id == NULL)) { - ret = -EINVAL; - goto err; - } + if (devargs == NULL || port_id == NULL) + return -EINVAL; /* parse devargs, then retrieve device name and args */ - if (rte_eal_parse_devargs_str(devargs, &name, &args)) + ret = rte_eal_parse_devargs_str(devargs, &name, &args); + if (ret < 0) goto err; ret = rte_eal_dev_attach(name, args); @@ -441,20 +440,18 @@ rte_eth_dev_attach(const char *devargs, uint8_t *port_id) if (!rte_eth_dev_count()) { RTE_LOG(ERR, EAL, "No port found for device (%s)\n", name); ret = -1; - goto err; - } - - /* if nothing happened, there is a bug here, since some driver told us - * it did attach a device, but did not create a port. - */ - if (current == rte_eth_dev_count()) { + } else if (current == rte_eth_dev_count()) { + /* + * if nothing happened, there is a bug here, since + * some driver told us it did attach a device, but did + * not create a port. + */ ret = -1; - goto err; + } else { + *port_id = eth_dev_last_created_port; + ret = 0; } - *port_id = eth_dev_last_created_port; - ret = 0; - err: free(name); free(args); @@ -465,27 +462,20 @@ rte_eth_dev_attach(const char *devargs, uint8_t *port_id) int rte_eth_dev_detach(uint8_t port_id, char *name) { - int ret = -1; + int ret; - if (name == NULL) { - ret = -EINVAL; - goto err; - } + if (name == NULL) + return -EINVAL; /* FIXME: move this to eal, once device flags are relocated there */ - if (rte_eth_dev_is_detachable(port_id)) - goto err; + ret = rte_eth_dev_is_detachable(port_id); + if (ret < 0) + return ret; snprintf(name, sizeof(rte_eth_devices[port_id].data->name), "%s", rte_eth_devices[port_id].data->name); - ret = rte_eal_dev_detach(name); - if (ret < 0) - goto err; - return 0; - -err: - return ret; + return rte_eal_dev_detach(name); } static int -- 2.11.0