From: David Laight <david.laight.linux@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
Kees Cook <kees@kernel.org>, Andy Shevchenko <andy@kernel.org>,
linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] lib/string_helpers: drop redundant allocation in kasprintf_strarray
Date: Wed, 15 Apr 2026 19:38:52 +0100 [thread overview]
Message-ID: <20260415193852.3171301b@pumpkin> (raw)
In-Reply-To: <ad-j4eGpltrb-WQj@ashevche-desk.local>
On Wed, 15 Apr 2026 17:42:41 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> On Wed, Apr 15, 2026 at 02:25:43PM +0200, Thorsten Blum wrote:
> > kasprintf_strarray() returns an array of N strings and kfree_strarray()
> > also frees N entries. However, kasprintf_strarray() currently allocates
> > N+1 char pointers. Allocate exactly N pointers instead of N+1.
> >
> > Also update the kernel-doc for @n.
>
> Have you checked all current users that they do not rely on the NULL terminated
> array?
>
> Note, that was done on purpose that once allocated it can allow user
> to drop the track of the number of strings and rely on NULL terminator.
> I.o.w. the number of strings may be just a local variable somewhere
> where kasprintf_strarray() is called.
>
> I tend to NAK this change, rather you can update kernel-doc to explain
> why it's done this way (see above).
>
It isn't as though it is going to make much difference to the memory
footprint.
Allocating an extra trailing NULL is just a bit safer.
David
prev parent reply other threads:[~2026-04-15 18:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-15 12:25 [PATCH 1/2] lib/string_helpers: drop redundant allocation in kasprintf_strarray Thorsten Blum
2026-04-15 12:25 ` [PATCH 2/2] lib/string_helpers: annotate struct strarray with __counted_by_ptr Thorsten Blum
2026-04-15 14:42 ` [PATCH 1/2] lib/string_helpers: drop redundant allocation in kasprintf_strarray Andy Shevchenko
2026-04-15 15:30 ` Thorsten Blum
2026-04-16 7:48 ` Andy Shevchenko
2026-04-30 14:39 ` Thorsten Blum
2026-04-15 18:38 ` David Laight [this message]
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=20260415193852.3171301b@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=thorsten.blum@linux.dev \
/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