From: David Marchand Date: Thu, 9 Jul 2015 09:19:22 +0000 (+0200) Subject: eal/linux: remove useless casts in hugepage init X-Git-Tag: spdx-start~8833 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=7392dde0cc9d40022bc5cf1098f2579dc3c0ca80;p=dpdk.git eal/linux: remove useless casts in hugepage init Rather than cast the huge pages number returned by get_num_hugepages, rework this function so that it returns 0 when something goes wrong. And no need for casts in log. Signed-off-by: David Marchand Acked-by: Sergio Gonzalez Monroy --- diff --git a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c index 6dd8a0b056..91e288c79e 100644 --- a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c +++ b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c @@ -63,7 +63,7 @@ static const char sys_dir_path[] = "/sys/kernel/mm/hugepages"; /* this function is only called from eal_hugepage_info_init which itself * is only called from a primary process */ -static int32_t +static uint32_t get_num_hugepages(const char *subdir) { char path[PATH_MAX]; @@ -87,10 +87,17 @@ get_num_hugepages(const char *subdir) subdir); /* adjust num_pages */ - if (num_pages > 0) + if (num_pages >= resv_pages) num_pages -= resv_pages; + else if (resv_pages) + num_pages = 0; - return (int32_t)num_pages; + /* we want to return a uint32_t and more than this looks suspicious + * anyway ... */ + if (num_pages > UINT32_MAX) + num_pages = UINT32_MAX; + + return num_pages; } static uint64_t @@ -288,12 +295,13 @@ eal_hugepage_info_init(void) /* first, check if we have a mountpoint */ if (hpi->hugedir == NULL){ - int32_t num_pages; - if ((num_pages = get_num_hugepages(dirent->d_name)) > 0) - RTE_LOG(INFO, EAL, "%u hugepages of size %llu reserved, "\ - "but no mounted hugetlbfs found for that size\n", - (unsigned)num_pages, - (unsigned long long)hpi->hugepage_sz); + uint32_t num_pages; + + num_pages = get_num_hugepages(dirent->d_name); + if (num_pages > 0) + RTE_LOG(INFO, EAL, "%" PRIu32 " hugepages of size %" PRIu64 " reserved, " + "but no mounted hugetlbfs found for that size\n", + num_pages, hpi->hugepage_sz); } else { /* try to obtain a writelock */ hpi->lock_descriptor = open(hpi->hugedir, O_RDONLY);