From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com [209.85.212.177]) by dpdk.org (Postfix) with ESMTP id 899D9C344 for ; Thu, 9 Jul 2015 11:19:45 +0200 (CEST) Received: by widjy10 with SMTP id jy10so239200866wid.1 for ; Thu, 09 Jul 2015 02:19:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=m8iyycUNf0MwmqDl5H9qWjhb8y4sqB263BNCfUR9zn0=; b=Zy1yuzw6eQS1h7ji9uEAFMd717LFqODLbafgROV+1ANCRpAS+U5bTG+pnIEhCZSmWG 0AHgXRCdbVSfCoYPfznWKX/ZC4WuH5c3//C16Ez7WA7rPREABgqBB+V68pEnh9eq/GU/ s/9IxaiY4wR1322wpNkGeBsuKURmFQYOC76o0hu1ivACTJsDYV6YuOIQlVMBeVy5hLga kYOwvoX/Rez5rHbjjtmmWVEeeU0Z2suQIXWKFFir/gY6FwKP8GswQzAMise/MDrBXYhS JwSPL8WAUDtcvu5BhRDcRXy+f+api3QVknI+HhzVPs0cXWMXRO+ZQNCvEyZykLVVghYy CrIQ== X-Gm-Message-State: ALoCoQki94r+87GKQuloKn7WJATTHr3ankByEyYp7knp2exM0pb+zRUXyO6KhipSHlQ3sE5rANrb X-Received: by 10.194.201.71 with SMTP id jy7mr29283877wjc.93.1436433585412; Thu, 09 Jul 2015 02:19:45 -0700 (PDT) Received: from alcyon.dev.6wind.com (6wind.net2.nerim.net. [213.41.151.210]) by smtp.gmail.com with ESMTPSA id um5sm7774777wjc.1.2015.07.09.02.19.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Jul 2015 02:19:44 -0700 (PDT) From: David Marchand To: dev@dpdk.org Date: Thu, 9 Jul 2015 11:19:22 +0200 Message-Id: <1436433566-328-3-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1436433566-328-1-git-send-email-david.marchand@6wind.com> References: <1436259634-7077-1-git-send-email-david.marchand@6wind.com> <1436433566-328-1-git-send-email-david.marchand@6wind.com> Subject: [dpdk-dev] [PATCH v2 2/6] eal/linux: remove useless casts 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: Thu, 09 Jul 2015 09:19:45 -0000 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 --- lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 26 +++++++++++++++-------- 1 file changed, 17 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..91e288c 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); -- 1.7.10.4