From: Takashi Iwai <tiwai@suse.de>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: David Laight <david.laight.linux@gmail.com>,
Junrui Luo <moonafterrain@outlook.com>,
linux-kernel@vger.kernel.org, pmladek@suse.com,
rostedt@goodmis.org, andriy.shevchenko@linux.intel.com,
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
Date: Sat, 08 Nov 2025 10:11:19 +0100 [thread overview]
Message-ID: <877bw0rirs.wl-tiwai@suse.de> (raw)
In-Reply-To: <20251107161130.4418562992d2477c4accc6ef@linux-foundation.org>
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@gmail.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
next prev parent reply other threads:[~2025-11-08 9:11 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20251107051616.21606-1-moonafterrain@outlook.com>
2025-11-07 5:16 ` [PATCH 1/4] lib/sprintf: add scnprintf_append() helper function Junrui Luo
2025-11-07 5:38 ` Andrew Morton
2025-11-07 9:12 ` David Laight
2025-11-07 9:35 ` Andy Shevchenko
2025-11-07 12:52 ` Petr Mladek
2025-11-07 17:51 ` David Laight
2025-11-10 14:13 ` Petr Mladek
2025-11-11 13:31 ` Junrui Luo
2025-11-12 9:39 ` Petr Mladek
2025-11-08 0:11 ` Andrew Morton
2025-11-08 9:11 ` Takashi Iwai [this message]
2025-11-07 9:34 ` Andy Shevchenko
2025-11-07 5:16 ` [PATCH 2/4] ALSA: wavefront: use scnprintf_append for longname construction Junrui Luo
2025-11-07 5:16 ` [PATCH 3/4] media: ivtv: use scnprintf_append for i2c adapter name Junrui Luo
2025-11-07 5:16 ` [PATCH 4/4] net: qede: use scnprintf_append for version string Junrui Luo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877bw0rirs.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=awalls@md.metrocast.net \
--cc=davem@davemloft.net \
--cc=david.laight.linux@gmail.com \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=moonafterrain@outlook.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=perex@perex.cz \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).