From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wg0-f46.google.com (mail-wg0-f46.google.com [74.125.82.46]) by dpdk.org (Postfix) with ESMTP id 6E8D9C36E for ; Thu, 9 Jul 2015 11:19:48 +0200 (CEST) Received: by wgov12 with SMTP id v12so33237951wgo.1 for ; Thu, 09 Jul 2015 02:19:48 -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=/N9U3Nx4eDaH2wUnWMVwstvYpwdl0ZOCooNs58H85oA=; b=jnO/EwCMUBqDIgmSJJqGUnbOJfsQpIzBep4eSaU/2Qr9nebVQCZP4DFZ7X+xxIc+xy ZlHyBXxJhPiy5oT73e72J3WONxod9irZ8D8ufkx5uH+IxLtzDMXQm/h4QHxahaFyPPCY Fm28bXRlMi3HJk5fckkouExsI7fz0ziZRiSIm+ytb1DutteAth4dI0TzZ7XKOepYqUlS 45y5JGRKX4XUD7swHaHaE79yPhFsk+I+Blweb9uivsrvs6/CpjkvBaO6CtmKCMsPVpyd 40gSl1C+AXrcI6+zsKrJ81UP+paJ8wHZEJ5jlRCL7MrqabFelY8XmyzYQ01aw1m0A5kx EFUA== X-Gm-Message-State: ALoCoQkIwRt/jmGLJkCOfj/LdvS+gdVKEdbdYtGg2NoVDIHeqNfNqXEjMIRiY0maaAjFPAWzVw1R X-Received: by 10.180.149.206 with SMTP id uc14mr40953086wib.12.1436433588332; Thu, 09 Jul 2015 02:19:48 -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.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Jul 2015 02:19:47 -0700 (PDT) From: David Marchand To: dev@dpdk.org Date: Thu, 9 Jul 2015 11:19:24 +0200 Message-Id: <1436433566-328-5-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 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: Thu, 09 Jul 2015 09:19:48 -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 Acked-by: Sergio Gonzalez Monroy --- 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 e676a31..d602350 100644 --- a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c +++ b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c @@ -287,12 +287,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); @@ -306,21 +307,20 @@ eal_hugepage_info_init(void) 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 { + 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 */ @@ -333,11 +333,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