Received: by 2002:a05:7412:d008:b0:f9:6acb:47ec with SMTP id bd8csp442601rdb; Wed, 20 Dec 2023 01:32:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGUjY/YMM/+dCo9uaM8cTwLU4ZHIxlXAGywX5M6t1cOvCHKSlNnA5FXH8+btjQh+/TTJAuz X-Received: by 2002:a17:906:bc87:b0:a26:8873:7bf with SMTP id lv7-20020a170906bc8700b00a26887307bfmr572170ejb.118.1703064751257; Wed, 20 Dec 2023 01:32:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703064751; cv=none; d=google.com; s=arc-20160816; b=xZ3T/f26RaQ441q2Tj5SJH3qIspFDZeDftst+wNA+hoir8F1ELuSE7lwW07V75cX/V KjSuBXqxnw+mVU4RGME3DfsQCw1T/Hyt/PJ3udxCQJ1BtgfCXrSL9epRnmB6Vx4eY5u9 1FbnAksQfCH0M30MZKu03EtcSn5F+D86IWU1yO089OehaS1dHbKS1zesqKD25akAQJcp GDCX46eMAbppCLR2HWwjFI5q6UeVHpEaRqKPviykNr2qXaCexWCUAxyBuR8bg4/4uEfX 8yUK2Ut0+UQ+EYadsu3hwRD3A65qYNN1ndQrYKGxNU+fgbrYLmZOvezKzYqDCamIoTk2 /lSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:in-reply-to:autocrypt :from:references:cc:to:content-language:subject:user-agent :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :date:message-id:dkim-signature; bh=U2CxCL3RFOKNqJByOBlVPw+i7R4+3Iux64NCfcYThws=; fh=cFsz07byehwvRHCn5QGBXE6yEtEjENZtcMGAPniRF3M=; b=FIHbBfPOttDvKZ5HXktKonWkaujT07Hl4pShK1auHdzCqNs1kaULPqLvYRRJE3YYZK 0xl1RCcsMYgAxqN+pxc0SvHFuAuEb2eoiBIAymIdhE6Fi9+7TzA7nrqRKVUz867kOScG 7uu9PsnMr6gsoMbknN05B0GD3VJz8Oa4j7mzR53WmpHkvhRNYDqd+H0Asn/E65r075ux dOtjlzvw7DSvaT7O6eD9HZmXqt6oJ0cO2NF4c6FvUOIje3nby67OBx0nNfb804vI+yEI 8ETvS11nbaeJiyBmPabi35ox5fDW/ySoG+lvHBsspVFgvpZipN1Rp67cY4BZInXtxBLy Q+KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.com header.s=s31663417 header.b=TKxKyyQe; spf=pass (google.com: domain of linux-kernel+bounces-6642-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6642-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ay25-20020a170906d29900b00a2684c29489si1065701ejb.526.2023.12.20.01.32.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 01:32:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6642-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.com header.s=s31663417 header.b=TKxKyyQe; spf=pass (google.com: domain of linux-kernel+bounces-6642-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6642-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.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 am.mirrors.kernel.org (Postfix) with ESMTPS id D45DF1F25DA3 for ; Wed, 20 Dec 2023 09:32:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 788441F612; Wed, 20 Dec 2023 09:32:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.com header.i=quwenruo.btrfs@gmx.com header.b="TKxKyyQe" X-Original-To: linux-kernel@vger.kernel.org Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) (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 7E0221F5F4; Wed, 20 Dec 2023 09:32:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.com; s=s31663417; t=1703064731; x=1703669531; i=quwenruo.btrfs@gmx.com; bh=RmcNpCoJv8JMDhdDtTD8JTG4zy09q5k4fiaUhfHwTpc=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From: In-Reply-To; b=TKxKyyQexREmWCysAwBClFck41AihhdWaZazSqVWwTcWJ0DNuXqRmr1BHphvLjCs puvdM0bef+K5oyJMSU4flJ+qM9E8S+gW/mbhwRnvFw/8+Ag6Af3ALH61SgXzBR9aN L4dq1iIrICxNYAHJ7PpXyZdgvVM1rKdEsi5A38UbMg2yKIMvDuCB+ld/E86WO8yUP gI5GQYdeDt4ys1UNJXQE73Wpg1bOpubbfMBJAdYZqeaMmWvBL4VAiv1+0CdZqnVql /mbeTKkR4w4PBVGoBt56XnN2oSbAY+fcQVB4s50mmvRLcvLUHmfhY/Nd0tKParwAT sPn0eVWm1IPP13nTaA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [172.16.0.153] ([115.64.109.135]) by mail.gmx.net (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MDysm-1rPkJ41pxM-009wYK; Wed, 20 Dec 2023 10:32:11 +0100 Message-ID: Date: Wed, 20 Dec 2023 20:02:03 +1030 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] lib/strtox: introduce kstrtoull_suffix() helper Content-Language: en-US To: David Laight , 'David Disseldorp' , Qu Wenruo Cc: "linux-btrfs@vger.kernel.org" , Andrew Morton , Christophe JAILLET , Andy Shevchenko , "linux-kernel@vger.kernel.org" References: <11da10b4d07bf472cd47410db65dc0e222d61e83.1702628925.git.wqu@suse.com> <20231218235946.32ab7a69@echidna> <8095c6ae5f8d412d8e6ff95707961a08@AcuMS.aculab.com> <4fbcab63-347f-4cef-ad35-686844c983ed@gmx.com> <3f8ee41745ac40e58e0aa535029e8751@AcuMS.aculab.com> From: Qu Wenruo Autocrypt: addr=quwenruo.btrfs@gmx.com; keydata= xsBNBFnVga8BCACyhFP3ExcTIuB73jDIBA/vSoYcTyysFQzPvez64TUSCv1SgXEByR7fju3o 8RfaWuHCnkkea5luuTZMqfgTXrun2dqNVYDNOV6RIVrc4YuG20yhC1epnV55fJCThqij0MRL 1NxPKXIlEdHvN0Kov3CtWA+R1iNN0RCeVun7rmOrrjBK573aWC5sgP7YsBOLK79H3tmUtz6b 9Imuj0ZyEsa76Xg9PX9Hn2myKj1hfWGS+5og9Va4hrwQC8ipjXik6NKR5GDV+hOZkktU81G5 gkQtGB9jOAYRs86QG/b7PtIlbd3+pppT0gaS+wvwMs8cuNG+Pu6KO1oC4jgdseFLu7NpABEB AAHNIlF1IFdlbnJ1byA8cXV3ZW5ydW8uYnRyZnNAZ214LmNvbT7CwJQEEwEIAD4CGwMFCwkI BwIGFQgJCgsCBBYCAwECHgECF4AWIQQt33LlpaVbqJ2qQu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CdtpR6GbL iQi22uZXoSPv/0oUrGU+U5X4IvdnvT+8viPzszL5wXswJZfqfy8tmHM85yjObVdIG6AlnrrD In-Reply-To: <3f8ee41745ac40e58e0aa535029e8751@AcuMS.aculab.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:n9xSg9cZiYmNhQQFK6SDW5MlADcP1MBIqspeEBCjddohlHyXYeL WuoSWLS6rPFh1PMV8U23tu5XQdvjaPN3Id7VYrZzsEgfnrH76V1pgWRK+18v3cUyNN+sWG8 7c7VTPIsVvgvK3uCqjoyHzpSiDi69X67hWJNL3B77T4d0zJGImueP663ddz8Va+FbbBqRjr 4x8BdOn2WEEZcbPuwQ7Fg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:mdEFmaWL+Bc=;7ddx42WlRz3s+zTrgoZ+6rRzxFo Wrfr5TNxBIwfZ72puFbpWXsYrOx3eG0uviO92V4oyppcA8nBL4eDIkMltytn5KF9Ui4dWpg1v yvIdgTdnT4zu7xv1YWVHyEa6NIvPH5NaQdpzrZJu+kvsTh8CI2cvEeRAbjYXXeWytTJ7vlbiq 2kYQh911GrXNlIdFXaZ34ZicKgyXJwF7w+YNBbpQVAkSVLnEApJOBojDfKzdGtwIRaESp7IFG aOaLrJ72V/GKejlZvwVTC5T2pwvGDXtvleFqVyYlrvi0vaDXXZqtIhoeNe1zX8Kt9iV0IKFrG TjrlEHpsR3OaPGyHQzrNPWg88MibWpXFfSWm6izRDxFFF71cJCWhi/NZcf41j9lFrbg9ESJtG siDMn23OR0V9I44XW/UGa5wiOwfoRAwu5qxx38KXOVEMk9lTq0lylWvI+3TqcKUktVglhX0ef Ah5H65pu6uzGi1J98SUaifPMdMt6H/qxkzANUKPT5rSckuDbiPvt3X3DVUIBlapxSZMGMheUJ Ziulqr5oLIcfz5QLZxrzb1gqz8pxgaeG/k+2Z55fsl66Fbmx67YauWpa5hR4rL8eBiYnXT1oe 8rg8Xie4dNHhMPNQ2+t03uNSy4k05y03y0DDm6alaMr4KNNnWpt2CtjFlweJQnCIy/5ceGpHq iofhNnRpkjYGZ9GVIMKhK0jTci4tzCre+kZUsHtuO57ldBDWmHd0xtPfvDEZc1+JbC35MDYem tQQ3V0BadASQwO7yp7PEoAlUnNBtrWsZo/4+tDKgQ3KDTYl8iuH5vmA2APdmCF9tS2Xu5b6to b3qa7pursEgDzF01HFDSgZNfpoUsujsSStBBVHFvRU7pFsjsZGtUyGmEZBNBonL+UzlDY58E0 UdS1UaOMA+a3tUvfp6jSZ7mIYg/3yHFaiGh9Ie72SdAHGAFujYp6cFe4ghPNNzDyZQMhVDGDo Fa91t3DKdsuSUUJ1k/PxLl1C+rU= On 2023/12/20 19:01, David Laight wrote: > From: Qu Wenruo >> Sent: 19 December 2023 21:18 > ... >>> How about: >>> suffix =3D *endptr; >>> if (!strchr(suffixes, suffix)) >>> return -ENIVAL; >>> shift =3D strcspn("KkMmGgTtPp", suffix)/2 * 10 + 10; >> >> This means the caller has to provide the suffix string in this >> particular order. > > No, The strchr() checks that the suffix is one the caller wanted. > The strcspn() is against a fixed list - so the order can be > selected to make the code shorter. Ah, got it. Although in that case, the 1st parameter should be ("KkMmGgTtPpEe"), as we still support "Ee", just not by default. Thanks, Qu > > Actually strcspn() isn't the function you need. > There might be a function like strchr() that returns a count > but I can't remember its name and it may not be in kernel. > You might have to write: > shift =3D 0; > for (const char *sfp =3D "KkMmGgTtPp"; suffix !=3D *sfp; sfp++, shift++= ) { > if (!*sfp) > return -EINVAL; > } > shift =3D shift/2 + 1 * 10; > > David > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK= 1 1PT, UK > Registration No: 1397386 (Wales)