From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Marchand Subject: [PATCH 4/6] eal/linux: rework while loop Date: Tue, 7 Jul 2015 11:00:32 +0200 Message-ID: <1436259634-7077-5-git-send-email-david.marchand@6wind.com> References: <1436259634-7077-1-git-send-email-david.marchand@6wind.com> To: dev@dpdk.org Return-path: Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com [209.85.212.181]) by dpdk.org (Postfix) with ESMTP id 52E6C5A52 for ; Tue, 7 Jul 2015 11:00:52 +0200 (CEST) Received: by widjy10 with SMTP id jy10so182355928wid.1 for ; Tue, 07 Jul 2015 02:00:52 -0700 (PDT) Received: from alcyon.dev.6wind.com (6wind.net2.nerim.net. [213.41.151.210]) by mx.google.com with ESMTPSA id y19sm32737674wia.15.2015.07.07.02.00.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Jul 2015 02:00:51 -0700 (PDT) In-Reply-To: <1436259634-7077-1-git-send-email-david.marchand@6wind.com> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Replace this while loop with a for loop and simplify error handling. Indent is broken on purpose, fixed in next commit. Signed-off-by: David Marchand --- lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 28 ++++++++++++----------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c index b474159..de3f48d 100644 --- a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c +++ b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c @@ -282,12 +282,13 @@ eal_hugepage_info_init(void) rte_panic("Cannot open directory %s to read system hugepage " "info\n", sys_dir_path); - dirent = readdir(dir); - while (dirent != NULL) { + for (dirent = readdir(dir); dirent != NULL; dirent = readdir(dir)) { struct hugepage_info *hpi; if (strncmp(dirent->d_name, dirent_start_text, - dirent_start_len) == 0) { + dirent_start_len) != 0) + continue; + hpi = &internal_config.hugepage_info[num_sizes]; hpi->hugepage_sz = rte_str_to_size(&dirent->d_name[dirent_start_len]); hpi->hugedir = get_hugepage_dir(hpi->hugepage_sz); @@ -301,21 +302,20 @@ eal_hugepage_info_init(void) 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 { + continue; + } + /* try to obtain a writelock */ hpi->lock_descriptor = open(hpi->hugedir, O_RDONLY); /* if blocking lock failed */ if (flock(hpi->lock_descriptor, LOCK_EX) == -1) { RTE_LOG(CRIT, EAL, "Failed to lock hugepage directory!\n"); - closedir(dir); - return -1; + break; } /* clear out the hugepages dir from unused pages */ - if (clear_hugedir(hpi->hugedir) == -1) { - closedir(dir); - return -1; - } + if (clear_hugedir(hpi->hugedir) == -1) + break; /* for now, put all pages into socket 0, * later they will be sorted */ @@ -328,11 +328,13 @@ eal_hugepage_info_init(void) #endif num_sizes++; - } - } - dirent = readdir(dir); } closedir(dir); + + /* something went wrong, and we broke from the for loop above */ + if (dirent != NULL) + return -1; + internal_config.num_hugepage_sizes = num_sizes; /* sort the page directory entries by size, largest to smallest */ -- 1.7.10.4