Re: [PATCH 2/3] powerpc: prom_init: switch to early string functions

2021-04-30 Thread Christophe Leroy




Le 30/04/2021 à 06:22, Daniel Walker a écrit :

This converts the prom_init string users to the early string function
which don't suffer from KASAN or any other debugging enabled.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Daniel Walker 
---
  arch/powerpc/kernel/prom_init.c| 185 ++---
  arch/powerpc/kernel/prom_init_check.sh |   9 +-
  2 files changed, 51 insertions(+), 143 deletions(-)

diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index ccf77b985c8f..4d4343da1280 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -225,105 +225,6 @@ static bool  __prombss rtas_has_query_cpu_stopped;
  #define PHANDLE_VALID(p)  ((p) != 0 && (p) != PROM_ERROR)
  #define IHANDLE_VALID(i)  ((i) != 0 && (i) != PROM_ERROR)
  
-/* Copied from lib/string.c and lib/kstrtox.c */


Please leave the second part of the comment as you have not removed 
prom_strtobool()



[PATCH 2/3] powerpc: prom_init: switch to early string functions

2021-04-29 Thread Daniel Walker
This converts the prom_init string users to the early string function
which don't suffer from KASAN or any other debugging enabled.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Daniel Walker 
---
 arch/powerpc/kernel/prom_init.c| 185 ++---
 arch/powerpc/kernel/prom_init_check.sh |   9 +-
 2 files changed, 51 insertions(+), 143 deletions(-)

diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index ccf77b985c8f..4d4343da1280 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -225,105 +225,6 @@ static bool  __prombss rtas_has_query_cpu_stopped;
 #define PHANDLE_VALID(p)   ((p) != 0 && (p) != PROM_ERROR)
 #define IHANDLE_VALID(i)   ((i) != 0 && (i) != PROM_ERROR)
 
-/* Copied from lib/string.c and lib/kstrtox.c */
-
-static int __init prom_strcmp(const char *cs, const char *ct)
-{
-   unsigned char c1, c2;
-
-   while (1) {
-   c1 = *cs++;
-   c2 = *ct++;
-   if (c1 != c2)
-   return c1 < c2 ? -1 : 1;
-   if (!c1)
-   break;
-   }
-   return 0;
-}
-
-static char __init *prom_strcpy(char *dest, const char *src)
-{
-   char *tmp = dest;
-
-   while ((*dest++ = *src++) != '\0')
-   /* nothing */;
-   return tmp;
-}
-
-static int __init prom_strncmp(const char *cs, const char *ct, size_t count)
-{
-   unsigned char c1, c2;
-
-   while (count) {
-   c1 = *cs++;
-   c2 = *ct++;
-   if (c1 != c2)
-   return c1 < c2 ? -1 : 1;
-   if (!c1)
-   break;
-   count--;
-   }
-   return 0;
-}
-
-static size_t __init prom_strlen(const char *s)
-{
-   const char *sc;
-
-   for (sc = s; *sc != '\0'; ++sc)
-   /* nothing */;
-   return sc - s;
-}
-
-static int __init prom_memcmp(const void *cs, const void *ct, size_t count)
-{
-   const unsigned char *su1, *su2;
-   int res = 0;
-
-   for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
-   if ((res = *su1 - *su2) != 0)
-   break;
-   return res;
-}
-
-static char __init *prom_strstr(const char *s1, const char *s2)
-{
-   size_t l1, l2;
-
-   l2 = prom_strlen(s2);
-   if (!l2)
-   return (char *)s1;
-   l1 = prom_strlen(s1);
-   while (l1 >= l2) {
-   l1--;
-   if (!prom_memcmp(s1, s2, l2))
-   return (char *)s1;
-   s1++;
-   }
-   return NULL;
-}
-
-static size_t __init prom_strlcat(char *dest, const char *src, size_t count)
-{
-   size_t dsize = prom_strlen(dest);
-   size_t len = prom_strlen(src);
-   size_t res = dsize + len;
-
-   /* This would be a bug */
-   if (dsize >= count)
-   return count;
-
-   dest += dsize;
-   count -= dsize;
-   if (len >= count)
-   len = count-1;
-   memcpy(dest, src, len);
-   dest[len] = 0;
-   return res;
-
-}
-
 #ifdef CONFIG_PPC_PSERIES
 static int __init prom_strtobool(const char *s, bool *res)
 {
@@ -694,7 +595,7 @@ static int __init prom_setprop(phandle node, const char 
*nodename,
add_string(, tohex((u32)(unsigned long) value));
add_string(, tohex(valuelen));
add_string(, tohex(ADDR(pname)));
-   add_string(, tohex(prom_strlen(pname)));
+   add_string(, tohex(early_strlen(pname)));
add_string(, "property");
*p = 0;
return call_prom("interpret", 1, 1, (u32)(unsigned long) cmd);
@@ -779,25 +680,25 @@ static void __init early_cmdline_parse(void)
l = prom_getprop(prom.chosen, "bootargs", p, 
COMMAND_LINE_SIZE-1);
 
if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || l <= 0 || p[0] == '\0')
-   prom_strlcat(prom_cmd_line, " " CONFIG_CMDLINE,
+   early_strlcat(prom_cmd_line, " " CONFIG_CMDLINE,
 sizeof(prom_cmd_line));
 
prom_printf("command line: %s\n", prom_cmd_line);
 
 #ifdef CONFIG_PPC64
-   opt = prom_strstr(prom_cmd_line, "iommu=");
+   opt = early_strstr(prom_cmd_line, "iommu=");
if (opt) {
prom_printf("iommu opt is: %s\n", opt);
opt += 6;
while (*opt && *opt == ' ')
opt++;
-   if (!prom_strncmp(opt, "off", 3))
+   if (!early_strncmp(opt, "off", 3))
prom_iommu_off = 1;
-   else if (!prom_strncmp(opt, "force", 5))
+   else if (!early_strncmp(opt, "force", 5))
prom_iommu_force_on = 1;
}
 #endif
-   opt = prom_strstr(prom_cmd_line, "mem=");
+   opt = early_strstr(prom_cmd_line, "mem=");
if (opt) {
opt += 4;
prom_memory_limit = prom_memparse(opt, (const char **));
@@ -809,7 +710,7 @@ static void