* [PATCH] lib/string: add memrchr function
@ 2019-02-12 18:06 Xiang Xiao
2019-02-12 18:34 ` Greg KH
2019-02-12 18:54 ` [v2] " Xiang Xiao
0 siblings, 2 replies; 9+ messages in thread
From: Xiang Xiao @ 2019-02-12 18:06 UTC (permalink / raw)
To: gregkh, alexander.shishkin, andriy.shevchenko, linux-kernel; +Cc: Xiang Xiao
Here is the detailed description for memrchr:
https://linux.die.net/man/3/memrchr
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
---
include/linux/string.h | 1 +
lib/string.c | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/include/linux/string.h b/include/linux/string.h
index 7927b87..f380f4b 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -167,6 +167,7 @@ static inline void memcpy_flushcache(void *dst, const void *src, size_t cnt)
memcpy(dst, src, cnt);
}
#endif
+void *memrchr(const void *s, int c, size_t n);
void *memchr_inv(const void *s, int c, size_t n);
char *strreplace(char *s, char old, char new);
diff --git a/lib/string.c b/lib/string.c
index 38e4ca0..92914f6 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -964,6 +964,27 @@ void *memchr(const void *s, int c, size_t n)
EXPORT_SYMBOL(memchr);
#endif
+/**
+ * memrchr - Find a character in an area of memory.
+ * @s: The memory area
+ * @c: The byte to search for
+ * @n: The size of the area.
+ *
+ * returns the address of the last occurrence of @c, or %NULL
+ * if @c is not found
+ */
+void *memrchr(const void *s, int c, size_t n)
+{
+ const unsigned char *p = s + n;
+
+ while (n-- != 0) {
+ if ((unsigned char)c == *--p)
+ return (void *)p;
+ }
+ return NULL;
+}
+EXPORT_SYMBOL(memrchr);
+
static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes)
{
while (bytes) {
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] lib/string: add memrchr function
2019-02-12 18:06 [PATCH] lib/string: add memrchr function Xiang Xiao
@ 2019-02-12 18:34 ` Greg KH
2019-02-12 19:09 ` xiang xiao
2019-02-12 18:54 ` [v2] " Xiang Xiao
1 sibling, 1 reply; 9+ messages in thread
From: Greg KH @ 2019-02-12 18:34 UTC (permalink / raw)
To: Xiang Xiao
Cc: alexander.shishkin, andriy.shevchenko, linux-kernel, Xiang Xiao
On Wed, Feb 13, 2019 at 02:06:49AM +0800, Xiang Xiao wrote:
> Here is the detailed description for memrchr:
> https://linux.die.net/man/3/memrchr
Please put it in the changelog, as web pages move and go away :(
>
> Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
> ---
> include/linux/string.h | 1 +
> lib/string.c | 21 +++++++++++++++++++++
> 2 files changed, 22 insertions(+)
>
> diff --git a/include/linux/string.h b/include/linux/string.h
> index 7927b87..f380f4b 100644
> --- a/include/linux/string.h
> +++ b/include/linux/string.h
> @@ -167,6 +167,7 @@ static inline void memcpy_flushcache(void *dst, const void *src, size_t cnt)
> memcpy(dst, src, cnt);
> }
> #endif
> +void *memrchr(const void *s, int c, size_t n);
Who is going to use this?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 9+ messages in thread
* [v2] lib/string: add memrchr function
2019-02-12 18:06 [PATCH] lib/string: add memrchr function Xiang Xiao
2019-02-12 18:34 ` Greg KH
@ 2019-02-12 18:54 ` Xiang Xiao
2019-02-12 19:11 ` Greg KH
2019-02-12 19:12 ` Greg KH
1 sibling, 2 replies; 9+ messages in thread
From: Xiang Xiao @ 2019-02-12 18:54 UTC (permalink / raw)
To: gregkh, alexander.shishkin, andriy.shevchenko, linux-kernel; +Cc: Xiang Xiao
Here is the detailed description for memrchr:
void *memrchr(const void *s, int c, size_t n);
The memrchr() function is like the memchr() function, except
that it searches backward from the end of the n bytes pointed
to by s instead of forward from the beginning.
The memrchr() functions return a pointer to the matching byte
or NULL if the character does not occur in the given memory
area.
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
---
include/linux/string.h | 1 +
lib/string.c | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/include/linux/string.h b/include/linux/string.h
index 7927b87..f380f4b 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -167,6 +167,7 @@ static inline void memcpy_flushcache(void *dst, const void *src, size_t cnt)
memcpy(dst, src, cnt);
}
#endif
+void *memrchr(const void *s, int c, size_t n);
void *memchr_inv(const void *s, int c, size_t n);
char *strreplace(char *s, char old, char new);
diff --git a/lib/string.c b/lib/string.c
index 38e4ca0..92914f6 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -964,6 +964,27 @@ void *memchr(const void *s, int c, size_t n)
EXPORT_SYMBOL(memchr);
#endif
+/**
+ * memrchr - Find a character in an area of memory.
+ * @s: The memory area
+ * @c: The byte to search for
+ * @n: The size of the area.
+ *
+ * returns the address of the last occurrence of @c, or %NULL
+ * if @c is not found
+ */
+void *memrchr(const void *s, int c, size_t n)
+{
+ const unsigned char *p = s + n;
+
+ while (n-- != 0) {
+ if ((unsigned char)c == *--p)
+ return (void *)p;
+ }
+ return NULL;
+}
+EXPORT_SYMBOL(memrchr);
+
static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes)
{
while (bytes) {
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] lib/string: add memrchr function
2019-02-12 18:34 ` Greg KH
@ 2019-02-12 19:09 ` xiang xiao
2019-02-12 19:15 ` Greg KH
0 siblings, 1 reply; 9+ messages in thread
From: xiang xiao @ 2019-02-12 19:09 UTC (permalink / raw)
To: Greg KH; +Cc: alexander.shishkin, andriy.shevchenko, linux-kernel, Xiang Xiao
On Wed, Feb 13, 2019 at 2:34 AM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Wed, Feb 13, 2019 at 02:06:49AM +0800, Xiang Xiao wrote:
> > Here is the detailed description for memrchr:
> > https://linux.die.net/man/3/memrchr
>
> Please put it in the changelog, as web pages move and go away :(
Sure.
>
> >
> > Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
> > ---
> > include/linux/string.h | 1 +
> > lib/string.c | 21 +++++++++++++++++++++
> > 2 files changed, 22 insertions(+)
> >
> > diff --git a/include/linux/string.h b/include/linux/string.h
> > index 7927b87..f380f4b 100644
> > --- a/include/linux/string.h
> > +++ b/include/linux/string.h
> > @@ -167,6 +167,7 @@ static inline void memcpy_flushcache(void *dst, const void *src, size_t cnt)
> > memcpy(dst, src, cnt);
> > }
> > #endif
> > +void *memrchr(const void *s, int c, size_t n);
>
> Who is going to use this?
This patch will use memrchr:
https://github.com/thesofproject/linux/pull/177/commits/a0b7009fede5552dc98733f2996a8140bff62455
I am preparing to upstream it.
>
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [v2] lib/string: add memrchr function
2019-02-12 18:54 ` [v2] " Xiang Xiao
@ 2019-02-12 19:11 ` Greg KH
2019-02-12 19:12 ` Greg KH
1 sibling, 0 replies; 9+ messages in thread
From: Greg KH @ 2019-02-12 19:11 UTC (permalink / raw)
To: Xiang Xiao
Cc: alexander.shishkin, andriy.shevchenko, linux-kernel, Xiang Xiao
On Wed, Feb 13, 2019 at 02:54:43AM +0800, Xiang Xiao wrote:
> Here is the detailed description for memrchr:
>
> void *memrchr(const void *s, int c, size_t n);
>
> The memrchr() function is like the memchr() function, except
> that it searches backward from the end of the n bytes pointed
> to by s instead of forward from the beginning.
>
> The memrchr() functions return a pointer to the matching byte
> or NULL if the character does not occur in the given memory
> area.
>
> Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
> ---
> include/linux/string.h | 1 +
> lib/string.c | 21 +++++++++++++++++++++
> 2 files changed, 22 insertions(+)
Don't add new apis without any users.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [v2] lib/string: add memrchr function
2019-02-12 18:54 ` [v2] " Xiang Xiao
2019-02-12 19:11 ` Greg KH
@ 2019-02-12 19:12 ` Greg KH
2019-02-12 19:19 ` xiang xiao
1 sibling, 1 reply; 9+ messages in thread
From: Greg KH @ 2019-02-12 19:12 UTC (permalink / raw)
To: Xiang Xiao
Cc: alexander.shishkin, andriy.shevchenko, linux-kernel, Xiang Xiao
On Wed, Feb 13, 2019 at 02:54:43AM +0800, Xiang Xiao wrote:
> Here is the detailed description for memrchr:
>
> void *memrchr(const void *s, int c, size_t n);
>
> The memrchr() function is like the memchr() function, except
> that it searches backward from the end of the n bytes pointed
> to by s instead of forward from the beginning.
>
> The memrchr() functions return a pointer to the matching byte
> or NULL if the character does not occur in the given memory
> area.
>
> Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
> ---
> include/linux/string.h | 1 +
> lib/string.c | 21 +++++++++++++++++++++
> 2 files changed, 22 insertions(+)
>
> diff --git a/include/linux/string.h b/include/linux/string.h
> index 7927b87..f380f4b 100644
> --- a/include/linux/string.h
> +++ b/include/linux/string.h
> @@ -167,6 +167,7 @@ static inline void memcpy_flushcache(void *dst, const void *src, size_t cnt)
> memcpy(dst, src, cnt);
> }
> #endif
> +void *memrchr(const void *s, int c, size_t n);
> void *memchr_inv(const void *s, int c, size_t n);
> char *strreplace(char *s, char old, char new);
Also, if you really need this, why not also provide the arch-specific
versions as well?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] lib/string: add memrchr function
2019-02-12 19:09 ` xiang xiao
@ 2019-02-12 19:15 ` Greg KH
2019-02-12 19:22 ` xiang xiao
0 siblings, 1 reply; 9+ messages in thread
From: Greg KH @ 2019-02-12 19:15 UTC (permalink / raw)
To: xiang xiao
Cc: alexander.shishkin, andriy.shevchenko, linux-kernel, Xiang Xiao
On Wed, Feb 13, 2019 at 03:09:19AM +0800, xiang xiao wrote:
> On Wed, Feb 13, 2019 at 2:34 AM Greg KH <gregkh@linuxfoundation.org> wrote:
> >
> > On Wed, Feb 13, 2019 at 02:06:49AM +0800, Xiang Xiao wrote:
> > > Here is the detailed description for memrchr:
> > > https://linux.die.net/man/3/memrchr
> >
> > Please put it in the changelog, as web pages move and go away :(
>
> Sure.
>
> >
> > >
> > > Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
> > > ---
> > > include/linux/string.h | 1 +
> > > lib/string.c | 21 +++++++++++++++++++++
> > > 2 files changed, 22 insertions(+)
> > >
> > > diff --git a/include/linux/string.h b/include/linux/string.h
> > > index 7927b87..f380f4b 100644
> > > --- a/include/linux/string.h
> > > +++ b/include/linux/string.h
> > > @@ -167,6 +167,7 @@ static inline void memcpy_flushcache(void *dst, const void *src, size_t cnt)
> > > memcpy(dst, src, cnt);
> > > }
> > > #endif
> > > +void *memrchr(const void *s, int c, size_t n);
> >
> > Who is going to use this?
>
> This patch will use memrchr:
> https://github.com/thesofproject/linux/pull/177/commits/a0b7009fede5552dc98733f2996a8140bff62455
> I am preparing to upstream it.
Great, make it part of the patch series for your driver, no need to
submit it separately.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [v2] lib/string: add memrchr function
2019-02-12 19:12 ` Greg KH
@ 2019-02-12 19:19 ` xiang xiao
0 siblings, 0 replies; 9+ messages in thread
From: xiang xiao @ 2019-02-12 19:19 UTC (permalink / raw)
To: Greg KH; +Cc: alexander.shishkin, andriy.shevchenko, linux-kernel, Xiang Xiao
On Wed, Feb 13, 2019 at 3:12 AM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Wed, Feb 13, 2019 at 02:54:43AM +0800, Xiang Xiao wrote:
> > Here is the detailed description for memrchr:
> >
> > void *memrchr(const void *s, int c, size_t n);
> >
> > The memrchr() function is like the memchr() function, except
> > that it searches backward from the end of the n bytes pointed
> > to by s instead of forward from the beginning.
> >
> > The memrchr() functions return a pointer to the matching byte
> > or NULL if the character does not occur in the given memory
> > area.
> >
> > Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
> > ---
> > include/linux/string.h | 1 +
> > lib/string.c | 21 +++++++++++++++++++++
> > 2 files changed, 22 insertions(+)
> >
> > diff --git a/include/linux/string.h b/include/linux/string.h
> > index 7927b87..f380f4b 100644
> > --- a/include/linux/string.h
> > +++ b/include/linux/string.h
> > @@ -167,6 +167,7 @@ static inline void memcpy_flushcache(void *dst, const void *src, size_t cnt)
> > memcpy(dst, src, cnt);
> > }
> > #endif
> > +void *memrchr(const void *s, int c, size_t n);
> > void *memchr_inv(const void *s, int c, size_t n);
> > char *strreplace(char *s, char old, char new);
>
> Also, if you really need this, why not also provide the arch-specific
> versions as well?
>
Good point, I will make the arch-specific overwrite possible.
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] lib/string: add memrchr function
2019-02-12 19:15 ` Greg KH
@ 2019-02-12 19:22 ` xiang xiao
0 siblings, 0 replies; 9+ messages in thread
From: xiang xiao @ 2019-02-12 19:22 UTC (permalink / raw)
To: Greg KH; +Cc: alexander.shishkin, andriy.shevchenko, linux-kernel, Xiang Xiao
On Wed, Feb 13, 2019 at 3:15 AM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Wed, Feb 13, 2019 at 03:09:19AM +0800, xiang xiao wrote:
> > On Wed, Feb 13, 2019 at 2:34 AM Greg KH <gregkh@linuxfoundation.org> wrote:
> > >
> > > On Wed, Feb 13, 2019 at 02:06:49AM +0800, Xiang Xiao wrote:
> > > > Here is the detailed description for memrchr:
> > > > https://linux.die.net/man/3/memrchr
> > >
> > > Please put it in the changelog, as web pages move and go away :(
> >
> > Sure.
> >
> > >
> > > >
> > > > Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
> > > > ---
> > > > include/linux/string.h | 1 +
> > > > lib/string.c | 21 +++++++++++++++++++++
> > > > 2 files changed, 22 insertions(+)
> > > >
> > > > diff --git a/include/linux/string.h b/include/linux/string.h
> > > > index 7927b87..f380f4b 100644
> > > > --- a/include/linux/string.h
> > > > +++ b/include/linux/string.h
> > > > @@ -167,6 +167,7 @@ static inline void memcpy_flushcache(void *dst, const void *src, size_t cnt)
> > > > memcpy(dst, src, cnt);
> > > > }
> > > > #endif
> > > > +void *memrchr(const void *s, int c, size_t n);
> > >
> > > Who is going to use this?
> >
> > This patch will use memrchr:
> > https://github.com/thesofproject/linux/pull/177/commits/a0b7009fede5552dc98733f2996a8140bff62455
> > I am preparing to upstream it.
>
> Great, make it part of the patch series for your driver, no need to
> submit it separately.
>
Ok, I will merge the depend patch into one series.
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2019-02-12 19:22 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-12 18:06 [PATCH] lib/string: add memrchr function Xiang Xiao
2019-02-12 18:34 ` Greg KH
2019-02-12 19:09 ` xiang xiao
2019-02-12 19:15 ` Greg KH
2019-02-12 19:22 ` xiang xiao
2019-02-12 18:54 ` [v2] " Xiang Xiao
2019-02-12 19:11 ` Greg KH
2019-02-12 19:12 ` Greg KH
2019-02-12 19:19 ` xiang xiao
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).