Received: by 2002:a05:7412:a9a3:b0:f9:327e:43ab with SMTP id o35csp103115rdh; Mon, 18 Dec 2023 05:44:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IGD5p6Zs31/FR6Cq7g08h0edCOEoT069V9yJqaZHRrudaxJYPfpFfv30LfnczTUY68t/Q7a X-Received: by 2002:a05:6214:b6a:b0:67f:83f:e035 with SMTP id ey10-20020a0562140b6a00b0067f083fe035mr13195402qvb.74.1702907072907; Mon, 18 Dec 2023 05:44:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702907072; cv=none; d=google.com; s=arc-20160816; b=gJS2D+s1C/1hwK/Mvu+NC0q/QxgMAQFbAJuYdiX28qZCpoXesclO5y5Coe1c92JMhJ HzseMUThQhlaF/S8QtSgNOSeq+mZ6Dfy9/XP0b08rceYDQoo9gCd5yz8hZ9/I4ujTowB +mB2J3uwxjHv2jVwcOPJKprPk7kzAaIsH/Ea8SqkLY1LCsTeyAXkzGCuEE1fLvSoT277 YkntDfn1uJxqeEym9dQrnHBNJugZZgsuRqWVJS3EBEqKCZQ5dLdOXrONPAh2eJvTdBNZ eTtDEJPKSl74l0otQGHTrAokxPUfao5c9XToPEpYVv2EhSWC3y5SsYPSvGP04DpfM7+d lGWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=organization:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:subject:cc:to:from :date:dkim-signature; bh=KEw4R4oMODj7f6AzCjgrD/+gDHA2BmV9TbVL9l0uN3c=; fh=30MKK7lxbBcBe8l1kz/EnE2wu9Dxw0q5rnArvF4f8Z8=; b=HoOAy7BiDfmOEQLq7C75GjJDmIiscuB26eVCwlVq9Kj5R8VGfsjj1XIYxYNnGmCMh5 OFA4RXMO4uC2JuKYfIEL3AekxMoshE74ED2VfM+3DkDgsj12UJ58wUjETDykfbw4G501 niE4laOZ9lzmx5z2eU7z6kJcDxcZy6dVVUrY+JtTztiIvkJ9IaXDQXSrXy4KcUbIaiFq +lWEuEtrXXlWk7ot9sR1NprWqHcxjlzLQMyBUFt5DlOKZi2KT2d4XviTlVTtOuYq4ILK 6qWtDML+gRsxAVymFnxfyBfQqDX9g+3iM5T9wgjBOAdyXgJ9xIAwqPAeP0PcrbWnH0ft 8Vgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UoGvaYxk; spf=pass (google.com: domain of linux-kernel+bounces-3767-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3767-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p18-20020a0cf552000000b0067f49266101si1374563qvm.477.2023.12.18.05.44.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 05:44:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3767-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UoGvaYxk; spf=pass (google.com: domain of linux-kernel+bounces-3767-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3767-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 655EA1C246CA for ; Mon, 18 Dec 2023 13:44:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 32F1B37868; Mon, 18 Dec 2023 13:44:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="UoGvaYxk" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E69F71D146; Mon, 18 Dec 2023 13:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702907047; x=1734443047; h=date:from:to:cc:subject:message-id:mime-version; bh=G/JDSsjaBbpRf47CjuV2xxri4aEDlv0U+LcRg8Kpez4=; b=UoGvaYxkF3eLP5wlEQrsTg3dwAra4RnN7h8qI95Hbqk5duFN3MoJ5Cae DMhsSBa4IvOb2ZwxgU1lyLugXDnStG9sDkGswOpqqajYNchtnZvU4yaj1 6hwyXL90muq0GAtjqO2u3zut7Ad5a2kMJGwffWBwg+UbMCFKimzE7XeCI aqS06bPJOTqr1FbpTkondN5yl5t5z6qGy6V/2Sl4VjX/GQPdxf3WhkCU/ u2SXQtnXsdYKCV4rRqLjY1M0JNAnh8TmAZf+5s/PLHCd6CwOykuufNrVA WleBm8cOpw7GInkt0yk/R8mX6r/1fK+QCvLUCXObw+KGoegs8ZppLX9CP A==; X-IronPort-AV: E=McAfee;i="6600,9927,10927"; a="8957884" X-IronPort-AV: E=Sophos;i="6.04,285,1695711600"; d="scan'208";a="8957884" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 05:44:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10927"; a="898974742" X-IronPort-AV: E=Sophos;i="6.04,285,1695711600"; d="scan'208";a="898974742" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga004.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 05:44:04 -0800 Received: from andy by smile.fi.intel.com with local (Exim 4.97) (envelope-from ) id 1rFDub-00000006x8d-3pIB; Mon, 18 Dec 2023 15:44:01 +0200 Date: Mon, 18 Dec 2023 15:44:01 +0200 From: Andy Shevchenko To: Qu Wenruo Cc: linux-btrfs@vger.kernel.org, Andrew Morton , Christophe JAILLET , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] lib/strtox: introduce kstrtoull_suffix() helper Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo On Fri, Dec 15, 2023 at 07:09:23PM +1030, Qu Wenruo wrote: > Just as mentioned in the comment of memparse(), the simple_stroull() > usage can lead to overflow all by itself. > > Furthermore, the suffix calculation is also super overflow prone because > that some suffix like "E" itself would eat 60bits, leaving only 4 bits > available. > > And that suffix "E" can also lead to confusion since it's using the same > char of hex Ox'E'. How would you distinguish 25E with [0x]25e? I believe it's unsolvable issue as long as we have it already. > One simple example to expose all the problem is to use memparse() on > "25E". > The correct value should be 28823037615171174400, but the suffix E makes > it super simple to overflow, resulting the incorrect value > 10376293541461622784 (9E). So, then you can probably improve memparse()? > So here we introduce a new helper to address the problem, > kstrtoull_suffix(): This is a horrible naming. What suffix? What would be without it (if it's even possible)? I have more questions than answers... > - Enhance _kstrtoull() > This allow _kstrtoull() to return even if it hits an invalid char, as > long as the optional parameter @retptr is provided. > > If @retptr is provided, _kstrtoull() would try its best to parse the > valid part, and leave the remaining to be handled by the caller. > > If @retptr is not provided, the behavior is not altered. Can we not touch that one. I admit that it may be not used in the hot paths, but I prefer that it does exactly what it does in a strict way. > - New kstrtoull_suffix() helper > This new helper utilize the new @retptr capability of _kstrtoull(), > and provides 2 new ability: > > * Allow certain suffixes to be chosen > The recommended suffix list is "KkMmGgTtPp", excluding the overflow > prone "Ee". Undermost cases there is really no need to use "E" suffix > anyway. > And for those who really need that exabytes suffix, they can enable > that suffix pretty easily. > > * Add overflow checks for the suffixes > If the original number string is fine, but with the extra left > shift overflow happens, then -EOVERFLOW is returned. And formal NAK due to lack of test cases. We do not accept new generic code without test cases. -- With Best Regards, Andy Shevchenko