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 0FE3EA0547; Fri, 12 Feb 2021 12:35:00 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7870422A24E; Fri, 12 Feb 2021 12:34:59 +0100 (CET) Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by mails.dpdk.org (Postfix) with ESMTP id AA1B622A23C for ; Fri, 12 Feb 2021 12:34:58 +0100 (CET) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 8487A6B7; Fri, 12 Feb 2021 06:34:57 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Fri, 12 Feb 2021 06:34:57 -0500 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:content-type; s=fm3; bh= wTAVfNOpKni0/Ck6m9IwMOvcmXLnuwV+g2IxPuBffcc=; b=ekit0WpO0OpBbUoH g+lCjhiQa9fLGf30ni2TWYaU/RBnCH2V1VgFH7W1tTnE1MSJ/1sRaHXMzyd9YRVf D4k6NoUFoA6iRgx8xOaXeqYLVn2+M/ofnB7aas3pxSgpmzaH41ctwyKgq27GehKh IycqY9rg6QVxF5lPCfvccmscKPURgqrkVFIaiB5t7LQNwodwN89xOrKFObwsS8Vr jpJ340ESVHgyWDIcTD8QMCu7/1uDnx5N70PYUQoXss/j/NwNMRDJkp8ZGVI4Gi9F tn3mDAvJzgrnFEnwCGED7TeHcOg9gOPpF7qQWbyFaaVtZhW0TadFazqWai2z7xQ/ 2+CAHA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :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=wTAVfNOpKni0/Ck6m9IwMOvcmXLnuwV+g2IxPuBff cc=; b=UXjYADCgjZv4MAD2zrjPXrHT8JTVIqy3cekD5i2p6TIGw5khr0oUKz0J7 noxk05y7w9zCNnhWgHc7JKpWtB52HL7aETPtkEDAHWnss4ldp/SCSTkyvbx7nwGN 26PJkf3biozShyCAHEr1JyAFjK+kj7GA7ltJm5N/8VmMhxCCaX6x0aKJXloW5cRy Ak2CacYSowvaPrYrzWI4riY8aCRkAMYOT0X/5DRkHmiuw5K9H158CbZE7Z8SIsCu zzMSuWX+gD1txzRmCGkvMVP2lo5PPKlibsymw+6ZxKqOtWZuLud1SQtZ8vmjg+XM M6IleAzpxDE5LkxNsUJN+NUQDXRgA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledriedugdeftdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkjghfggfgtgesthfuredttddtvdenucfhrhhomhepvfhhohhmrghs ucfoohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenucggtf frrghtthgvrhhnpedugefgvdefudfftdefgeelgffhueekgfffhfeujedtteeutdejueei iedvffegheenucfkphepjeejrddufeegrddvtdefrddukeegnecuvehluhhsthgvrhfuih iivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepthhhohhmrghssehmohhnjhgrlhho nhdrnhgvth X-ME-Proxy: Received: from xps.localnet (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 1913A240064; Fri, 12 Feb 2021 06:34:56 -0500 (EST) From: Thomas Monjalon To: "Burakov, Anatoly" Cc: dev@dpdk.org, sarosh.arif@emumba.com, stephen@networkplumber.org Date: Fri, 12 Feb 2021 12:34:53 +0100 Message-ID: <6402439.QoXlHTGXZI@thomas> In-Reply-To: References: <20210211220544.55439-1-thomas@monjalon.net> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Subject: Re: [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" 12/02/2021 12:27, Burakov, Anatoly: > On 11-Feb-21 10:05 PM, Thomas Monjalon wrote: > > 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 > > --- > > @@ -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)) > > Both None and 0 evaluate to False for boolean comparisons, so you can > replace it with: > > if not pagesize_kb: > sys.exit(...) Oh yes better :)