]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
string: use min in sized_strscpy
authorThorsten Blum <thorsten.blum@linux.dev>
Thu, 14 May 2026 16:56:03 +0000 (18:56 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 29 May 2026 04:24:58 +0000 (21:24 -0700)
Use min() and drop the limit variable to simplify sized_strscpy().

Link: https://lore.kernel.org/20260514165601.527883-3-thorsten.blum@linux.dev
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Cc: Andy Shevchenko <andy@kernel.org>
Cc: Kees Cook <kees@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
lib/string.c

index b632c71df1a5061256f556c40a30587cf45dce18..1f9297e9776a9983b81980a03a016db3860b8a42 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/errno.h>
 #include <linux/limits.h>
 #include <linux/linkage.h>
+#include <linux/minmax.h>
 #include <linux/stddef.h>
 #include <linux/string.h>
 #include <linux/types.h>
@@ -125,11 +126,8 @@ ssize_t sized_strscpy(char *dest, const char *src, size_t count)
         * If src is unaligned, don't cross a page boundary,
         * since we don't know if the next page is mapped.
         */
-       if ((long)src & (sizeof(long) - 1)) {
-               size_t limit = PAGE_SIZE - ((long)src & (PAGE_SIZE - 1));
-               if (limit < max)
-                       max = limit;
-       }
+       if ((long)src & (sizeof(long) - 1))
+               max = min(PAGE_SIZE - ((long)src & (PAGE_SIZE - 1)), max);
 #else
        /* If src or dest is unaligned, don't do word-at-a-time. */
        if (((long) dest | (long) src) & (sizeof(long) - 1))