From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 6D62B1150 for ; Fri, 3 Feb 2017 14:53:11 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP; 03 Feb 2017 05:53:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,328,1477983600"; d="scan'208";a="1102612158" Received: from gklab-246-019.igk.intel.com (HELO intel.com) ([10.217.246.19]) by fmsmga001.fm.intel.com with SMTP; 03 Feb 2017 05:53:07 -0800 Received: by intel.com (sSMTP sendmail emulation); Fri, 03 Feb 2017 16:55:05 +0100 From: Slawomir Mrozowicz To: declan.doherty@intel.com Cc: dev@dpdk.org, Slawomir Mrozowicz Date: Fri, 3 Feb 2017 16:55:02 +0100 Message-Id: <1486137302-28074-1-git-send-email-slawomirx.mrozowicz@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1486113475-4622-1-git-send-email-slawomirx.mrozowicz@intel.com> References: <1486113475-4622-1-git-send-email-slawomirx.mrozowicz@intel.com> Subject: [dpdk-dev] [PATCH v2] cryptodev: fix segmentation fault 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: Fri, 03 Feb 2017 13:53:11 -0000 This patch fix problem in function rte_cryptodev_devices_get(). Program received signal SIGSEGV, Segmentation fault. It rework the function to use correct types and clean up visibility. It also fix Coverity ID 141073 Fixes: 38227c0e3ad2 ("cryptodev: retrieve device info") Signed-off-by: Slawomir Mrozowicz --- lib/librte_cryptodev/rte_cryptodev.c | 33 ++++++++++++++------------------- lib/librte_cryptodev/rte_cryptodev.h | 2 +- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c index e557e77..a64320e 100644 --- a/lib/librte_cryptodev/rte_cryptodev.c +++ b/lib/librte_cryptodev/rte_cryptodev.c @@ -482,34 +482,29 @@ rte_cryptodev_count_devtype(enum rte_cryptodev_type type) return dev_count; } -int +uint8_t rte_cryptodev_devices_get(const char *dev_name, uint8_t *devices, uint8_t nb_devices) { - uint8_t i, cmp, count = 0; - struct rte_cryptodev **devs = &rte_cryptodev_globals->devs; - struct rte_device *dev; - - for (i = 0; i < rte_cryptodev_globals->max_devs && count < nb_devices; - i++) { + uint8_t i, count = 0; + struct rte_cryptodev *devs = rte_cryptodev_globals->devs; + uint8_t max_devs = rte_cryptodev_globals->max_devs; - if ((*devs + i) - && (*devs + i)->attached == - RTE_CRYPTODEV_ATTACHED) { + for (i = 0; i < max_devs && count < nb_devices; i++) { - dev = (*devs + i)->device; + if (devs[i].attached == RTE_CRYPTODEV_ATTACHED) { + const struct rte_cryptodev_driver *drv = devs[i].driver; + int cmp; - if (dev) - cmp = strncmp(dev->driver->name, - dev_name, - strlen(dev_name)); + if (drv) + cmp = strncmp(drv->pci_drv.driver.name, + dev_name, strlen(dev_name)); else - cmp = strncmp((*devs + i)->data->name, - dev_name, - strlen(dev_name)); + cmp = strncmp(devs[i].data->name, + dev_name, strlen(dev_name)); if (cmp == 0) - devices[count++] = (*devs + i)->data->dev_id; + devices[count++] = devs[i].data->dev_id; } } diff --git a/lib/librte_cryptodev/rte_cryptodev.h b/lib/librte_cryptodev/rte_cryptodev.h index 37f08ae..82f3bc3 100644 --- a/lib/librte_cryptodev/rte_cryptodev.h +++ b/lib/librte_cryptodev/rte_cryptodev.h @@ -435,7 +435,7 @@ rte_cryptodev_count_devtype(enum rte_cryptodev_type type); * @return * Returns number of attached crypto device. */ -int +uint8_t rte_cryptodev_devices_get(const char *dev_name, uint8_t *devices, uint8_t nb_devices); /* -- 2.5.0