From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id BE97DA0547; Thu, 11 Feb 2021 23:05:57 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4150122A24E; Thu, 11 Feb 2021 23:05:57 +0100 (CET) Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by mails.dpdk.org (Postfix) with ESMTP id 2E07C40147 for ; Thu, 11 Feb 2021 23:05:56 +0100 (CET) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 00557A5C; Thu, 11 Feb 2021 17:05:54 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 11 Feb 2021 17:05:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=fm3; bh=MxwybTTx460oskCuSXkH1or1oJ OqjR3QUNUAXRyNA84=; b=s+WK8GKLqP+bTnCPSf1yxXrToKnouOHfQrx02t2O91 GkqPiAZNKNjM2pLoLp5QaHFLGiunxtEuzG35kdTcN51oDDL8kLFAuBgBh/2pxQmi UbAewS2XaJQbn3LNxXk1y2QfJCFCqjXnOwka51hBraZd8pwd0YjxoGBF+5d7bTGh AAUxuFMDm6U4LQ/0+i6y5RbImqY3Fm9fpWf7w6rsNmUZ+x/vJ5xEVwVwdXasMEtd R8pCcKgoQj0qpjjgCuLn270EEnFWStk1vn9zW47qbjAj+DOmEn8of7Cw3xmOm1n3 MLSfN56ZpXiiVdMVuldlJaJVpADmrjNOQh4Nb6iy1/0g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=MxwybTTx460oskCuS XkH1or1oJOqjR3QUNUAXRyNA84=; b=f2/mhwezJ9K8KfBI9qbcnGCVeJGCrUQSi Ijgko3qbfqGDv1hfc7WqVfEcXlp0UkmDQ58iCCUkI2ztkQIEnNmteb0vqz3oC4aD ie3EOuShGJFRewkJZWek7oDw4WpclV0Vqp+IVY+CUpyt+YYIa9vK2FsGOHq3R6hU 1hI1wDr+vE9z1ReNVDnFsxC/7MYPZ+ZuYekjJA6hI3xgbVoqg69F0LDEpPzLxPpb XaAdG7qY01AyzGyCbT/QIsBxs7xc0qcN+ln3CNd/LkQog3xrFNzs+DEaNl8B7fnB PcZfxq+ozgZsB9c9KC4DUpdkBBTiQ9fJWC5MLeZEeaRvkvRNhq56Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrheelgdduheeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgggfestdekredtre dttdenucfhrhhomhepvfhhohhmrghsucfoohhnjhgrlhhonhcuoehthhhomhgrshesmhho nhhjrghlohhnrdhnvghtqeenucggtffrrghtthgvrhhnpedvledvudehvdduudevuedvve ehgeduleegiefgjeehudehtddtgeduffejiefhgfenucfkphepjeejrddufeegrddvtdef rddukeegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epthhhohhmrghssehmohhnjhgrlhhonhdrnhgvth X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id A0BC324005E; Thu, 11 Feb 2021 17:05:53 -0500 (EST) From: Thomas Monjalon To: dev@dpdk.org Cc: sarosh.arif@emumba.com, stephen@networkplumber.org Date: Thu, 11 Feb 2021 23:05:44 +0100 Message-Id: <20210211220544.55439-1-thomas@monjalon.net> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] usertools: check 0-division with hugepage size X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The default page size can be None, and the page size from user request can be 0 kB if lower than 1024. In these cases, a division will fail. In order to avoid a Python exception, the page size is checked and an error message "Invalid page size" is printed. A similar error message is printed in set_hugepages() if the size is not supported, except at this stage the message can be completed with "Valid page sizes". Unfortunately the first check is too early to print such information. A third error message can be printed in a different place (get_memsize) in case of a format issue, e.g. a negative size. The function get_memsize() is also used for total requested size, so the error message "not a valid page size" was potentially wrong. This message is replaced with the more general "is not a valid size". Signed-off-by: Thomas Monjalon --- usertools/dpdk-hugepages.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/usertools/dpdk-hugepages.py b/usertools/dpdk-hugepages.py index fb368b6933..c1f2549ec0 100755 --- a/usertools/dpdk-hugepages.py +++ b/usertools/dpdk-hugepages.py @@ -29,7 +29,7 @@ def get_memsize(arg): '''Convert memory size with suffix to kB''' match = re.match(r'(\d+)([' + BINARY_PREFIX + r']?)$', arg.upper()) if match is None: - sys.exit('{} is not a valid page size'.format(arg)) + sys.exit('{} is not a valid size'.format(arg)) num = float(match.group(1)) suffix = match.group(2) if suffix == "": @@ -254,6 +254,8 @@ def main(): pagesize_kb = get_memsize(args.pagesize) else: pagesize_kb = default_pagesize() + if pagesize_kb is None or pagesize_kb == 0: + sys.exit("Invalid page size: {}kB".format(pagesize_kb)) if args.clear: clear_pages() -- 2.30.0