Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp808633rdb; Sun, 18 Feb 2024 12:59:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUYBtNB7k9OwdHaDZPV6U0BXQUbjOCTAjPWyhSSvmpEcOhOORz12CPXdaxJge3EvEhpFDXUW7jFso+iHnhR9Buij7I669q1QMwVIw+Z1A== X-Google-Smtp-Source: AGHT+IGXNhCcPr5GGAt7MWNSvV5Bzsd4Og5JX9MyofUGxIvjo6v+CfN5JKFqvIcNgVyJNujBkOPK X-Received: by 2002:a05:6808:11c5:b0:3c0:3ac9:80c0 with SMTP id p5-20020a05680811c500b003c03ac980c0mr11927492oiv.56.1708289953385; Sun, 18 Feb 2024 12:59:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708289953; cv=pass; d=google.com; s=arc-20160816; b=HTX3tCJyGqI39P0TLI3Ss3AG8Y8zElZWLC0mOKzG2oEKYZHk4ekMfG0kbFK1n4W0as hT5lC8iWfZDRRzxTgxZ3BkN+dZ2VIj6Y7UYhyzlQnDkFquxYF5EkfxU8KOp73fO5rWbk x7J8v5SwFXX2MbrgV4JHxCNQQiOG3xJbp9YApPM0ueDr0PckcKSp0WIdmz3Pw3/hyGsp Iw2HGKx+3zB6UK4/GYf+DQiyDI7Jl3ablQBTwXpQDvg5pA0CR5cWR9045pxX9U0vZTf/ As5O71m/WO6NtPBSuOOUKaB7HSgwprYlOIykNNZgMTj6by4YYo1uf+eRpx9HTpydFWgo mQTw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:dkim-signature:date; bh=EdAwdrqq1gjopSy69bhrt8pxRsrhYgfK4y3CMVxelXU=; fh=QlPQTDiUXlEBUVsLubp5sa1HfmxIc7/7f2wx9fAzjEI=; b=ysKeTdpSjgFq9dnZWmq6/qlqBaRXniQLlaYy2apMFy2BsOesfF4TbixihQ8dibIWkH WG3ArQeFTWl4PAiFWV+yvCsyrby1TB8HSdLsMWFgSr+2S/6fUrW2ckhQRIZLXXlxLwjm FIzmbBeAKle1lZwI7W0pTwUu1hPMWvTFTYYVOozuBAFmd3bwWmoLkH57w6EcHFdidaUn 9+Wzojk2Gb6NNiLwyZLArfGI36suQG0jmNLx2t5Xv0EKWMRfPkIpzzVntZxe6FMfRt74 p2LUuJ00QRLqw4U+htNwtQsc9R+GqDDP5Eo8yzd3NYWq+T+lW4j8JZ//ZoIp3oFFpKLF 9Wfw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=cNSa8tXr; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-70581-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70581-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id c17-20020a17090abf1100b002993718977fsi3367667pjs.91.2024.02.18.12.59.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 12:59:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70581-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=@linux.dev header.s=key1 header.b=cNSa8tXr; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-70581-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70581-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 16CDF28184E for ; Sun, 18 Feb 2024 20:59:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B589B73186; Sun, 18 Feb 2024 20:58:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="cNSa8tXr" Received: from out-176.mta0.migadu.com (out-176.mta0.migadu.com [91.218.175.176]) (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 5E2ED7604F for ; Sun, 18 Feb 2024 20:57:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708289881; cv=none; b=bi3YZ6skCqItOkl9Benzb59ZEQCCOkMDLnRuusi/J/FBwoMDppJkpiU+EAadkWdrbOrnDklrpcEN7SSnIr5dT4sq0H6fEBgGus2eXeX1BR8Axcx3BCdrOeYI6V+hJtXL2T/7T/W8HyszkiTbS+7Fen6PYigJ/Jw88XTxlELTNf8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708289881; c=relaxed/simple; bh=R3BsKSBb4VGS4GVOpXyV+CdEBnSBq1bsunScPm8BKvo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gkfbpl3QqP6eYnttJSHumDE2H8Q48e5GFWFEAeu7i4tAx3D0oUGrkyI8sj1nLPXGg1eJJiNgB2rp3vTIKMwiI8QRKVw9hcxd98uKPL/9k0jkV75X9ehp2lDIrQZsmTdvq8RNoEcPPnUASO9z+ZP3D+n37D/3/1YWuq6usbt+LFw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=cNSa8tXr; arc=none smtp.client-ip=91.218.175.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Sun, 18 Feb 2024 15:57:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708289877; 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: in-reply-to:in-reply-to:references:references; bh=EdAwdrqq1gjopSy69bhrt8pxRsrhYgfK4y3CMVxelXU=; b=cNSa8tXrIg0K67WUJsYtKYxpEgNZ6dhvowvBSBxFGSSFh47PK200tMOTvcGy6T4MDO12q4 lDWB/9TzyZXQSKiOAIy2981a0s/SzsT2u2XVS4/GeU/LBE3w8eYC23x5+wL18zHh2VZCUy hIR9xeQWwA5Rcmuay329tja3A9bGqro= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Christophe JAILLET Cc: Brian Foster , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-bcachefs@vger.kernel.org Subject: Re: [PATCH v2] bcachefs: Avoid a potential useless over memory allocation in bch2_prt_[v]printf() Message-ID: References: <4c614db674887346ea418acaeafd6bf86502ec77.1708272713.git.christophe.jaillet@wanadoo.fr> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4c614db674887346ea418acaeafd6bf86502ec77.1708272713.git.christophe.jaillet@wanadoo.fr> X-Migadu-Flow: FLOW_OUT On Sun, Feb 18, 2024 at 05:12:28PM +0100, Christophe JAILLET wrote: > 2 issues related to incorrect available space in the output buffer > computation may lead to some extra memory allocation. > > > First: vsnprintf() takes the size of the buffer, *including* the space for > the trailing null. > > But printbuf_remaining() returns the number of characters we can print > to the output buffer, *excluding* the terminating null. > > So, use printbuf_remaining_size(), which includes the space for the > terminating null. > > > Second: if the return value of vsnprintf() is greater than or equal to the > passed size, the resulting string is truncated. > So, in order to see if some extra space is needed, the check needs to be > changed. > > Signed-off-by: Christophe JAILLET Thanks, applied