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 734C2A0547; Fri, 12 Feb 2021 12:27:43 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D75D022A257; Fri, 12 Feb 2021 12:27:42 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id A021322A24E for ; Fri, 12 Feb 2021 12:27:41 +0100 (CET) IronPort-SDR: KplG5n5h+v4jJuw18aJUHCtia7QY7LHu9Si3fomtr2uqtZLbwNA6Ds2dgO1HQUca8Xd4Q4CUBY 1z/7iaf67q4g== X-IronPort-AV: E=McAfee;i="6000,8403,9892"; a="246462705" X-IronPort-AV: E=Sophos;i="5.81,173,1610438400"; d="scan'208";a="246462705" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2021 03:27:40 -0800 IronPort-SDR: BQRyLI6LXcqKVqJoqAgWMdNVuuIP89BIL+XvUjjxDGkB15n8I2e0e4P6bFibjdBBrEgmCKjevV 0o+B+JZsjqsw== X-IronPort-AV: E=Sophos;i="5.81,173,1610438400"; d="scan'208";a="397943135" Received: from aburakov-mobl.ger.corp.intel.com (HELO [10.252.26.71]) ([10.252.26.71]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2021 03:27:39 -0800 To: Thomas Monjalon , dev@dpdk.org Cc: sarosh.arif@emumba.com, stephen@networkplumber.org References: <20210211220544.55439-1-thomas@monjalon.net> From: "Burakov, Anatoly" Message-ID: Date: Fri, 12 Feb 2021 11:27:37 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20210211220544.55439-1-thomas@monjalon.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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" 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 > --- > 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)) Both None and 0 evaluate to False for boolean comparisons, so you can replace it with: if not pagesize_kb: sys.exit(...) > > if args.clear: > clear_pages() > -- Thanks, Anatoly