Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1440341pxb; Wed, 2 Feb 2022 05:11:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJyRoxNjARIsYrpNjp5mu/vUEPJsc4ukMANACdfRTL4kUAs88js7RWnnoeWI26ciG9JS5Vy/ X-Received: by 2002:a17:90a:290b:: with SMTP id g11mr8076911pjd.8.1643807501962; Wed, 02 Feb 2022 05:11:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643807501; cv=none; d=google.com; s=arc-20160816; b=wEUR1OZuwAJhef4oE5guYgUMOB3VQ8aMQxrgaEqvdOthnGT1/ofi/QsGPWtPVtP+Nr 836+rnO6WbyUHwdn5r51NczUx278f7fQ/01BLFaSZnCi5LUBQy4uBYedr5LPfrLMhJNG yrCro9bTDGLRbumIV20p0X5CV+XnG6UWSfHF3rk7T/qP8qL59JYahve3nw5ot8jauCuY e79h2ad4cATb7o7eievYPLVcEn1L61LeLzYl6FCwC05t4L7M2bt/NNp9ozTKXapUF43T yb3fodypjImyxYG2TYAMtLQS3W5n0VhhTy+zj44DuhgRwv9F/c8Nx6XlZ5cnmCaNdjDN ryDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=0lOsjYnjuXJjkQQPkdLRQ4+5wRRHj/4IS9YqFDRMAvI=; b=NfNfItob41QaEaSuomXlLKjIeMMsjL8+/yboYvbWW7AKS3XbwPnkt8Zmr+vMY1lpuR +DSel3dvZT8lXdWfSKDPLJWwzZJnFaZBwhRawUMCZsloj2Zm8P8mbWmR7gaXzJusmucF hbfBBkf2CUU098J42As2GegtmvYnHrtqy3OGCnxyEktODvqMPMv5HMFRmX+aH72/KcXH 2cGPN8mJxNDvR3Lk0BjZ5QNJHLWhv83A8HtH25lOoJjGDEeuDVNuZ/5qrrXtnsV9A+qY 2a3KKuLimOxlhcV1VtEMKfqRsqfa84s52ZVXd4ZFb4C4W9svNFzgAO2TJvSiHz+d2nuW Uxzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Anw2DN4M; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kb18si6448907pjb.44.2022.02.02.05.11.30; Wed, 02 Feb 2022 05:11:41 -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=@redhat.com header.s=mimecast20190719 header.b=Anw2DN4M; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240785AbiBAQCc (ORCPT + 99 others); Tue, 1 Feb 2022 11:02:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:37129 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235398AbiBAQCb (ORCPT ); Tue, 1 Feb 2022 11:02:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643731351; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0lOsjYnjuXJjkQQPkdLRQ4+5wRRHj/4IS9YqFDRMAvI=; b=Anw2DN4MVE9HwvRI69CsHJuNcovHkFg9GbRP6qf8YA8cGlDIKlj9kLZKfjDTZPQnU5AhLG 9K4Hf8pvyyHHW7QYqWlzHPl3Kg1p3+9/o1PIQU4niuBwJHrW4GBySIUrVwlJJ5XRirr7h1 66RaGKKlO5CbyvM9W9z5vDrb1kdVrPk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-75-WqDDEl3dPKOc7sq2HX2xEg-1; Tue, 01 Feb 2022 11:02:27 -0500 X-MC-Unique: WqDDEl3dPKOc7sq2HX2xEg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2A3211966320; Tue, 1 Feb 2022 16:02:14 +0000 (UTC) Received: from [10.22.19.61] (unknown [10.22.19.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 00CF772FA2; Tue, 1 Feb 2022 16:01:51 +0000 (UTC) Message-ID: Date: Tue, 1 Feb 2022 11:01:51 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH v2 1/3] lib/vsprintf: Avoid redundant work with 0 size Content-Language: en-US To: Rasmus Villemoes , 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: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/1/22 02:12, Rasmus Villemoes wrote: > 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 > Thanks for the clarification. Cheers, Longman