From: Guilhem Massol <guilhem.massol85@gmail.com>
To: kees@kernel.org
Cc: linux-kernel@vger.kernel.org,
Guilhem Massol <guilhem.massol85@gmail.com>
Subject: [PATCH] string: Use __restrict__ according to ISO/IEC 9899:TC3
Date: Sun, 3 May 2026 15:12:45 +0200 [thread overview]
Message-ID: <20260503131245.13868-1-guilhem.massol85@gmail.com> (raw)
Source: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
Some functions in lib/string.c needs to use restrict according to sections:
* 7.21.2.1: memcpy
* 7.21.2.3: strcpy
* 7.21.2.4: strncpy
* 7.21.3.1: strcat
* 7.21.3.2: strncat
Signed-off-by: Guilhem Massol <guilhem.massol85@gmail.com>
---
include/linux/string.h | 12 ++++++------
lib/string.c | 12 ++++++------
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/include/linux/string.h b/include/linux/string.h
index b850bd91b3d8..07679485104b 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -65,12 +65,12 @@ void *vmemdup_array_user(const void __user *src, size_t n, size_t size)
#include <asm/string.h>
#ifndef __HAVE_ARCH_STRCPY
-extern char * strcpy(char *,const char *);
+extern char * strcpy(char *__restrict__, const char *__restrict__);
#endif
#ifndef __HAVE_ARCH_STRNCPY
-extern char * strncpy(char *,const char *, __kernel_size_t);
+extern char * strncpy(char *__restrict__, const char *__restrict__, __kernel_size_t);
#endif
-ssize_t sized_strscpy(char *, const char *, size_t);
+ssize_t sized_strscpy(char *__restrict__, const char *__restrict__, size_t);
/*
* The 2 argument style can only be used when dst is an array with a
@@ -149,10 +149,10 @@ ssize_t sized_strscpy(char *, const char *, size_t);
CONCATENATE(__strscpy_pad, COUNT_ARGS(__VA_ARGS__))(dst, src, __VA_ARGS__)
#ifndef __HAVE_ARCH_STRCAT
-extern char * strcat(char *, const char *);
+extern char * strcat(char *__restrict__, const char *__restrict__);
#endif
#ifndef __HAVE_ARCH_STRNCAT
-extern char * strncat(char *, const char *, __kernel_size_t);
+extern char * strncat(char *__restrict__, const char *__restrict__, __kernel_size_t);
#endif
#ifndef __HAVE_ARCH_STRLCAT
extern size_t strlcat(char *, const char *, __kernel_size_t);
@@ -257,7 +257,7 @@ extern void **__memcat_p(void **a, void **b);
})
#ifndef __HAVE_ARCH_MEMCPY
-extern void * memcpy(void *,const void *,__kernel_size_t);
+extern void * memcpy(void *__restrict__, const void *__restrict__, __kernel_size_t);
#endif
#ifndef __HAVE_ARCH_MEMMOVE
extern void * memmove(void *,const void *,__kernel_size_t);
diff --git a/lib/string.c b/lib/string.c
index b632c71df1a5..9b492402ad04 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -77,7 +77,7 @@ EXPORT_SYMBOL(strcasecmp);
#endif
#ifndef __HAVE_ARCH_STRCPY
-char *strcpy(char *dest, const char *src)
+char *strcpy(char *__restrict__ dest, const char *__restrict__ src)
{
char *tmp = dest;
@@ -89,7 +89,7 @@ EXPORT_SYMBOL(strcpy);
#endif
#ifndef __HAVE_ARCH_STRNCPY
-char *strncpy(char *dest, const char *src, size_t count)
+char *strncpy(char *__restrict__ dest, const char *__restrict__ src, size_t count)
{
char *tmp = dest;
@@ -110,7 +110,7 @@ EXPORT_SYMBOL(strncpy);
# define ALLBUTLAST_BYTE_MASK (~0ul >> 8)
#endif
-ssize_t sized_strscpy(char *dest, const char *src, size_t count)
+ssize_t sized_strscpy(char *__restrict__ dest, const char *__restrict__ src, size_t count)
{
const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
size_t max = count;
@@ -215,7 +215,7 @@ char *stpcpy(char *__restrict__ dest, const char *__restrict__ src)
EXPORT_SYMBOL(stpcpy);
#ifndef __HAVE_ARCH_STRCAT
-char *strcat(char *dest, const char *src)
+char *strcat(char *__restrict__ dest, const char *__restrict__ src)
{
char *tmp = dest;
@@ -229,7 +229,7 @@ EXPORT_SYMBOL(strcat);
#endif
#ifndef __HAVE_ARCH_STRNCAT
-char *strncat(char *dest, const char *src, size_t count)
+char *strncat(char *__restrict__ dest, const char *__restrict__ src, size_t count)
{
char *tmp = dest;
@@ -618,7 +618,7 @@ EXPORT_SYMBOL(memset64);
* You should not use this function to access IO space, use memcpy_toio()
* or memcpy_fromio() instead.
*/
-void *memcpy(void *dest, const void *src, size_t count)
+void *memcpy(void *__restrict__ dest, const void *__restrict__ src, size_t count)
{
char *tmp = dest;
const char *s = src;
--
2.54.0
next reply other threads:[~2026-05-03 13:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-03 13:12 Guilhem Massol [this message]
2026-05-09 2:43 ` kernel test robot
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=20260503131245.13868-1-guilhem.massol85@gmail.com \
--to=guilhem.massol85@gmail.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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®