* [PATCH] string: Add missing const
@ 2026-11-25 18:26 Alejandro Colomar
2026-11-26 15:20 ` Andy Shevchenko
0 siblings, 1 reply; 5+ messages in thread
From: Alejandro Colomar @ 2026-11-25 18:26 UTC (permalink / raw)
To: Kees Cook, linux-hardening; +Cc: Alejandro Colomar, Andy Shevchenko
[-- Attachment #1: Type: text/plain, Size: 797 bytes --]
This pointer is derived from other const pointers.
Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
Hi,
This was found while changing some <linux/string.h> APIs to preserve the
const qualifier in the return type.
Have a lovely night!
Alex
lib/tests/string_kunit.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/tests/string_kunit.c b/lib/tests/string_kunit.c
index f84a60d4414c..2b681089c200 100644
--- a/lib/tests/string_kunit.c
+++ b/lib/tests/string_kunit.c
@@ -233,7 +233,7 @@ static void string_test_strnchr(struct kunit *test)
{
const char *test_string = "abcdefghijkl";
const char *empty_string = "";
- char *result;
+ const char *result;
int i, j;
for (i = 0; i < strlen(test_string) + 1; i++) {
--
2.55.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] string: Add missing const
2026-11-25 18:26 [PATCH] string: Add missing const Alejandro Colomar
@ 2026-11-26 15:20 ` Andy Shevchenko
2026-11-26 15:55 ` Alejandro Colomar
0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2026-11-26 15:20 UTC (permalink / raw)
To: Alejandro Colomar; +Cc: Kees Cook, linux-hardening, Andy Shevchenko
On Wed, Nov 25, 2026 at 07:26:38PM +0100, Alejandro Colomar wrote:
> This pointer is derived from other const pointers.
Constification almost always is a good thing, if this builds and works as
expected,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] string: Add missing const
2026-11-26 15:20 ` Andy Shevchenko
@ 2026-11-26 15:55 ` Alejandro Colomar
2026-11-26 20:51 ` Andy Shevchenko
0 siblings, 1 reply; 5+ messages in thread
From: Alejandro Colomar @ 2026-11-26 15:55 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Alejandro Colomar, Kees Cook, linux-hardening, Andy Shevchenko
[-- Attachment #1: Type: text/plain, Size: 629 bytes --]
Hi Andy,
> Date: 2026-11-26 17:20:11+0200
> From: Andy Shevchenko <andriy.shevchenko@intel.com>
>
> On Wed, Nov 25, 2026 at 07:26:38PM +0100, Alejandro Colomar wrote:
> > This pointer is derived from other const pointers.
>
> Constification almost always is a good thing, if this builds and works as
> expected,
Yup, I built it as part of a larger branch. I didn't run the tests,
but this should be a compile-time-only thing, so I don't think it's
necessary.
>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Thanks!
Have a lovely day!
Alex
--
<https://www.alejandro-colomar.es>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] string: Add missing const
2026-11-26 15:55 ` Alejandro Colomar
@ 2026-11-26 20:51 ` Andy Shevchenko
2026-11-26 21:49 ` Alejandro Colomar
0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2026-11-26 20:51 UTC (permalink / raw)
To: Alejandro Colomar
Cc: Alejandro Colomar, Kees Cook, linux-hardening, Andy Shevchenko
On Thu, Nov 26, 2026 at 04:55:07PM +0100, Alejandro Colomar wrote:
> > On Wed, Nov 25, 2026 at 07:26:38PM +0100, Alejandro Colomar wrote:
> > > This pointer is derived from other const pointers.
> >
> > Constification almost always is a good thing, if this builds and works as
> > expected,
>
> Yup, I built it as part of a larger branch. I didn't run the tests,
> but this should be a compile-time-only thing, so I don't think it's
> necessary.
Running kunit test is so-o easy! Just run
./tools/testing/kunit/kunit.py run string
It will fail if compilation fails, so it's 2-in-1.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] string: Add missing const
2026-11-26 20:51 ` Andy Shevchenko
@ 2026-11-26 21:49 ` Alejandro Colomar
0 siblings, 0 replies; 5+ messages in thread
From: Alejandro Colomar @ 2026-11-26 21:49 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Alejandro Colomar, Kees Cook, linux-hardening, Andy Shevchenko
[-- Attachment #1: Type: text/plain, Size: 5092 bytes --]
Hi Andy,
> Date: 2026-11-26 22:51:57+0200
> From: Andy Shevchenko <andriy.shevchenko@intel.com>
>
> On Thu, Nov 26, 2026 at 04:55:07PM +0100, Alejandro Colomar wrote:
> > > On Wed, Nov 25, 2026 at 07:26:38PM +0100, Alejandro Colomar wrote:
> > > > This pointer is derived from other const pointers.
> > >
> > > Constification almost always is a good thing, if this builds and works as
> > > expected,
> >
> > Yup, I built it as part of a larger branch. I didn't run the tests,
> > but this should be a compile-time-only thing, so I don't think it's
> > necessary.
>
> Running kunit test is so-o easy! Just run
>
> ./tools/testing/kunit/kunit.py run string
>
> It will fail if compilation fails, so it's 2-in-1.
I've passed the tests now; see below.
Have a lovely night!
Alex
$ git log -1
commit 9331ce2afba1a44bb84f371581478a9ac5ee7380 (HEAD -> qchar)
Author: Alejandro Colomar <alx@kernel.org>
Date: 2026-11-25 19:25:10 +0100
string: Add missing const
This pointer is derived from other const pointers.
Signed-off-by: Alejandro Colomar <alx@kernel.org>
$ cp ../kunitconfig .kunitconfig
$ cat .kunitconfig
CONFIG_KUNIT=y
CONFIG_STRING_KUNIT_TEST=y
$ mkdir -p ~/tmp/const-string1
$ export TMPDIR=$HOME/tmp/const-string1/
$ ./tools/testing/kunit/kunit.py run "string*"
[22:47:41] Configuring KUnit Kernel ...
Generating .config ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
[22:47:44] Building KUnit Kernel ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
Building with:
$ make all compile_commands.json scripts_gdb ARCH=um O=.kunit --jobs=24
../drivers/base/dd.c: In function ‘__device_set_driver_override’:
../drivers/base/dd.c:406:20: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
406 | cp = strnchr(s, len, '\n');
| ^
[22:48:01] Starting KUnit Kernel (1/1)...
[22:48:01] ============================================================
Running tests with:
$ .kunit/linux 'kunit.filter_glob=string*' kunit.enable=1 mem=1G console=tty kunit_shutdown=halt
[22:48:02] ============= string-stream-test (12 subtests) =============
[22:48:02] [PASSED] string_stream_managed_init_test
[22:48:02] [PASSED] string_stream_unmanaged_init_test
[22:48:02] [PASSED] string_stream_managed_free_test
[22:48:02] [PASSED] string_stream_resource_free_test
[22:48:02] [PASSED] string_stream_line_add_test
[22:48:02] [PASSED] string_stream_variable_length_line_test
[22:48:02] [PASSED] string_stream_append_test
[22:48:02] [PASSED] string_stream_append_auto_newline_test
[22:48:02] [PASSED] string_stream_append_empty_string_test
[22:48:02] [PASSED] string_stream_no_auto_newline_test
[22:48:02] [PASSED] string_stream_auto_newline_test
[22:48:02] [PASSED] string_stream_performance_test
[22:48:02] =============== [PASSED] string-stream-test ================
[22:48:02] =================== string (29 subtests) ===================
[22:48:02] [PASSED] string_test_memset16
[22:48:02] [PASSED] string_test_memset32
[22:48:02] [PASSED] string_test_memset64
[22:48:02] [PASSED] string_test_strlen
[22:48:02] [PASSED] string_test_strnlen
[22:48:02] [PASSED] string_test_strchr
[22:48:02] [PASSED] string_test_strnchr
[22:48:02] [PASSED] string_test_strrchr
[22:48:02] [PASSED] string_test_strspn
[22:48:02] [PASSED] string_test_streq
[22:48:02] [PASSED] string_test_strcmp
[22:48:02] [PASSED] string_test_strcmp_long_strings
[22:48:02] [PASSED] string_test_strncmp
[22:48:02] [PASSED] string_test_strncmp_long_strings
[22:48:02] [PASSED] string_test_strcasecmp
[22:48:02] [PASSED] string_test_strcasecmp_long_strings
[22:48:02] [PASSED] string_test_strncasecmp
[22:48:02] [PASSED] string_test_strncasecmp_long_strings
[22:48:02] [PASSED] string_test_strscpy
[22:48:02] [PASSED] string_test_strcat
[22:48:02] [PASSED] string_test_strncat
[22:48:02] [PASSED] string_test_strlcat
[22:48:02] [PASSED] string_test_strtomem
[22:48:02] [PASSED] string_test_memtostr
[22:48:02] [PASSED] string_test_strends
[22:48:02] [SKIPPED] string_bench_strlen (not enabled)
[22:48:02] [SKIPPED] string_bench_strnlen (not enabled)
[22:48:02] [SKIPPED] string_bench_strchr (not enabled)
[22:48:02] [SKIPPED] string_bench_strrchr (not enabled)
[22:48:02] ===================== [PASSED] string ======================
[22:48:02] =============== string_helpers (4 subtests) ================
[22:48:02] [PASSED] test_get_size
[22:48:02] [PASSED] test_upper_lower
[22:48:02] [PASSED] test_unescape
[22:48:02] [PASSED] test_escape
[22:48:02] ================= [PASSED] string_helpers ==================
[22:48:02] ============================================================
[22:48:02] Testing complete. Ran 45 tests: passed: 41, skipped: 4
[22:48:02] Elapsed time: 20.674s total, 3.447s configuring, 17.058s building, 0.128s running
--
<https://www.alejandro-colomar.es>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-26 21:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 18:26 [PATCH] string: Add missing const Alejandro Colomar
2026-11-26 15:20 ` Andy Shevchenko
2026-11-26 15:55 ` Alejandro Colomar
2026-11-26 20:51 ` Andy Shevchenko
2026-11-26 21:49 ` Alejandro Colomar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox