Skip to contentSkip to conversation

lib/string: add memrchr function

PATCH In review Xiang Xiao 2 participants 6 messages Feb 14, 2019

Subsystems (3)
lore
Share & tools
lore

Xiang Xiao

author
#0 lore raw

PATCH 1/2 lib/string: add memrchr function

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.

---
 include/linux/string.h |  1 +
 lib/string.c           | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)
include/linux/string.h +1 -0
index 7927b87..f380f4b 100644
@@ -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);
 
lib/string.c +21 -0
index 38e4ca0..92914f6 100644
@@ -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) {
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 2/2 rpmsg: add syslog redirection driver

From: Guiding Li <[email protected]>

This driver allows the remote processor redirect the output of syslog/printf into the kernel log, which is very useful to see what happen in the remote side.

---
 drivers/rpmsg/Kconfig        |  12 ++++
 drivers/rpmsg/Makefile       |   1 +
 drivers/rpmsg/rpmsg_syslog.c | 163 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 176 insertions(+)
 create mode 100644 drivers/rpmsg/rpmsg_syslog.c
drivers/rpmsg/Kconfig +12 -0
index d0322b4..d701614 100644
@@ -15,6 +15,18 @@ config RPMSG_CHAR
 	  in /dev. They make it possible for user-space programs to send and
 	  receive rpmsg packets.
 
+config RPMSG_SYSLOG
+	tristate "RPMSG syslog redirection"
+	depends on RPMSG
+	help
+	  Say Y here to redirect the syslog/printf from remote processor into
+	  the kernel log which is very useful to see what happen in the remote
+	  side.
+
+	  If the remote processor hang during bootup or panic at the runtime,
+	  We can even cat /sys/kernel/debug/remoteproc/remoteprocX/trace0 to
+	  get the last log which doesn't output yet.
+
 config RPMSG_QCOM_GLINK_NATIVE
 	tristate
 	select RPMSG
drivers/rpmsg/Makefile +1 -0
index 9aa8595..bfd22df 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_RPMSG)		+= rpmsg_core.o
 obj-$(CONFIG_RPMSG_CHAR)	+= rpmsg_char.o
+obj-$(CONFIG_RPMSG_SYSLOG)	+= rpmsg_syslog.o
 obj-$(CONFIG_RPMSG_QCOM_GLINK_RPM) += qcom_glink_rpm.o
 obj-$(CONFIG_RPMSG_QCOM_GLINK_NATIVE) += qcom_glink_native.o
 obj-$(CONFIG_RPMSG_QCOM_GLINK_SMEM) += qcom_glink_smem.o
drivers/rpmsg/rpmsg_syslog.c new file +163 -0

163 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH 2/2] rpmsg: add syslog redirection driver

Quoted 3 lines · Xiang Xiao

From: Guiding Li <[email protected]>

This driver allows the remote processor redirect the output of

processor to redirect

Quoted 16 lines

syslog/printf into the kernel log, which is very useful to see what happen in the remote side.

---
 drivers/rpmsg/Kconfig        |  12 ++++
 drivers/rpmsg/Makefile       |   1 +
 drivers/rpmsg/rpmsg_syslog.c | 163 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 176 insertions(+)
 create mode 100644 drivers/rpmsg/rpmsg_syslog.c
drivers/rpmsg/Kconfig +0 -0
index d0322b4..d701614 100644

drivers/rpmsg/Kconfig config RPMSG_CHAR · line 23

Quoted 9 lines
drivers/rpmsg/Kconfig +6 -0
@@ -15,6 +15,18 @@ config RPMSG_CHAR
 	  in /dev. They make it possible for user-space programs to send and
 	  receive rpmsg packets.
 
+config RPMSG_SYSLOG
+	tristate "RPMSG syslog redirection"
+	depends on RPMSG
+	help
+	  Say Y here to redirect the syslog/printf from remote processor into
+	  the kernel log which is very useful to see what happen in the remote

see what happens
or see what happened

drivers/rpmsg/Kconfig config RPMSG_CHAR · line 26

Quoted 3 lines
drivers/rpmsg/Kconfig +3 -0
+	  side.
+
+	  If the remote processor hang during bootup or panic at the runtime,

hangs during bootup or panics during runtime,

drivers/rpmsg/Kconfig config RPMSG_CHAR · line 27

Quoted 1 line
drivers/rpmsg/Kconfig +1 -0
+	  We can even cat /sys/kernel/debug/remoteproc/remoteprocX/trace0 to

we

drivers/rpmsg/Kconfig config RPMSG_CHAR · line 28

Quoted 1 line
drivers/rpmsg/Kconfig +1 -0
+	  get the last log which doesn't output yet.

get the last log which hasn't been output yet.

Quoted 4 lines
drivers/rpmsg/Kconfig +1 -0
+
 config RPMSG_QCOM_GLINK_NATIVE
 	tristate
 	select RPMSG
Signature · 1 line
~Randy
author
#3 lore raw

Re: [PATCH 2/2] rpmsg: add syslog redirection driver

