From: Richard Fitzgerald <rf@opensource.cirrus.com>
To: "Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
"Simon Trimmer" <simont@opensource.cirrus.com>,
"Charles Keepax" <ckeepax@opensource.cirrus.com>,
"Mark Brown" <broonie@kernel.org>
Cc: <patches@opensource.cirrus.com>, <linux-kernel@vger.kernel.org>,
<stable@vger.kernel.org>
Subject: Re: [PATCH] firmware: cs_dsp: test_control_parse: null-terminate test strings
Date: Tue, 11 Feb 2025 15:10:38 +0000 [thread overview]
Message-ID: <d1c9a0f3-5bc5-4b78-abfa-d17e90c36f48@opensource.cirrus.com> (raw)
In-Reply-To: <20250211-cs_dsp-kunit-strings-v1-1-d9bc2035d154@linutronix.de>
On 11/02/2025 3:00 pm, Thomas Weißschuh wrote:
> The char pointers in 'struct cs_dsp_mock_coeff_def' are expected to
> point to C strings. They need to be terminated by a null byte.
> However the code does not allocate that trailing null byte and only
> works if by chance the allocation is followed by such a null byte.
>
> Refactor the repeated string allocation logic into a new helper which
> makes sure the terminating null is always present.
> It also makes the code more readable.
>
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> Fixes: 83baecd92e7c ("firmware: cs_dsp: Add KUnit testing of control parsing")
> Cc: stable@vger.kernel.org
> ---
> .../cirrus/test/cs_dsp_test_control_parse.c | 51 ++++++++--------------
> 1 file changed, 19 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/firmware/cirrus/test/cs_dsp_test_control_parse.c b/drivers/firmware/cirrus/test/cs_dsp_test_control_parse.c
> index cb90964740ea351113dac274f0366de7cedfd3d1..942ba1af5e7c1e47e8a2fbe548a7993b94f96515 100644
> --- a/drivers/firmware/cirrus/test/cs_dsp_test_control_parse.c
> +++ b/drivers/firmware/cirrus/test/cs_dsp_test_control_parse.c
> @@ -73,6 +73,18 @@ static const struct cs_dsp_mock_coeff_def mock_coeff_template = {
> .length_bytes = 4,
> };
>
> +static char *cs_dsp_ctl_alloc_test_string(struct kunit *test, char c, size_t len)
> +{
> + char *str;
> +
> + str = kunit_kmalloc(test, len + 1, GFP_KERNEL);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, str);
> + memset(str, c, len);
> + str[len] = '\0';
> +
> + return str;
> +}
> +
> /* Algorithm info block without controls should load */
> static void cs_dsp_ctl_parse_no_coeffs(struct kunit *test)
> {
> @@ -160,12 +172,8 @@ static void cs_dsp_ctl_parse_max_v1_name(struct kunit *test)
> struct cs_dsp_mock_coeff_def def = mock_coeff_template;
> struct cs_dsp_coeff_ctl *ctl;
> struct firmware *wmfw;
> - char *name;
>
> - name = kunit_kzalloc(test, 256, GFP_KERNEL);
This allocates 256 bytes of zero-filled memory...
> - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, name);
> - memset(name, 'A', 255);
... and this fills the first 255 bytes, leaving the last byte still as
zero. So the string is zero-terminated. I don't see a problem here.
Just fix the other allocs to be kzalloc with the correct length?
next prev parent reply other threads:[~2025-02-11 15:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-11 15:00 Thomas Weißschuh
2025-02-11 15:10 ` Richard Fitzgerald [this message]
2025-02-11 15:21 ` Thomas Weißschuh
2025-02-11 16:30 ` Richard Fitzgerald
2025-02-19 15:18 ` Richard Fitzgerald
2025-02-20 22:21 ` Mark Brown
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=d1c9a0f3-5bc5-4b78-abfa-d17e90c36f48@opensource.cirrus.com \
--to=rf@opensource.cirrus.com \
--cc=broonie@kernel.org \
--cc=ckeepax@opensource.cirrus.com \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=simont@opensource.cirrus.com \
--cc=stable@vger.kernel.org \
--cc=thomas.weissschuh@linutronix.de \
/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
all inboxes | Powered by JetHome®