From mboxrd@z Thu Jan 1 00:00:00 1970 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) 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=d3roc7k7Id2GWK8K/zJIUIsdfoUuuAS737BMaj4D/vI=; b=LKlSUT3zBVppHJn1RkVAiwfdsQqUkyNO9SzI9Us9jOOD4OUtNhShJGp+Opokbevu30 sbsVlxpfD6eDL+on5kCltmi67chY1ztqs3nrW0FWxFdLpWsOFPjqU2tH1WWA1CXoZVej fKjvkFZgV6C29Df8TuT2X1yjbXBVA92wSirZoHMCxJIL8spKEvwHOUofweuwAZeiKGE7 0xtGSHcWjKswhBE/eqYMgb0KNk8/bQXiNaylMVC+HtpsKQc2Axd+O4jFyUk2T//SldtE sXUC0I5t4IyvfqNl7i4BdRfzg+spR8oxgjoVxDSZHUisixd2Sl3qDOHUfWRTs7F2mMr2 8uFQ== X-Gm-Message-State: ALoCoQl0a1dkrPzapwnSXAk5PBgEgMI3tq+0ZBYoau5KgmutrAQTH1OcVArZQpWdOvw2tyrwNVQ+ X-Received: by 10.194.203.3 with SMTP id km3mr5977098wjc.114.1436259652176; 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) From: David Marchand To: dev@dpdk.org Date: Tue, 7 Jul 2015 11:00:32 +0200 Message-Id: <1436259634-7077-5-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1436259634-7077-1-git-send-email-david.marchand@6wind.com> References: <1436259634-7077-1-git-send-email-david.marchand@6wind.com> Subject: [dpdk-dev] [PATCH 4/6] eal/linux: rework while loop 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: Tue, 07 Jul 2015 09:00:52 -0000 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