Thanks, will fix all typo in the next patch.

Quoted 66 lines · Randy Dunlap
Quoted 3 lines · Xiang Xiao

From: Guiding Li <[email protected]>

This driver allows the remote processor redirect the output of

processor to redirect

Quoted 8 lines

syslog/printf into the kernel log, which is very useful to see what happen in the remote side.

---
 drivers/rpmsg/Kconfig        |  12 ++++
 drivers/rpmsg/Makefile       |   1 +
 drivers/rpmsg/rpmsg_syslog.c | 163

+++++++++++++++++++++++++++++++++++++++++++

drivers/rpmsg/Kconfig config RPMSG_CHAR · line 15

Quoted 9 lines
 3 files changed, 176 insertions(+)
 create mode 100644 drivers/rpmsg/rpmsg_syslog.c
drivers/rpmsg/Kconfig +0 -0
index d0322b4..d701614 100644
@@ -15,6 +15,18 @@ config RPMSG_CHAR
        in /dev. They make it possible for user-space programs to send

and

drivers/rpmsg/Kconfig config RPMSG_CHAR

Quoted 7 lines
drivers/rpmsg/Kconfig +5 -0
        receive rpmsg packets.
 
+config RPMSG_SYSLOG
+     tristate "RPMSG syslog redirection"
+     depends on RPMSG
+     help
+       Say Y here to redirect the syslog/printf from remote processor

into

drivers/rpmsg/Kconfig config RPMSG_CHAR · line 23

Quoted 1 line
drivers/rpmsg/Kconfig +1 -0
+       the kernel log which is very useful to see what happen in the

remote

see what happens
or see what happened

drivers/rpmsg/Kconfig config RPMSG_CHAR

Quoted 3 lines
drivers/rpmsg/Kconfig +3 -0
+       side.
+
+       If the remote processor hang during bootup or panic at the

runtime,

hangs during bootup or panics during
runtime,

drivers/rpmsg/Kconfig config RPMSG_CHAR · line 27

Quoted 1 line
drivers/rpmsg/Kconfig +1 -0
+       We can even cat /sys/kernel/debug/remoteproc/remoteprocX/trace0

to

we

drivers/rpmsg/Kconfig config RPMSG_CHAR · line 28

Quoted 1 line
drivers/rpmsg/Kconfig +1 -0
+       get the last log which doesn't output yet.

get the last log which hasn't been output yet.

drivers/rpmsg/Kconfig config RPMSG_CHAR · line 32

Quoted 4 lines
drivers/rpmsg/Kconfig +1 -0
+
 config RPMSG_QCOM_GLINK_NATIVE
      tristate
      select RPMSG

--
~Randy

#4 lore raw
In reply to Xiang Xiao
Quoted 35 lines · 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.

---
 include/linux/string.h |  1 +
 lib/string.c           | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)
include/linux/string.h +1 -0
index 7927b87..f380f4b 100644
@@ -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);
 
lib/string.c +0 -0
index 38e4ca0..92914f6 100644

lib/string.c void *memchr(const void *s, int c, size_t n) · line 968

Quoted 5 lines
lib/string.c +2 -0
@@ -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.

This should say up front that this is a reverse search, from the end of the memory area backwards.

lib/string.c void *memchr(const void *s, int c, size_t n) · line 973

Quoted 5 lines
lib/string.c +5 -0
+ * @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

* Return: the address of the last occurrence of @c, or %NULL

Quoted 18 lines
lib/string.c +14 -0
+ * 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) {
Signature · 1 line
~Randy
author
#5 lore raw

Thanks, will fix all issues in the next review.

Quoted 77 lines · Randy Dunlap

include/linux/string.h static inline void memcpy_flushcache(void *dst,

Quoted 23 lines · 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.

---
 include/linux/string.h |  1 +
 lib/string.c           | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)
include/linux/string.h +0 -0
index 7927b87..f380f4b 100644
@@ -167,6 +167,7 @@ static inline void memcpy_flushcache(void *dst,

const void *src, size_t cnt)

Quoted 12 lines
include/linux/string.h +1 -0
      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);
 
lib/string.c +0 -0
index 38e4ca0..92914f6 100644

lib/string.c void *memchr(const void *s, int c, size_t n) · line 968

Quoted 5 lines
lib/string.c +2 -0
@@ -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.

This should say up front that this is a reverse search, from the end of the memory area backwards.

lib/string.c void *memchr(const void *s, int c, size_t n) · line 973

Quoted 5 lines
lib/string.c +5 -0
+ * @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

* Return: the address of the last occurrence of @c, or %NULL

Quoted 8 lines
lib/string.c +7 -0
+ * if @c is not found
+ */
+void *memrchr(const void *s, int c, size_t n)
+{
+     const unsigned char *p = s + n;
+
+     while (n-- != 0) {

lib/string.c void *memchr(const void *s, int c, size_t n) · line 990

Quoted 10 lines
lib/string.c +7 -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) {

--
~Randy