From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC42CC433F5 for ; Tue, 1 Feb 2022 07:12:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4564B8D005A; Tue, 1 Feb 2022 02:12:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 405EA8D0054; Tue, 1 Feb 2022 02:12:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2CE298D005A; Tue, 1 Feb 2022 02:12:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0157.hostedemail.com [216.40.44.157]) by kanga.kvack.org (Postfix) with ESMTP id 1DCD28D0054 for ; Tue, 1 Feb 2022 02:12:46 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id C732618233655 for ; Tue, 1 Feb 2022 07:12:45 +0000 (UTC) X-FDA: 79093343490.19.EB1B5D9 Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) by imf13.hostedemail.com (Postfix) with ESMTP id 52F0520005 for ; Tue, 1 Feb 2022 07:12:45 +0000 (UTC) Received: by mail-lj1-f178.google.com with SMTP id c15so22725922ljf.11 for ; Mon, 31 Jan 2022 23:12:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=PVW92HDoC/XVNlQ/sBgLb71ANKolpSb9a+lR1z7DyS0=; b=CPLDx7KNeK82j2UI56J1LCuggSFeS3B2lH5X9mR4iWGhggCJZ7rZFSdvibZncDYfeL 3aGqJjr05O4+vnzjbsQBaM8wljY2rHeBMdnMAjqAfYWCw9vb8EqAzVHJ+/2/S2VQDaA7 Up2Jqz0gcUyuHx7md+lYW8pzmwH4plPXMFItE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=PVW92HDoC/XVNlQ/sBgLb71ANKolpSb9a+lR1z7DyS0=; b=gDe1vTnPL0/pmY4nMD2ZWNTVTw+17rxKmwVYeBhZprWmtpll/0LKnZfQPRHvMGdYgy /EIyxTo9Fjw9o7XIOWuG866wfTf/YudIt7MQ9cyxixAlzGpEQ7UZSjCIlY72C+BygrhG 6ZfADH/D8lcFUyZl1nuzRxfBW0tiBg3cBfvRq5tOTIG/1KVi0GLVIxeLQXgvHev5YqDQ 6ChVd2wOuz6lGuUhc9i3Gg0ciGHRixc7tlZt0bXsQXIGMfvmGcVa/s6dPd3P/7GVmpyr Zkszi8FBg+rBiu7Ao80cNJupRK24TL0wjjhtHNJVpATWYGwsrHfnilZ6JwVrD8p8qYWc QtqA== X-Gm-Message-State: AOAM533hTlKJasSsH2GypA0FC2zL5ARU8tP39sLdyiJqpX1c1WLj08dE OTIptQjr3re5RuSNhvrLG4wxJg== X-Google-Smtp-Source: ABdhPJyAdQ4Gv3Z2Qodv0TvVsi1PTC193vemFm9wBX541IgG+fveE5li4PdKDLfvw6DSY9tWIOAXzg== X-Received: by 2002:a2e:890a:: with SMTP id d10mr6847738lji.29.1643699563231; Mon, 31 Jan 2022 23:12:43 -0800 (PST) Received: from [172.16.11.74] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id j18sm749488lfr.253.2022.01.31.23.12.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 31 Jan 2022 23:12:42 -0800 (PST) Subject: Re: [PATCH v2 1/3] lib/vsprintf: Avoid redundant work with 0 size To: Waiman Long , Andy Shevchenko , David Rientjes Cc: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Ira Weiny , Rafael Aquini References: <20220129205315.478628-1-longman@redhat.com> <20220129205315.478628-2-longman@redhat.com> From: Rasmus Villemoes Message-ID: Date: Tue, 1 Feb 2022 08:12:41 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US X-Stat-Signature: zfq8d8jsaft5iowkniwusw6hsx6u19f9 X-Rspam-User: nil Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=rasmusvillemoes.dk header.s=google header.b=CPLDx7KN; spf=pass (imf13.hostedemail.com: domain of linux@rasmusvillemoes.dk designates 209.85.208.178 as permitted sender) smtp.mailfrom=linux@rasmusvillemoes.dk; dmarc=none X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 52F0520005 X-HE-Tag: 1643699565-721389 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 31/01/2022 19.48, Waiman Long wrote: > On 1/31/22 05:34, Andy Shevchenko wrote: >> Also it seems currently the kernel documentation is not aligned with >> the code >> >> =C2=A0=C2=A0 "If @size is =3D=3D 0 the function returns 0." >> >> It should mention the (theoretical?) possibility of getting negative >> value, >> if vsnprintf() returns negative value. >=20 > AFAICS, the kernel's vsnprintf() function will not return -1. Even if it did, the "i < size" comparison in vscnprintf() is "int v size_t", so integer promotion says that even if i were negative, that comparison would be false, so we wouldn't forward that negative value anyway. > So in that > sense it is not fully POSIX compliant.=20 Of course it's not, but not because it doesn't return -1. POSIX just says to return that in case of an error, and as a matter of QoI, the kernel's implementation simply can't (and must not) fail. There are other cases where we don't follow POSIX/C, e.g. in some corner cases around field length and precision (documented in test_printf.c), and the non-support of %n (and floating point and handling of wchar_t*), and the whole %p<> extension etc. Rasmus