From patchwork Tue Feb 27 08:58:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mohammad Abdul Awal X-Patchwork-Id: 35436 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A3BBB4C9D; Tue, 27 Feb 2018 09:58:41 +0100 (CET) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id D49A94C97 for ; Tue, 27 Feb 2018 09:58:40 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Feb 2018 00:58:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,400,1515484800"; d="scan'208";a="30043696" Received: from awal-z170x.ir.intel.com ([163.33.210.59]) by FMSMGA003.fm.intel.com with ESMTP; 27 Feb 2018 00:58:36 -0800 From: Mohammad Abdul Awal To: thomas@monjalon.net Cc: rkerur@gmail.com, dev@dpdk.org, konstantin.ananyev@intel.com, Mohammad Abdul Awal Date: Tue, 27 Feb 2018 08:58:27 +0000 Message-Id: <1519721907-25198-1-git-send-email-mohammad.abdul.awal@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-dev] [PATCH v2] ether: fix invalid string length in ethdev name comparison 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The current code compares two strings upto the length of 1st string (searched name). If the 1st string is prefix of 2nd string (existing name), the string comparison returns the port_id of earliest prefix matches. This patch fixes the bug by using strcmp instead of strncmp. Fixes: 9c5b8d8b9fe ("ethdev: clean port id retrieval when attaching") Signed-off-by: Mohammad Abdul Awal Acked-by: Konstantin Ananyev --- lib/librte_ether/rte_ethdev.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 0590f0c..3b885a6 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -572,8 +572,7 @@ rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id) for (pid = 0; pid < RTE_MAX_ETHPORTS; pid++) { if (rte_eth_devices[pid].state != RTE_ETH_DEV_UNUSED && - !strncmp(name, rte_eth_dev_shared_data->data[pid].name, - strlen(name))) { + !strcmp(name, rte_eth_dev_shared_data->data[pid].name)) { *port_id = pid; return 0; }