Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6773090rdb; Tue, 2 Jan 2024 12:56:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFYxd2hRJkMVqvpDjNit1rZpKe5UzfSn8JAueFrk2mhrKghNH+G6mJYeYBmpRFhIxcntQhs X-Received: by 2002:a17:902:dacd:b0:1d4:caef:6f69 with SMTP id q13-20020a170902dacd00b001d4caef6f69mr980845plx.63.1704228976108; Tue, 02 Jan 2024 12:56:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704228976; cv=none; d=google.com; s=arc-20160816; b=rAsTOdxjOKeUVdwENDBD5fE32i98ye9JnVlyIGnLnU6un8TwKlonPy2ueda+xTRylq 4m6F0uR0bu6C+65zVF2EWitwBHj1Y0pDlK7p7SAVxTScy89DtvC/O8CghCgSfHdzqof7 XhiwUVOrvlleiAdoojTmkvhrbwMV60zkkoQ7xZE3aZQ16K1lxU18YWnJMCqlSNaR/LnW Na72jRIhXxOP/NORoQbOGuGUrEkiopQ/MUbjOh2beUbYYER5iUdmDxhLw96HKeLgQa2/ ilatNIApymmIkbVKJABcSxhgcB7JiseGqYGKXgZeV9LnVifyeanYzZcxk/LH0+JeV7Iz 8xOA== 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=9bg+4Wzobkqx2Ey6MEXubBNUXgo/1YQdri1E1pqkpnw=; fh=0F4ZCYcG1u1zz78GMu47REdKB8Qv6gfyki5xP5fdwwg=; b=Zx5egJ1pUeTUS8No/ewMl19YpB753EtucTqLQpzCABF0sKSk1+zEvMV4+T46AKEwM4 PoBLLVE5+Q7BtxE5X+kR8SKdpu6jJWTm528OxAcOsS0TkUQQiP3qTt5FtRtSvW23vRj8 bWaafW1KY3Lo59O+t8wc/AbCAvKEgCJGo5v3OSgobjE8i7Pf75J/pail2YvT7YW8749j JfpMM/eFa4lwUVujnawhhswfuJxDIMfpzkwSusd0005Iw9kF4t7pOZaRFMYOJSlNmQBx n92pwFUAWH81DgkGE1ESqDm5NB6dAmKOQ5aKfdCDGvDfmlg9VTl4Z2DYP54lyYiOx3mv s2Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.com header.s=s31663417 header.b=A259hMUY; spf=pass (google.com: domain of linux-kernel+bounces-14812-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14812-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id f21-20020a170902e99500b001d420ecdaccsi18487014plb.92.2024.01.02.12.56.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 12:56:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14812-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.com header.s=s31663417 header.b=A259hMUY; spf=pass (google.com: domain of linux-kernel+bounces-14812-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14812-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id BFB10284372 for ; Tue, 2 Jan 2024 20:56:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C7E02168A3; Tue, 2 Jan 2024 20:56:07 +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="A259hMUY" 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 55BA4168A4; Tue, 2 Jan 2024 20:56:01 +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=1704228943; x=1704833743; i=quwenruo.btrfs@gmx.com; bh=gMHU+YJ/gkegHphYhhSdY57QJmZ7UfevcmljOKNvk84=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From: In-Reply-To; b=A259hMUY6mlOGHZpcbVMQjPdNDRa86L6+nB4+k7XLTCx7EF5ny208dr5wkigGuai ckO/q8sLEjTr9W5+X9nhuJwkRtsEe1Dq7VxWxfZFam3VjUpTC+bVCOQDjP+ko43yn 24qrSzNKDXzK1tIJRJCuaTq67sqnie2vZQrMVHbEEIG4ezIuHQaL29gdt8bZfkOqw 5t5oOtVZGqp8++9dpuehQO2q1orjriWTUZYZYsUsK1MuXLGfCIaXgQfkNlhm438mO lL5KbjNOzsbnEIIt/oajXFGMklt5mwBrkjrt5JfpXzBxCqLSUeX2peBT+51ljx4R+ YTWYtrV7+IgmoR3nAw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [172.16.0.153] ([118.211.64.174]) by mail.gmx.net (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MWzfl-1rj7Dj2JDN-00XLzI; Tue, 02 Jan 2024 21:55:43 +0100 Message-ID: <756ac3e8-3d68-40fe-a7d4-1cf6ac77185e@gmx.com> Date: Wed, 3 Jan 2024 07:25:33 +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 v2 3/4] kstrtox: add unit tests for memparse_safe() Content-Language: en-US To: Geert Uytterhoeven , Qu Wenruo Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, christophe.jaillet@wanadoo.fr, andriy.shevchenko@linux.intel.com, David.Laight@aculab.com, ddiss@suse.de References: From: Qu Wenruo Autocrypt: addr=quwenruo.btrfs@gmx.com; keydata= xsBNBFnVga8BCACyhFP3ExcTIuB73jDIBA/vSoYcTyysFQzPvez64TUSCv1SgXEByR7fju3o 8RfaWuHCnkkea5luuTZMqfgTXrun2dqNVYDNOV6RIVrc4YuG20yhC1epnV55fJCThqij0MRL 1NxPKXIlEdHvN0Kov3CtWA+R1iNN0RCeVun7rmOrrjBK573aWC5sgP7YsBOLK79H3tmUtz6b 9Imuj0ZyEsa76Xg9PX9Hn2myKj1hfWGS+5og9Va4hrwQC8ipjXik6NKR5GDV+hOZkktU81G5 gkQtGB9jOAYRs86QG/b7PtIlbd3+pppT0gaS+wvwMs8cuNG+Pu6KO1oC4jgdseFLu7NpABEB AAHNIlF1IFdlbnJ1byA8cXV3ZW5ydW8uYnRyZnNAZ214LmNvbT7CwJQEEwEIAD4CGwMFCwkI BwIGFQgJCgsCBBYCAwECHgECF4AWIQQt33LlpaVbqJ2qQuHCPZHzoSX+qAUCY00iVQUJDToH pgAKCRDCPZHzoSX+qNKACACkjDLzCvcFuDlgqCiS4ajHAo6twGra3uGgY2klo3S4JespWifr BLP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plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:UmyXHuFoSVhnuT83cFdKK3fd5FHyo1ASrWsEVOMNHuB/hEzFIVk 4+RA+m49jyEGT62Ja+lu3T+9Oco2BCQSLjpSKnt8R2KNcIYqLPSbEc2vcCWTHtmq3noA1QA IF3q4ljyfXLrhkwTz6NrKoxS/0ymL9GBqSYPL6hIVVcCBxispvDgV6//cKt9S4mjpAeaVXx yzeNZu1LWgo14kxTqQ0pQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:mnR9ez2d0gc=;40hSjPfhcb1LEjj8XRXYIVAvC/s yRhPSbTzyIEaZz/4hmQ2xa94yi26O8BiiaDLZPny9EuKTYi8QYyE93cdqWVhtAjR99RpSSrVz QgaDbie+gezPujC6gK1Isp8LjrE3PSAazGYBAukmlOe9P3fstlCSTJocNLN6Jpoy9taq/+IIG TU6LAuo2ounE3KZydF2T2WjibgGYfeC9Eha/dFIcYQNYstomLQl8oTNClTnssvaRAPgt//NUo cf4Q8GMBpQ0cC9wU6fIdSUEGc0uTub9vF+7/10q61HZqb3zLOK/0mh1qoNiyzcM3u79Q5C4xn DRcUEzUVk4knE/Rm2SbnylXsbdDdovHvFg+uPlqq+ZoirFCOG32sglymxvDo+PJgdg8C+je56 1qFjqmnWY3V6DFqSkhyoUdoazjYqNLreqkfXse+bKhL1pnxSU5Tg0rVo/FUsvwpA28LsYdOqp dfvi94xhihy80yr4q10Wsdlj9EDBQH5Y0bvS+bAdJAvtnQSfiptb0nX2Usd+3QDkzYVvB1GiN erEHW4Q7W+1RFy01zbHIMZ1PG0NqB1L6AY7PjAqvGyjs8vc1YnZrOC/U8vWTxNdjip1NQqHDO dr6YHvRdlRAH0Vvq+OXNw5SWambflonG57Dq/JodnGUvazBnqip/yoEMAZzvbRoCTGPYymGVY fGynHvbSjQLLhBT6t/vxptb7k4oTjgseskJRtTz6fwdDnim8M90aBV/nIgYYtHuw8ByRWMBGE yU0jER45J0obr3TNmg05TTVz9PMV93AcDMQmZZa4lgK2GHWFC3qE0kEzFrBAJXrVTMq8f2qBl vvjfYHGuLTclhMueFdX8B7fsh49KUlhiUrk3U4+hRCqm4LYMosKHJXHno7xe5TNDWTIOFNUcK g3t77sLHkzFAme09MVHzQtuOdcHix1ZhOV5zV5pJrIyVIbV8EzRf9gyV+fo9AyegQLBqZODp7 dz63cFM9wpuPVR8WW14ZuLX82zw= On 2024/1/2 23:53, Geert Uytterhoeven wrote: > Hi Qu, > > On Tue, Jan 2, 2024 at 5:13=E2=80=AFAM Qu Wenruo wrote: >> The new tests cases for memparse_safe() include: >> >> - The existing test cases for kstrtoull() >> Including all the 3 bases (8, 10, 16), and all the ok and failure >> cases. >> Although there are something we need to verify specific for >> memparse_safe(): >> >> * @retptr and @value are not modified for failure cases >> >> * return value are correct for failure cases >> >> * @retptr is correct for the good cases >> >> - New test cases >> Not only testing the result value, but also the @retptr, including: >> >> * good cases with extra tailing chars, but without valid prefix >> The @retptr should point to the first char after a valid string. >> 3 cases for all the 3 bases. >> >> * good cases with extra tailing chars, with valid prefix >> 5 cases for all the suffixes. >> >> * bad cases without any number but stray suffix >> Should be rejected with -EINVAL >> >> Signed-off-by: Qu Wenruo > > Thanks for your patch! > >> --- a/lib/test-kstrtox.c >> +++ b/lib/test-kstrtox.c >> @@ -268,6 +268,237 @@ static void __init test_kstrtoll_ok(void) >> TEST_OK(kstrtoll, long long, "%lld", test_ll_ok); >> } >> >> +/* >> + * The special pattern to make sure the result is not modified for err= or cases. >> + */ >> +#define ULL_PATTERN (0xefefefef7a7a7a7aULL) >> +#if BITS_PER_LONG =3D=3D 32 >> +#define POINTER_PATTERN (0xefef7a7a7aUL) > > This pattern needs 40 bits to fit, so it doesn't fit in a 32-bit > unsigned long or pointer. Probably you wanted to use 0xef7a7a7aUL > instead? My bad, one extra byte... > >> +#else >> +#define POINTER_PATTERN (ULL_PATTERN) >> +#endif > > Shouldn't a simple cast to uintptr_t work fine for both 32-bit and > 64-bit systems: > > #define POINTER_PATTERN ((uintptr_t)ULL_PATTERN) > > Or even better, incorporate the cast to a pointer: > > #define POINTER_PATTERN ((void *)(uintptr_t)ULL_PATTERN) The problem is reported by sparse, which warns about that ULL_PATTERN converted to a pointer would lose its width: lib/test-kstrtox.c:339:40: sparse: sparse: cast truncates bits from constant value (efefefef7a7a7a7a becomes 7a7a7a7a) I'm not sure if using uiintptr_t would solve it, thus I go the macro to switch the value to avoid the static checker's warning. I tried to check how other locations handles patterned pointer value, like CONFIG_INIT_STACK_ALL_PATTERN, but they're either relying on the compiler or just memset(). Any better idea to solve the problem in a better way? Thanks, Qu > > so you can drop the extra cast when assigning/comparing retptr below. > >> + >> +/* Want to include "E" suffix for full coverage. */ >> +#define MEMPARSE_TEST_SUFFIX (MEMPARSE_SUFFIX_K | MEMPARSE_SUFFIX_M = |\ >> + MEMPARSE_SUFFIX_G | MEMPARSE_SUFFIX_T = |\ >> + MEMPARSE_SUFFIX_P | MEMPARSE_SUFFIX_E) >> + >> +static void __init test_memparse_safe_fail(void) >> +{ > > [...] > >> + for_each_test(i, tests) { >> + const struct memparse_test_fail *t =3D &tests[i]; >> + unsigned long long tmp =3D ULL_PATTERN; >> + char *retptr =3D (char *)POINTER_PATTERN; >> + int ret; > > [...] > > + if (retptr !=3D (char *)POINTER_PATTERN) > > Gr{oetje,eeting}s, > > Geert >