Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2716659pxb; Thu, 3 Feb 2022 12:37:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJydZGpyZ5c8TQS0Urhv4Av/PIOYRDpuEBin5e6I2ET1PFI/QdKYOKc9B0M71IQ8QT76RaES X-Received: by 2002:a17:903:18b:: with SMTP id z11mr36824374plg.59.1643920640855; Thu, 03 Feb 2022 12:37:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643920640; cv=none; d=google.com; s=arc-20160816; b=RopOJviXbt3rcC5OqW6ZsKZzGHZU1gXdrhe0a71w9ydjjpz/0R5QGoL8a5aA8YwiST BhYgs14h6m+OJRWSChACy4u/H7ai8s8LkK1aM5dhItoM3Lk1aRkgQPs2GQyo+arWPT+t I6ctN00oNxmwqgI6IFSpE02YmPzMvqPOnd5PN2KlpLo8qzKMRcuT7Cb9X41AuCdSsz0I atYgQecTqfYyHHcbTXWKbGPO+AnS6aAzayi09LYTWDKNfW2hzezWfThYFjQWBlic/IJ1 tgdAxAR9Q52tr9mS+gcILde0YCFvsj0ct118N14n7IlhxCX6aFdsipSBZakGRkOQSk0v IHDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=PVW92HDoC/XVNlQ/sBgLb71ANKolpSb9a+lR1z7DyS0=; b=V4yxp8JqhxLIQ/qJ0+elV1qg7+joZEW7VJExfcnIK7BSyOp8U/Jzw+2fi5LnTZEz6m +q9xJmfguHQLiJatcD5Se+vJz7MO4+pPBzm44QZ9huQe5yts4dq2ta4uPl/2swyaio8d Zr4l0SZs3LfPJhSjiqD8UOvftejgv1WuAWiLgxSSleq7S/n07/lLLNVuBd2aj2OQo53F dm/BDwQkT6EtpOMNQ3y7MCFVkOkiAHubF6761XWg7Vadm7FX1H6mqM8rRrb6db365afz 6cse8MQeZ7gVjF8pWl3ylpUhPEh+KovC5AjIdwJyqg3c9SBMMP32JlP7xf0+AjvM2blC xDkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=CPLDx7KN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l63si16280811pgd.96.2022.02.03.12.37.09; Thu, 03 Feb 2022 12:37:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=CPLDx7KN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234599AbiBAHMq (ORCPT + 99 others); Tue, 1 Feb 2022 02:12:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234592AbiBAHMp (ORCPT ); Tue, 1 Feb 2022 02:12:45 -0500 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E605FC061714 for ; Mon, 31 Jan 2022 23:12:44 -0800 (PST) Received: by mail-lj1-x229.google.com with SMTP id q127so22788603ljq.2 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=R+zIEvEJb132RNmjuWOVkxwWRjdOuYtit0KXXolXO85s2EdF2GKFwQ6uUG8BG5TjVo OdJJE0FiImjJ9z1fghuBqRi1s6ysX7uNtL/nGmMEzCBeapU1JgJOsENomQBR4LeOwfeq hmUQmcHGKkcTxchiEnOH01qyOe6Pj17PQRIqHwzNcs3FghC30LQOAS2oEuFSLCD+fPf3 oV8COTezZRjlvFsJaDF46AD1+wxry/iDDw4weJpybsnxciuKkin/54Qr/9mjNNgyeolA sEoXiEn5RZPLk+KXlEUCTXe6nVQ10s6Yxgx0RZCqMrcK6PsjBHS6YwJIxxuZ7xTdev9c FKCw== X-Gm-Message-State: AOAM530MCMUjhBj5Hv17hXZOasu7AjvVankvwFz/Aqs16fRTexTosv3c or8qVkAeiZ01+jo/rP9uOm45wg== 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >> >>    "If @size is == 0 the function returns 0." >> >> It should mention the (theoretical?) possibility of getting negative >> value, >> if vsnprintf() returns negative value. > > 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. 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