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 C07B3A034F; Sun, 21 Mar 2021 10:09:14 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A872340042; Sun, 21 Mar 2021 10:09:14 +0100 (CET) Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) by mails.dpdk.org (Postfix) with ESMTP id 1D5AD40041 for ; Sun, 21 Mar 2021 10:09:12 +0100 (CET) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 0861E15BC; Sun, 21 Mar 2021 05:09:10 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Sun, 21 Mar 2021 05:09:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=cTFdjN2q16fMh 4fqz2xQzH2H8Rwi6Z3SMR81cEX6PNc=; b=WNSyVUAZOowdB275MLspLRAwOPSPB geyDTuyxeFMwm7Q5Q6yIcsfSnXHjMNfttobllbFAa79MrvZqeE3jCQDWqZDjjqdJ l2cwQAEDpfOsWHgYHx6HObrPaNNaOIjeH91Yz46zGqmfIn+5F1rqGgngp7BhB+5b xyR0QCSO3LOVOvZIqlcpQmfuxeq0zyzk5O9QpNLwRACi4s/AQYlAfuxBTXh+4cNo Oobe6g3O6GhtekZWVwi2Sp5mPyUMdFEmFBzXBYgm1g/+pnMY4CTIt22+4ZmvkHcp BiYybE+3SJ3TIOb/KBYlfnrtDN01cHDv3wyzJCTrpZZiKBd9l5RpGdIBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=cTFdjN2q16fMh4fqz2xQzH2H8Rwi6Z3SMR81cEX6PNc=; b=Xdm/Gdnz SZdnxqxa8ON1hhVc1x4drWmNXS1QbDeldK7zeHCq/Ug5xBFKdSHNc6fUibZDRnAe 5is2rwpWJCtFbeqKKdWYT000ZBQQest4FDVo16MGwKNt6CHW6l5ky8vZsitJWsr+ 21tQ0+bjaYwQptIGkUwWCbhjDBQxKn3Bbyx9xluGgvHnCW2fW0XRorqWhp5/cA3H oBOIqS/PSJo/5IqEMJqRrmSFtD9cFxY92FKXF9K3UZh7aJemJCzgTmtrL/MqP+tj HAonQIEevN+4fysc/A9ZaLMYty30P7JZwjc8bR1hZngHmkqeUDTcYJCcFr7Yt8fK NmHPDeD9fesHSw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudeguddgudefudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepvfhhohhm rghsucfoohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenuc ggtffrrghtthgvrhhnpedvhefgiedvjeegtdevheefhfetleefgfeivefgffevfeejgedt gfeutdehtdegveenucfkphepjeejrddufeegrddvtdefrddukeegnecuvehluhhsthgvrh fuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepthhhohhmrghssehmohhnjhgr lhhonhdrnhgvth 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 73E841080057; Sun, 21 Mar 2021 05:09:09 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: sarosh.arif@emumba.com, anatoly.burakov@intel.com, Stephen Hemminger Date: Sun, 21 Mar 2021 10:09:03 +0100 Message-Id: <20210321090903.612998-1-thomas@monjalon.net> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210211220544.55439-1-thomas@monjalon.net> References: <20210211220544.55439-1-thomas@monjalon.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2] 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 Acked-by: Stephen Hemminger --- v2: use simple "if not" construct for both None and 0 --- 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..db141b3efa 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 not pagesize_kb: + sys.exit("Invalid page size: {}kB".format(pagesize_kb)) if args.clear: clear_pages() -- 2.30.1