* [PATCH] firmware: cs_dsp: Replace strlcat() with seq_buf in KUnit tests
@ 2026-11-24 11:36 Andrey Zakharov
2026-11-24 13:59 ` Richard Fitzgerald
0 siblings, 1 reply; 2+ messages in thread
From: Andrey Zakharov @ 2026-11-24 11:36 UTC (permalink / raw)
To: simont, ckeepax, rf; +Cc: broonie, patches, linux-kernel
strlcat() is being removed from the kernel. It runs an unbounded
strlen() on the destination, and its size argument is not tied to
the real buffer, see the issue below.
The bin and wmfw tests fill a 512 byte buffer with a repeated string
by calling strlcat() in a loop, and use the return value to detect
that the buffer is full. Use seq_buf_init() and seq_buf_puts() and
stop when seq_buf_has_overflowed() is true. kunit_kzalloc() returns
a zeroed buffer, so seq_buf_init() is enough here.
Tested: built with gcc 16.2.1 and ran the cs_dsp KUnit suites under
QEMU (x86_64, kunit.py, REGMAP_BUILD): 5829 of 5829 tests pass, the
same as without the patch. The tests do not look at the contents of
the buffer, so I also checked it with a temporary assertion after the
loop: strlen(infobuf) is 511 with the old strlcat() loop and with the
new code, and the assertion fails if 510 is expected.
Not tested: other architectures and any real hardware.
Link: https://github.com/KSPP/linux/issues/370
Signed-off-by: Andrey Zakharov <dedemorow@gmail.com>
---
drivers/firmware/cirrus/test/cs_dsp_test_bin.c | 7 +++++--
drivers/firmware/cirrus/test/cs_dsp_test_wmfw.c | 7 +++++--
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/firmware/cirrus/test/cs_dsp_test_bin.c b/drivers/firmware/cirrus/test/cs_dsp_test_bin.c
index 63416838f865..2f44b7a6e637 100644
--- a/drivers/firmware/cirrus/test/cs_dsp_test_bin.c
+++ b/drivers/firmware/cirrus/test/cs_dsp_test_bin.c
@@ -17,6 +17,7 @@
#include <linux/math.h>
#include <linux/random.h>
#include <linux/regmap.h>
+#include <linux/seq_buf.h>
#include "../cs_dsp.h"
@@ -2109,6 +2110,7 @@ static void bin_patch_name_and_info(struct kunit *test)
unsigned int reg_inc_per_word = cs_dsp_mock_reg_addr_inc_per_unpacked_word(priv);
u32 reg_val, payload_data;
char *infobuf;
+ struct seq_buf sb;
unsigned int alg_base_words, reg_addr;
struct firmware *fw;
@@ -2126,8 +2128,9 @@ static void bin_patch_name_and_info(struct kunit *test)
infobuf = kunit_kzalloc(test, 512, GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, infobuf);
- for (; strlcat(infobuf, "Waffle{Blah}\n", 512) < 512; )
- ;
+ seq_buf_init(&sb, infobuf, 512);
+ while (!seq_buf_has_overflowed(&sb))
+ seq_buf_puts(&sb, "Waffle{Blah}\n");
cs_dsp_mock_bin_add_info(priv->local->bin_builder, infobuf);
diff --git a/drivers/firmware/cirrus/test/cs_dsp_test_wmfw.c b/drivers/firmware/cirrus/test/cs_dsp_test_wmfw.c
index 1de70e81a868..464a0cc79415 100644
--- a/drivers/firmware/cirrus/test/cs_dsp_test_wmfw.c
+++ b/drivers/firmware/cirrus/test/cs_dsp_test_wmfw.c
@@ -16,6 +16,7 @@
#include <linux/firmware/cirrus/wmfw.h>
#include <linux/random.h>
#include <linux/regmap.h>
+#include <linux/seq_buf.h>
#include <linux/string.h>
#include <linux/vmalloc.h>
@@ -1722,6 +1723,7 @@ static void wmfw_load_with_info(struct kunit *test)
unsigned int reg_addr;
u8 *payload_data, *readback;
char *infobuf;
+ struct seq_buf sb;
const unsigned int payload_size_bytes = 48;
int ret;
@@ -1745,8 +1747,9 @@ static void wmfw_load_with_info(struct kunit *test)
infobuf = kunit_kzalloc(test, 512, GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, infobuf);
- for (; strlcat(infobuf, "Waffle{Blah}\n", 512) < 512;)
- ;
+ seq_buf_init(&sb, infobuf, 512);
+ while (!seq_buf_has_overflowed(&sb))
+ seq_buf_puts(&sb, "Waffle{Blah}\n");
cs_dsp_mock_wmfw_add_info(local->wmfw_builder, infobuf);
cs_dsp_mock_wmfw_add_info(local->wmfw_builder, "Another block of info");
--
2.56.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] firmware: cs_dsp: Replace strlcat() with seq_buf in KUnit tests
2026-11-24 11:36 [PATCH] firmware: cs_dsp: Replace strlcat() with seq_buf in KUnit tests Andrey Zakharov
@ 2026-11-24 13:59 ` Richard Fitzgerald
0 siblings, 0 replies; 2+ messages in thread
From: Richard Fitzgerald @ 2026-11-24 13:59 UTC (permalink / raw)
To: Andrey Zakharov, broonie; +Cc: patches, linux-kernel, ckeepax, simont
On 24/11/2026 11:36 am, Andrey Zakharov wrote:
> strlcat() is being removed from the kernel. It runs an unbounded
> strlen() on the destination, and its size argument is not tied to
> the real buffer, see the issue below.
>
> The bin and wmfw tests fill a 512 byte buffer with a repeated string
> by calling strlcat() in a loop, and use the return value to detect
> that the buffer is full. Use seq_buf_init() and seq_buf_puts() and
> stop when seq_buf_has_overflowed() is true. kunit_kzalloc() returns
> a zeroed buffer, so seq_buf_init() is enough here.
Reviewed-by: Richard Fitzgerald <rf@opensource.cirrus.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-24 14:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 11:36 [PATCH] firmware: cs_dsp: Replace strlcat() with seq_buf in KUnit tests Andrey Zakharov
2026-11-24 13:59 ` Richard Fitzgerald
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®