From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3C5230F7F7 for ; Mon, 10 Nov 2025 14:14:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762784042; cv=none; b=EdCyOaOEb+Lk7qkN8KhdmfSSfTS0RlBLp69Et1RSLdALLRvbPlXikf5KbAfx9TeZTgHySaIMqgacfetZmZ59p5GZAaHzTG/K42qMwc8MQJZkKkcE7HHUyZNbWbVLM1ndaNas4sx1K+VSDSCOwSdwZTmyvmJTNiPMTn606AWxSR0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762784042; c=relaxed/simple; bh=nhj3Igbx12WySTAs3L6CZE8fbVP3gkRxrlKpU0V1S2w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BVSQK9owGhDX42PpMr9b54qFYH6fUliH/0VQB9LWUpdSGB2togbabMyQvtz9j7/1geqVQpUzzghoxurhO4eui2Qx4dyCQYohejQkjbPBZMz3FK1D2aNiMwDVtwTWL4sCOiilzcJyfrajHUaUKTthRW2LqPMtvfg0/c8x3isbGNg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=QshNdn8y; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="QshNdn8y" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-b729a941e35so383265766b.3 for ; Mon, 10 Nov 2025 06:14:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1762784039; x=1763388839; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=MYf9FpLZWUf42lAhUlxsk+V48xYQlFSQ2G8JV6jPPvE=; b=QshNdn8yQ7FchSFTx7qcHFGVopt7Fd31yJBamIE8scdUsKrK/Dl1wesxzuiw1aqwxw fA/KZZckMgyCowdFY8JB/HTMTraHBXYKDxp3G0h4p8MwKLJKR5gD8iuVHN0pF642sdZe 35kwMDAl2kDoP9y0NDtIAln4A7XoOOIzGpAGgABYPj58EL6qhnVIyeyRjKWvq3jb/i/0 v1SPcux9ZbAl7ofXlfFewNgib5lDR7/+CHOxRVJMToN5jiokP/6QbncOOyYPgBILY3s7 8yMZZnIFGt0Fyiz4VYERDzIaYTR6O1a0NTGIn7nus2e95TP3UtcrIGYg0nAjFpqxtAxQ eBgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762784039; x=1763388839; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MYf9FpLZWUf42lAhUlxsk+V48xYQlFSQ2G8JV6jPPvE=; b=r6Ns5UpELSkR/NKNnNhVXNvOfJfYPCkFVGxOabU2mmOSdapdjGS+DuyFgGRtCr2bs4 JYKYnyOn4VSZ0kBOOeXF6oRdfsdMVfgl9pAWTczX5pvggvTV27ZBAYA8elaUU1Elcs+9 sszuam949otaEO6T/GYBhFY0GIXpuNX1/oL00NVtVxOF21jkzVNpmUTlstLEgvpWg1LA bLlkSN3CVNjzv0VE8YnYBfAzoOmzVPmDIATA/lBGZo8Wzhqbmo2iQ+MIqbfoQrxcgmJ/ YwUN6ReHUtuKMimIlXPCUWh5EUV1htSjhOYVpvZUaGlM8ycwdU9448dw7x/7TCI4F3x0 afbA== X-Forwarded-Encrypted: i=1; AJvYcCXAY2zJC2Oawod19EasjrAGPGM/ivChfGtkWfckJLmuf5ZqxY6yR7VKJjDpGn0MMEoBe3M4BpiBjDFPuQ==@vger.kernel.org X-Gm-Message-State: AOJu0YwonvdDSywu5eUlroxHnBTxIrKm3PxcphHzGQdkdggLXaGMVXYx XxkhAJdjQxKsILY7zoFQXYKXiyJXGUuXtn15eGLpsC68mS8DlSU4rCV5ubRx9Hu+oVI= X-Gm-Gg: ASbGncvL8MuCyczG7OMyqiHeA/ONmpCM/5fL3YZyWadKDxglrpDS1J8Pr166Jgp0wXZ Hzn6TIrpitSEHsjScr8jiCYZWdPCs/Ak38awo/QeXOuv+i4WZAknh4NJrw5o9TGTefS5U8nM3MJ mlGxk4XIDXhhrsuhgO+2NCrjRQUM7ZHf6hyi/4J3a3M6HhipMCqurJY+0ziTcklmTMgOBW/kNK/ 8omqUafk2NXTeNHLMpDKeErSXsj9XUPjFMNLOne++GZsl/m/GEwJdFF/EttyNlO3AHcxe1k0s4j j8vCCT6U83hMkMdw/fifdAbp31XiyOydWKW+RmlPtYG26ujOsliWufdKrwcy5Kv0FOWDiv6+0JF p5JpeyzhV7iGvF4ifEnTgGuNEj7FUOiLu7P/JJOmzn4IxCGQ+k463e3J8iPluJNyig6arE4dwtd XDXuc= X-Google-Smtp-Source: AGHT+IFWGbbWVSdwsSwRLLUACXXxYZpMnpmrI0HtAU0yQT12wD1kfbTgpMWg/xPH1FaG58xVuN8lew== X-Received: by 2002:a17:907:a0c8:b0:b3f:9b9c:d49e with SMTP id a640c23a62f3a-b72e053f2b5mr824285466b.57.1762784039128; Mon, 10 Nov 2025 06:13:59 -0800 (PST) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b72bf407a01sm1105466366b.22.2025.11.10.06.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 06:13:58 -0800 (PST) Date: Mon, 10 Nov 2025 15:13:56 +0100 From: Petr Mladek To: David Laight Cc: Andy Shevchenko , Andrew Morton , Junrui Luo , linux-kernel@vger.kernel.org, rostedt@goodmis.org, tiwai@suse.com, perex@perex.cz, linux-sound@vger.kernel.org, mchehab@kernel.org, awalls@md.metrocast.net, linux-media@vger.kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org Subject: Re: [PATCH 1/4] lib/sprintf: add scnprintf_append() helper function Message-ID: References: <20251107051616.21606-1-moonafterrain@outlook.com> <20251106213833.546c8eaba8aec6aa6a5e30b6@linux-foundation.org> <20251107091246.4e5900f4@pumpkin> <20251107175123.70ded89e@pumpkin> Precedence: bulk X-Mailing-List: linux-sound@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: <20251107175123.70ded89e@pumpkin> On Fri 2025-11-07 17:51:23, David Laight wrote: > On Fri, 7 Nov 2025 13:52:27 +0100 > Petr Mladek wrote: > > > On Fri 2025-11-07 11:35:35, Andy Shevchenko wrote: > > > On Fri, Nov 07, 2025 at 09:12:46AM +0000, David Laight wrote: > > > > On Thu, 6 Nov 2025 21:38:33 -0800 > > > > Andrew Morton wrote: > > > > > On Fri, 7 Nov 2025 13:16:13 +0800 Junrui Luo wrote: > > > > > > ... > > > > > > > That is true for all the snprintf() functions. > > > > > > > > > I wonder if we should instead implement a kasprintf() version of this > > > > > which reallocs each time and then switch all the callers over to that. > > > > > > > > That adds the cost of a malloc, and I, like kasprintf() probably ends up > > > > doing all the work of snprintf twice. > > > > > > > > I'd be tempted to avoid the strlen() by passing in the offset. > > > > So (say): > > > > #define scnprintf_at(buf, len, off, ...) \ > > > > scnprintf((buf) + off, (len) - off, __VA_ARGS__) > > > > It does not handle correctly the situation when len < off. > > Othersise, it looks good. > > That shouldn't happen unless the calling code is really buggy. > There is also a WARN_ON_ONCE() at the top of snprintf(). Fair enough. BTW: I have found there exists a userspace library which implements this idea, the funtion is called vsnoprintf(), see https://arpa2.gitlab.io/arpa2common/group__snoprintf.html I know that it is cryptic. But I like the name. The letters "no" match the ordering of the parameters "size, offset". In our case, it would be scnoprintf() ... Best Regards, Petr