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 <david.marchand at 6wind.com> --- lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c index 6dd8a0b..0b6ece7 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 unsigned long get_num_hugepages(const char *subdir) { char path[PATH_MAX]; @@ -87,10 +87,12 @@ 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; + return num_pages; } static uint64_t @@ -288,12 +290,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); + unsigned long num_pages; + + num_pages = get_num_hugepages(dirent->d_name); + if (num_pages > 0) + RTE_LOG(INFO, EAL, "%lu hugepages of size %lu 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); -- 1.7.10.4