From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [143.182.124.21]) by dpdk.org (Postfix) with ESMTP id DEC2DB0BD for ; Fri, 13 Jun 2014 16:52:44 +0200 (CEST) Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga101.ch.intel.com with ESMTP; 13 Jun 2014 07:52:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,471,1400050800"; d="scan'208";a="445224072" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by azsmga001.ch.intel.com with ESMTP; 13 Jun 2014 07:52:57 -0700 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id s5DEquAj004310; Fri, 13 Jun 2014 15:52:56 +0100 Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id s5DEquMH017179; Fri, 13 Jun 2014 15:52:56 +0100 Received: (from aburakov@localhost) by sivswdev02.ir.intel.com with id s5DEqutP017175; Fri, 13 Jun 2014 15:52:56 +0100 From: Anatoly Burakov To: dev@dpdk.org Date: Fri, 13 Jun 2014 15:52:37 +0100 Message-Id: <9537360ee1d9b2efeaa04fb00338b0263bf5755b.1402670566.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v6 03/20] pci: fixing errors in a previous commit found by checkpatch 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: Fri, 13 Jun 2014 14:52:45 -0000 --- lib/librte_eal/linuxapp/eal/eal_pci.c | 2 +- lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 112 +++++++++++---------- lib/librte_eal/linuxapp/eal/include/eal_pci_init.h | 2 +- 3 files changed, 63 insertions(+), 53 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index a422e5f..2066608 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -99,7 +99,7 @@ error: /* map a particular resource from a file */ void * -pci_map_resource(void * requested_addr, int fd, off_t offset, size_t size) +pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size) { void *mapaddr; diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c index c9a12a1..7c75593 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c @@ -74,7 +74,7 @@ pci_uio_get_mappings(const char *devname, struct pci_map maps[], int nb_maps) RTE_LOG(ERR, EAL, "%s(): cannot parse offset of %s\n", __func__, dirname); - return (-1); + return -1; } /* get mapping size */ @@ -84,7 +84,7 @@ pci_uio_get_mappings(const char *devname, struct pci_map maps[], int nb_maps) RTE_LOG(ERR, EAL, "%s(): cannot parse size of %s\n", __func__, dirname); - return (-1); + return -1; } /* get mapping physical address */ @@ -94,20 +94,21 @@ pci_uio_get_mappings(const char *devname, struct pci_map maps[], int nb_maps) RTE_LOG(ERR, EAL, "%s(): cannot parse addr of %s\n", __func__, dirname); - return (-1); + return -1; } if ((offset > OFF_MAX) || (size > SIZE_MAX)) { RTE_LOG(ERR, EAL, "%s(): offset/size exceed system max value\n", __func__); - return (-1); + return -1; } maps[i].offset = offset; maps[i].size = size; - } - return (i); + } + + return i; } static int @@ -140,12 +141,12 @@ pci_uio_map_secondary(struct rte_pci_device *dev) RTE_LOG(ERR, EAL, "Cannot mmap device resource\n"); close(fd); - return (-1); + return -1; } /* fd is not needed in slave process, close it */ close(fd); } - return (0); + return 0; } RTE_LOG(ERR, EAL, "Cannot find resource for device\n"); @@ -214,15 +215,15 @@ pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf, * or uio:uioX */ rte_snprintf(dirname, sizeof(dirname), - SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/uio", - loc->domain, loc->bus, loc->devid, loc->function); + SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/uio", + loc->domain, loc->bus, loc->devid, loc->function); dir = opendir(dirname); if (dir == NULL) { /* retry with the parent directory */ rte_snprintf(dirname, sizeof(dirname), - SYSFS_PCI_DEVICES "/" PCI_PRI_FMT, - loc->domain, loc->bus, loc->devid, loc->function); + SYSFS_PCI_DEVICES "/" PCI_PRI_FMT, + loc->domain, loc->bus, loc->devid, loc->function); dir = opendir(dirname); if (dir == NULL) { @@ -265,7 +266,8 @@ pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf, return -1; /* create uio device if we've been asked to */ - if (internal_config.create_uio_dev && pci_mknod_uio_dev(dstbuf, uio_num) < 0) + if (internal_config.create_uio_dev && + pci_mknod_uio_dev(dstbuf, uio_num) < 0) RTE_LOG(WARNING, EAL, "Cannot create /dev/uio%u\n", uio_num); return uio_num; @@ -293,7 +295,7 @@ pci_uio_map_resource(struct rte_pci_device *dev) /* secondary processes - use already recorded details */ if (rte_eal_process_type() != RTE_PROC_PRIMARY) - return (pci_uio_map_secondary(dev)); + return pci_uio_map_secondary(dev); /* find uio resource */ uio_num = pci_get_uio_dev(dev, dirname, sizeof(dirname)); @@ -314,10 +316,11 @@ pci_uio_map_resource(struct rte_pci_device *dev) dev->intr_handle.type = RTE_INTR_HANDLE_UIO; /* allocate the mapping details for secondary processes*/ - if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) { + uio_res = rte_zmalloc("UIO_RES", sizeof(*uio_res), 0); + if (uio_res == NULL) { RTE_LOG(ERR, EAL, "%s(): cannot store uio mmap details\n", __func__); - return (-1); + return -1; } rte_snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname); @@ -328,7 +331,7 @@ pci_uio_map_resource(struct rte_pci_device *dev) RTE_DIM(uio_res->maps)); if (nb_maps < 0) { rte_free(uio_res); - return (nb_maps); + return nb_maps; } uio_res->nb_maps = nb_maps; @@ -341,7 +344,8 @@ pci_uio_map_resource(struct rte_pci_device *dev) int fd; /* skip empty BAR */ - if ((phaddr = dev->mem_resource[i].phys_addr) == 0) + phaddr = dev->mem_resource[i].phys_addr; + if (phaddr == 0) continue; for (j = 0; j != nb_maps && (phaddr != maps[j].phaddr || @@ -351,6 +355,7 @@ pci_uio_map_resource(struct rte_pci_device *dev) /* if matching map is found, then use it */ if (j != nb_maps) { + int fail = 0; offset = j * pagesz; /* @@ -363,14 +368,19 @@ pci_uio_map_resource(struct rte_pci_device *dev) return -1; } - if (maps[j].addr != NULL || - (mapaddr = pci_map_resource(NULL, fd, - (off_t)offset, - (size_t)maps[j].size) - ) == NULL) { + if (maps[j].addr != NULL) + fail = 1; + else { + mapaddr = pci_map_resource(NULL, fd, (off_t)offset, + (size_t)maps[j].size); + if (mapaddr == NULL) + fail = 1; + } + + if (fail) { rte_free(uio_res); close(fd); - return (-1); + return -1; } close(fd); @@ -382,7 +392,7 @@ pci_uio_map_resource(struct rte_pci_device *dev) TAILQ_INSERT_TAIL(pci_res_list, uio_res, next); - return (0); + return 0; } /* @@ -392,30 +402,30 @@ pci_uio_map_resource(struct rte_pci_device *dev) static int pci_parse_sysfs_value(const char *filename, uint64_t *val) { - FILE *f; - char buf[BUFSIZ]; - char *end = NULL; - - f = fopen(filename, "r"); - if (f == NULL) { - RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n", - __func__, filename); - return -1; - } - - if (fgets(buf, sizeof(buf), f) == NULL) { - RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n", - __func__, filename); - fclose(f); - return -1; - } - *val = strtoull(buf, &end, 0); - if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) { - RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n", - __func__, filename); - fclose(f); - return -1; - } - fclose(f); - return 0; + FILE *f; + char buf[BUFSIZ]; + char *end = NULL; + + f = fopen(filename, "r"); + if (f == NULL) { + RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n", + __func__, filename); + return -1; + } + + if (fgets(buf, sizeof(buf), f) == NULL) { + RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n", + __func__, filename); + fclose(f); + return -1; + } + *val = strtoull(buf, &end, 0); + if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) { + RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n", + __func__, filename); + fclose(f); + return -1; + } + fclose(f); + return 0; } diff --git a/lib/librte_eal/linuxapp/eal/include/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/include/eal_pci_init.h index 1292eda..87bdfe7 100644 --- a/lib/librte_eal/linuxapp/eal/include/eal_pci_init.h +++ b/lib/librte_eal/linuxapp/eal/include/eal_pci_init.h @@ -57,7 +57,7 @@ struct mapped_pci_resource { TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource); extern struct mapped_pci_res_list *pci_res_list; -void * pci_map_resource(void * requested_addr, int fd, off_t offset, +void *pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size); /* map IGB_UIO resource prototype */ -- 1.8.1.4