lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <877bw0rirs.wl-tiwai@suse.de>
Date: Sat, 08 Nov 2025 10:11:19 +0100
From: Takashi Iwai <tiwai@...e.de>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: David Laight <david.laight.linux@...il.com>,
	Junrui Luo <moonafterrain@...look.com>,
	linux-kernel@...r.kernel.org,
	pmladek@...e.com,
	rostedt@...dmis.org,
	andriy.shevchenko@...ux.intel.com,
	tiwai@...e.com,
	perex@...ex.cz,
	linux-sound@...r.kernel.org,
	mchehab@...nel.org,
	awalls@...metrocast.net,
	linux-media@...r.kernel.org,
	davem@...emloft.net,
	edumazet@...gle.com,
	kuba@...nel.org,
	pabeni@...hat.com,
	netdev@...r.kernel.org
Subject: Re: [PATCH 1/4] lib/sprintf: add scnprintf_append() helper function

On Sat, 08 Nov 2025 01:11:30 +0100,
Andrew Morton wrote:
> 
> On Fri, 7 Nov 2025 09:12:46 +0000 David Laight <david.laight.linux@...il.com> wrote:
> 
> > > 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.
> 
> There is no need at all to optimize the performance of scruffy once-off
> string pasting functions.  For these it's better to optimize for
> readability, reliability.  maintainability.

Actually this scnprintf_append() helper was my suggestion in another
threads:
  https://lore.kernel.org/ME2PR01MB3156CEC4F31F253C9B540FB7AFFDA@ME2PR01MB3156.ausprd01.prod.outlook.com
  https://lore.kernel.org/SYBPR01MB7881987D79C62D8122B655FEAFC6A@SYBPR01MB7881.ausprd01.prod.outlook.com

Basically its use is for filling a substring with s*printf() inside a
fixed string such as a field in a struct.  Through a quick grep, there
are many kernel code doing it without bounce checks, and it's for
helping those.  So it's a bit different from what you assumed with the
re-allocatable buffers.

The most merit of this API is that it can just be a kind of drop-in
replacement without extra variable to keep the offset, as found in
this patch series.

Though, it won't change too much to introduce an offset variable as
the API David suggested, which looks nice, so I myself don't mind
either way (it's a bike-shed topic, after all :)


thanks,

Takashi

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