* [PATCH v1 1/1] string: Group str_has_prefix() and strstarts()
@ 2025-07-11 8:55 Andy Shevchenko
2025-07-15 5:24 ` Kees Cook
2025-07-17 23:40 ` Kees Cook
0 siblings, 2 replies; 5+ messages in thread
From: Andy Shevchenko @ 2025-07-11 8:55 UTC (permalink / raw)
To: linux-hardening, linux-kernel; +Cc: Kees Cook, Andy Shevchenko, Andy Shevchenko
The two str_has_prefix() and strstarts() are about the same
with a slight difference on what they return. Group them in
the header.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/string.h | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/include/linux/string.h b/include/linux/string.h
index 01621ad0f598..fdd3442c6bcb 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -345,16 +345,6 @@ extern ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,
int ptr_to_hashval(const void *ptr, unsigned long *hashval_out);
-/**
- * strstarts - does @str start with @prefix?
- * @str: string to examine
- * @prefix: prefix to look for.
- */
-static inline bool strstarts(const char *str, const char *prefix)
-{
- return strncmp(str, prefix, strlen(prefix)) == 0;
-}
-
size_t memweight(const void *ptr, size_t bytes);
/**
@@ -562,4 +552,14 @@ static __always_inline size_t str_has_prefix(const char *str, const char *prefix
return strncmp(str, prefix, len) == 0 ? len : 0;
}
+/**
+ * strstarts - does @str start with @prefix?
+ * @str: string to examine
+ * @prefix: prefix to look for.
+ */
+static inline bool strstarts(const char *str, const char *prefix)
+{
+ return strncmp(str, prefix, strlen(prefix)) == 0;
+}
+
#endif /* _LINUX_STRING_H_ */
--
2.47.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v1 1/1] string: Group str_has_prefix() and strstarts()
2025-07-11 8:55 [PATCH v1 1/1] string: Group str_has_prefix() and strstarts() Andy Shevchenko
@ 2025-07-15 5:24 ` Kees Cook
2025-07-15 6:52 ` Andy Shevchenko
2025-07-17 23:40 ` Kees Cook
1 sibling, 1 reply; 5+ messages in thread
From: Kees Cook @ 2025-07-15 5:24 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: linux-hardening, linux-kernel, Andy Shevchenko
On Fri, Jul 11, 2025 at 11:55:14AM +0300, Andy Shevchenko wrote:
> The two str_has_prefix() and strstarts() are about the same
> with a slight difference on what they return. Group them in
> the header.
It seems more like strstarts should just be a macro around
str_has_prefix() != 0?
-Kees
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> include/linux/string.h | 20 ++++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/include/linux/string.h b/include/linux/string.h
> index 01621ad0f598..fdd3442c6bcb 100644
> --- a/include/linux/string.h
> +++ b/include/linux/string.h
> @@ -345,16 +345,6 @@ extern ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,
>
> int ptr_to_hashval(const void *ptr, unsigned long *hashval_out);
>
> -/**
> - * strstarts - does @str start with @prefix?
> - * @str: string to examine
> - * @prefix: prefix to look for.
> - */
> -static inline bool strstarts(const char *str, const char *prefix)
> -{
> - return strncmp(str, prefix, strlen(prefix)) == 0;
> -}
> -
> size_t memweight(const void *ptr, size_t bytes);
>
> /**
> @@ -562,4 +552,14 @@ static __always_inline size_t str_has_prefix(const char *str, const char *prefix
> return strncmp(str, prefix, len) == 0 ? len : 0;
> }
>
> +/**
> + * strstarts - does @str start with @prefix?
> + * @str: string to examine
> + * @prefix: prefix to look for.
> + */
> +static inline bool strstarts(const char *str, const char *prefix)
> +{
> + return strncmp(str, prefix, strlen(prefix)) == 0;
> +}
> +
> #endif /* _LINUX_STRING_H_ */
> --
> 2.47.2
>
--
Kees Cook
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1 1/1] string: Group str_has_prefix() and strstarts()
2025-07-15 5:24 ` Kees Cook
@ 2025-07-15 6:52 ` Andy Shevchenko
2025-07-15 6:53 ` Andy Shevchenko
0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2025-07-15 6:52 UTC (permalink / raw)
To: Kees Cook; +Cc: Andy Shevchenko, linux-hardening, linux-kernel, Andy Shevchenko
On Tue, Jul 15, 2025 at 8:24 AM Kees Cook <kees@kernel.org> wrote:
>
> On Fri, Jul 11, 2025 at 11:55:14AM +0300, Andy Shevchenko wrote:
> > The two str_has_prefix() and strstarts() are about the same
> > with a slight difference on what they return. Group them in
> > the header.
>
> It seems more like strstarts should just be a macro around
> str_has_prefix() != 0?
This change is only about grouping, but if you think it worth
modifying, I am not going to object. Just that I am about to have my
vacation and I leave this as is for now. Up to you how to proceed.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1 1/1] string: Group str_has_prefix() and strstarts()
2025-07-15 6:52 ` Andy Shevchenko
@ 2025-07-15 6:53 ` Andy Shevchenko
0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2025-07-15 6:53 UTC (permalink / raw)
To: Kees Cook; +Cc: Andy Shevchenko, linux-hardening, linux-kernel, Andy Shevchenko
On Tue, Jul 15, 2025 at 9:52 AM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Tue, Jul 15, 2025 at 8:24 AM Kees Cook <kees@kernel.org> wrote:
> >
> > On Fri, Jul 11, 2025 at 11:55:14AM +0300, Andy Shevchenko wrote:
> > > The two str_has_prefix() and strstarts() are about the same
> > > with a slight difference on what they return. Group them in
> > > the header.
> >
> > It seems more like strstarts should just be a macro around
> > str_has_prefix() != 0?
Actually this won't work for len == 0, would it?
> This change is only about grouping, but if you think it worth
> modifying, I am not going to object. Just that I am about to have my
> vacation and I leave this as is for now. Up to you how to proceed.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1 1/1] string: Group str_has_prefix() and strstarts()
2025-07-11 8:55 [PATCH v1 1/1] string: Group str_has_prefix() and strstarts() Andy Shevchenko
2025-07-15 5:24 ` Kees Cook
@ 2025-07-17 23:40 ` Kees Cook
1 sibling, 0 replies; 5+ messages in thread
From: Kees Cook @ 2025-07-17 23:40 UTC (permalink / raw)
To: linux-hardening, linux-kernel, Andy Shevchenko; +Cc: Kees Cook, Andy Shevchenko
On Fri, 11 Jul 2025 11:55:14 +0300, Andy Shevchenko wrote:
> The two str_has_prefix() and strstarts() are about the same
> with a slight difference on what they return. Group them in
> the header.
>
>
Applied to for-next/hardening, thanks!
[1/1] string: Group str_has_prefix() and strstarts()
https://git.kernel.org/kees/c/2d8ae9a4f1bc
Take care,
--
Kees Cook
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-07-17 23:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-11 8:55 [PATCH v1 1/1] string: Group str_has_prefix() and strstarts() Andy Shevchenko
2025-07-15 5:24 ` Kees Cook
2025-07-15 6:52 ` Andy Shevchenko
2025-07-15 6:53 ` Andy Shevchenko
2025-07-17 23:40 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).