Skip to contentSkip to conversation

Don't use SBI functions in fdt code

PATCH New Daniel Schaefer 3 participants 11 messages May 19, 2021

lore
Share & tools
lore
#0 lore raw

v2 cover Don't use SBI functions in fdt code

Second series with minor changes based on the feedback

- Made commit description of 1 better
- Changed sbi_memcpy to memcpy in 2 (forgot it before because I was basing on v0.9 instead of master)
- Fixed typo in commit message of 3

Cc Xiang W <[email protected]>
Cc Abner Chang <[email protected]>
Cc Anup Patel <[email protected]>

Daniel Schaefer (3):
lib: utils: Add strncpy macro to libfdt_env.h
lib: fdt: Don't use sbi_string functions
lib: utils: Replace strcmp with strncmp

 lib/utils/fdt/fdt_domain.c    | 9 +++++----
 lib/utils/libfdt/libfdt_env.h | 1 +
 2 files changed, 6 insertions(+), 4 deletions(-)
Signature · 1 line
2.30.1
#1 lore raw

PATCH v2 1/3 lib: utils: Add strncpy macro to libfdt_env.h

Just like 2845d2d2cf4fb74a89452ba223995aa4a118c07e
we want to use sbi_strncpy as strncpy in the OpenSBI implementation for libfdt.

---
 lib/utils/libfdt/libfdt_env.h | 1 +
 1 file changed, 1 insertion(+)
lib/utils/libfdt/libfdt_env.h +1 -0
index bc3e7588660a..f9d9c6783c52 100644
@@ -31,6 +31,7 @@
 #define strchr		sbi_strchr
 #define strrchr		sbi_strrchr
 #define strcpy		sbi_strcpy
+#define strncpy		sbi_strncpy
 #define strcmp		sbi_strcmp
 #define strncmp		sbi_strncmp
 #define strlen		sbi_strlen
Signature · 1 line
2.30.1
#2 lore raw

PATCH v2 1/3 lib: utils: Add strncpy macro to libfdt_env.h

? 2021-05-19?? 15:54 +0800?Daniel Schaefer???

Quoted 9 lines

Just like 2845d2d2cf4fb74a89452ba223995aa4a118c07e
we want to use sbi_strncpy as strncpy in the OpenSBI implementation for
libfdt.

Quoted 21 lines
---
 lib/utils/libfdt/libfdt_env.h | 1 +
 1 file changed, 1 insertion(+)
lib/utils/libfdt/libfdt_env.h +1 -0
index bc3e7588660a..f9d9c6783c52 100644
@@ -31,6 +31,7 @@
 #define strchr		sbi_strchr
 #define strrchr		sbi_strrchr
 #define strcpy		sbi_strcpy
+#define strncpy		sbi_strncpy
 #define strcmp		sbi_strcmp
 #define strncmp		sbi_strncmp
 #define strlen		sbi_strlen
Signature · 1 line
2.30.1
#3 lore raw

PATCH v2 1/3 lib: utils: Add strncpy macro to libfdt_env.h

Quoted 16 lines

-----Original Message-----
From: Xiang W <[email protected]>
Sent: 19 May 2021 14:08
To: Daniel Schaefer <[email protected]>;
opensbi at lists.infradead.org
Cc: Abner Chang <[email protected]>; Anup Patel <[email protected]>
Subject: Re: [PATCH v2 1/3] lib: utils: Add strncpy macro to libfdt_env.h

? 2021-05-19?? 15:54 +0800?Daniel Schaefer???

Quoted 4 lines

Just like 2845d2d2cf4fb74a89452ba223995aa4a118c07e
we want to use sbi_strncpy as strncpy in the OpenSBI implementation for libfdt.

Quoted 6 lines
Quoted 4 lines

Looks good to me.

Regards,
Anup

Quoted 22 lines
Quoted 22 lines
---
 lib/utils/libfdt/libfdt_env.h | 1 +
 1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/lib/utils/libfdt/libfdt_env.h index bc3e7588660a..f9d9c6783c52 100644

lib/utils/libfdt/libfdt_env.h +1 -1
@@ -31,6 +31,7 @@
 #define strchr		sbi_strchr
 #define strrchr		sbi_strrchr
 #define strcpy		sbi_strcpy
+#define strncpy		sbi_strncpy
 #define strcmp		sbi_strcmp
 #define strncmp		sbi_strncmp
 #define strlen		sbi_strlen
--

2.30.1

#4 lore raw

PATCH v2 1/3 lib: utils: Add strncpy macro to libfdt_env.h

Quoted 32 lines

-----Original Message-----
From: Anup Patel
Sent: 19 May 2021 18:22
To: Xiang W <[email protected]>; Daniel Schaefer <[email protected]>; opensbi at lists.infradead.org
Cc: Abner Chang <[email protected]>
Subject: RE: [PATCH v2 1/3] lib: utils: Add strncpy macro to libfdt_env.h

Quoted 6 lines

-----Original Message-----
From: Xiang W <[email protected]>
Sent: 19 May 2021 14:08
To: Daniel Schaefer <[email protected]>;
opensbi at lists.infradead.org
Cc: Abner Chang <[email protected]>; Anup Patel

<[email protected]>

Quoted 13 lines

Subject: Re: [PATCH v2 1/3] lib: utils: Add strncpy macro to libfdt_env.h

? 2021-05-19?? 15:54 +0800?Daniel Schaefer???

Quoted 8 lines

Just like 2845d2d2cf4fb74a89452ba223995aa4a118c07e
we want to use sbi_strncpy as strncpy in the OpenSBI implementation for libfdt.

Quoted 5 lines
Quoted 1 line

Looks good to me.

Forgot to mention that I have applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 26 lines

Regards,
Anup

Quoted 22 lines
Quoted 22 lines
---
 lib/utils/libfdt/libfdt_env.h | 1 +
 1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/lib/utils/libfdt/libfdt_env.h index bc3e7588660a..f9d9c6783c52 100644

lib/utils/libfdt/libfdt_env.h +1 -1
@@ -31,6 +31,7 @@
 #define strchr		sbi_strchr
 #define strrchr		sbi_strrchr
 #define strcpy		sbi_strcpy
+#define strncpy		sbi_strncpy
 #define strcmp		sbi_strcmp
 #define strncmp		sbi_strncmp
 #define strlen		sbi_strlen
--

2.30.1

#5 lore raw

PATCH v2 2/3 lib: fdt: Don't use sbi_string functions

In reply to Daniel Schaefer

When SBI is built by external firmware, we need to use their functions, defined in libfdt_env.h.
Just like 2cfd2fc9048806353298a1b967abf985901e36e8

---
 lib/utils/fdt/fdt_domain.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
lib/utils/fdt/fdt_domain.c +5 -4
index 95c195d65238..fc8ad423eb88 100644
@@ -9,6 +9,7 @@
  */
 
 #include <libfdt.h>
+#include <libfdt_env.h>
 #include <sbi/sbi_domain.h>
 #include <sbi/sbi_error.h>
 #include <sbi/sbi_hartmask.h>
@@ -95,7 +96,7 @@ static int __fixup_find_domain_offset(void *fdt, int doff, void *p)
 {
 	struct __fixup_find_domain_offset_info *fdo = p;
 
-	if (!sbi_strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
+	if (!strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
 		*fdo->doffset = doff;
 
 	return 0;
@@ -287,7 +288,7 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque)
 	regions = &fdt_regions[fdt_domains_count][0];
 
 	/* Read DT node name */
-	sbi_strncpy(dom->name, fdt_get_name(fdt, domain_offset, NULL),
+	strncpy(dom->name, fdt_get_name(fdt, domain_offset, NULL),
 		    sizeof(dom->name));
 	dom->name[sizeof(dom->name) - 1] = '\0';
 
@@ -313,7 +314,7 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque)
 
 	/* Setup memregions from DT */
 	val32 = 0;
-	sbi_memset(regions, 0,
+	memset(regions, 0,
 		   sizeof(*regions) * (FDT_DOMAIN_REGION_MAX_COUNT + 1));
 	dom->regions = regions;
 	err = fdt_iterate_each_memregion(fdt, domain_offset, &val32,
@@ -337,7 +338,7 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque)
 			continue;
 		if (FDT_DOMAIN_REGION_MAX_COUNT <= val32)
 			return SBI_EINVAL;
-		sbi_memcpy(&regions[val32++], reg, sizeof(*reg));
+		memcpy(&regions[val32++], reg, sizeof(*reg));
 	}
 
 	/* Read "boot-hart" DT property */
Signature · 1 line
2.30.1
#6 lore raw

PATCH v2 2/3 lib: fdt: Don't use sbi_string functions

? 2021-05-19?? 15:54 +0800?Daniel Schaefer???

Quoted 9 lines

When SBI is built by external firmware, we need to use their functions,
defined in libfdt_env.h.
Just like 2cfd2fc9048806353298a1b967abf985901e36e8

Quoted 61 lines
---
 lib/utils/fdt/fdt_domain.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
lib/utils/fdt/fdt_domain.c +2 -1
index 95c195d65238..fc8ad423eb88 100644
@@ -9,6 +9,7 @@
  */
 
 #include <libfdt.h>
+#include <libfdt_env.h>
 #include <sbi/sbi_domain.h>
 #include <sbi/sbi_error.h>
 #include <sbi/sbi_hartmask.h>
@@ -95,7 +96,7 @@ static int __fixup_find_domain_offset(void *fdt,
 int doff, void *p)
 {
 	struct __fixup_find_domain_offset_info *fdo = p;
 
-	if (!sbi_strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
+	if (!strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
 		*fdo->doffset = doff;
 
lib/utils/fdt/fdt_domain.c +2 -2
 	return 0;
@@ -287,7 +288,7 @@ static int __fdt_parse_domain(void *fdt, int
 domain_offset, void *opaque)
 	regions = &fdt_regions[fdt_domains_count][0];
 
 	/* Read DT node name */
-	sbi_strncpy(dom->name, fdt_get_name(fdt, domain_offset, NULL),
+	strncpy(dom->name, fdt_get_name(fdt, domain_offset, NULL),
 		    sizeof(dom->name));
 	dom->name[sizeof(dom->name) - 1] = '\0';
@@ -313,7 +314,7 @@ static int __fdt_parse_domain(void *fdt, int
 domain_offset, void *opaque)
 
 	/* Setup memregions from DT */
 	val32 = 0;
-	sbi_memset(regions, 0,
+	memset(regions, 0,
 		   sizeof(*regions) * (FDT_DOMAIN_REGION_MAX_COUNT +
 1));
lib/utils/fdt/fdt_domain.c +1 -1
 	dom->regions = regions;
 	err = fdt_iterate_each_memregion(fdt, domain_offset, &val32,
@@ -337,7 +338,7 @@ static int __fdt_parse_domain(void *fdt, int
 domain_offset, void *opaque)
 			continue;
 		if (FDT_DOMAIN_REGION_MAX_COUNT <= val32)
 			return SBI_EINVAL;
-		sbi_memcpy(&regions[val32++], reg, sizeof(*reg));
+		memcpy(&regions[val32++], reg, sizeof(*reg));
 	}
 

/* Read "boot-hart" DT property */

Signature · 1 line
2.30.1
#7 lore raw

PATCH v2 2/3 lib: fdt: Don't use sbi_string functions

Quoted 16 lines

-----Original Message-----
From: Xiang W <[email protected]>
Sent: 19 May 2021 14:09
To: Daniel Schaefer <[email protected]>;
opensbi at lists.infradead.org
Cc: Abner Chang <[email protected]>; Anup Patel <[email protected]>
Subject: Re: [PATCH v2 2/3] lib: fdt: Don't use sbi_string functions

? 2021-05-19?? 15:54 +0800?Daniel Schaefer???

Quoted 4 lines

When SBI is built by external firmware, we need to use their functions, defined in libfdt_env.h.
Just like 2cfd2fc9048806353298a1b967abf985901e36e8

Quoted 6 lines
Quoted 4 lines

Looks good to me.

Regards,
Anup

Quoted 61 lines
Quoted 37 lines
---
 lib/utils/fdt/fdt_domain.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
lib/utils/fdt/fdt_domain.c +3 -2
index 95c195d65238..fc8ad423eb88 100644
@@ -9,6 +9,7 @@
  */
 
 #include <libfdt.h>
+#include <libfdt_env.h>
 #include <sbi/sbi_domain.h>
 #include <sbi/sbi_error.h>
 #include <sbi/sbi_hartmask.h>
@@ -95,7 +96,7 @@ static int __fixup_find_domain_offset(void *fdt, int
 doff, void *p)  {
 	struct __fixup_find_domain_offset_info *fdo = p;
 
-	if (!sbi_strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
+	if (!strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
 		*fdo->doffset = doff;
 
 	return 0;
@@ -287,7 +288,7 @@ static int __fdt_parse_domain(void *fdt, int
 domain_offset, void *opaque)
 	regions = &fdt_regions[fdt_domains_count][0];
 
 	/* Read DT node name */
-	sbi_strncpy(dom->name, fdt_get_name(fdt, domain_offset, NULL),
+	strncpy(dom->name, fdt_get_name(fdt, domain_offset, NULL),
 		    sizeof(dom->name));
 	dom->name[sizeof(dom->name) - 1] = '\0';

lib/utils/fdt/fdt_domain.c static int __fdt_parse_domain(void *fdt, int · line 319

Quoted 7 lines
lib/utils/fdt/fdt_domain.c +1 -1
@@ -313,7 +314,7 @@ static int __fdt_parse_domain(void *fdt, int
 domain_offset, void *opaque)
 
 	/* Setup memregions from DT */
 	val32 = 0;
-	sbi_memset(regions, 0,
+	memset(regions, 0,
 		   sizeof(*regions) * (FDT_DOMAIN_REGION_MAX_COUNT +

1));

Quoted 16 lines
lib/utils/fdt/fdt_domain.c +0 -0
 	dom->regions = regions;

err = fdt_iterate_each_memregion(fdt, domain_offset, &val32, @@
-337,7 +338,7 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque)

lib/utils/fdt/fdt_domain.c +1 -2
 			continue;
 		if (FDT_DOMAIN_REGION_MAX_COUNT <= val32)
 			return SBI_EINVAL;
-		sbi_memcpy(&regions[val32++], reg, sizeof(*reg));
+		memcpy(&regions[val32++], reg, sizeof(*reg));
 	}
 
 	/* Read "boot-hart" DT property */
--

2.30.1

#8 lore raw

PATCH v2 2/3 lib: fdt: Don't use sbi_string functions

Quoted 31 lines

-----Original Message-----
From: Anup Patel
Sent: 19 May 2021 18:22
To: 'Xiang W' <[email protected]>; Daniel Schaefer <[email protected]>; opensbi at lists.infradead.org
Cc: Abner Chang <[email protected]>
Subject: RE: [PATCH v2 2/3] lib: fdt: Don't use sbi_string functions

Quoted 6 lines

-----Original Message-----
From: Xiang W <[email protected]>
Sent: 19 May 2021 14:09
To: Daniel Schaefer <[email protected]>;
opensbi at lists.infradead.org
Cc: Abner Chang <[email protected]>; Anup Patel

<[email protected]>

Quoted 12 lines

Subject: Re: [PATCH v2 2/3] lib: fdt: Don't use sbi_string functions

? 2021-05-19?? 15:54 +0800?Daniel Schaefer???

Quoted 8 lines

When SBI is built by external firmware, we need to use their functions, defined in libfdt_env.h.
Just like 2cfd2fc9048806353298a1b967abf985901e36e8

Quoted 5 lines
Quoted 1 line

Looks good to me.

Forgot to mention that I have applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 65 lines

Regards,
Anup

Quoted 61 lines
Quoted 37 lines
---
 lib/utils/fdt/fdt_domain.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
lib/utils/fdt/fdt_domain.c +3 -2
index 95c195d65238..fc8ad423eb88 100644
@@ -9,6 +9,7 @@
  */
 
 #include <libfdt.h>
+#include <libfdt_env.h>
 #include <sbi/sbi_domain.h>
 #include <sbi/sbi_error.h>
 #include <sbi/sbi_hartmask.h>
@@ -95,7 +96,7 @@ static int __fixup_find_domain_offset(void *fdt,
 int doff, void *p)  {
 	struct __fixup_find_domain_offset_info *fdo = p;
 
-	if (!sbi_strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
+	if (!strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
 		*fdo->doffset = doff;
 
 	return 0;
@@ -287,7 +288,7 @@ static int __fdt_parse_domain(void *fdt, int
 domain_offset, void *opaque)
 	regions = &fdt_regions[fdt_domains_count][0];
 
 	/* Read DT node name */
-	sbi_strncpy(dom->name, fdt_get_name(fdt, domain_offset, NULL),
+	strncpy(dom->name, fdt_get_name(fdt, domain_offset, NULL),
 		    sizeof(dom->name));
 	dom->name[sizeof(dom->name) - 1] = '\0';

lib/utils/fdt/fdt_domain.c static int __fdt_parse_domain(void *fdt, int · line 319

Quoted 7 lines
lib/utils/fdt/fdt_domain.c +1 -1
@@ -313,7 +314,7 @@ static int __fdt_parse_domain(void *fdt, int
 domain_offset, void *opaque)
 
 	/* Setup memregions from DT */
 	val32 = 0;
-	sbi_memset(regions, 0,
+	memset(regions, 0,
 		   sizeof(*regions) * (FDT_DOMAIN_REGION_MAX_COUNT +

1));

Quoted 16 lines
lib/utils/fdt/fdt_domain.c +0 -0
 	dom->regions = regions;

err = fdt_iterate_each_memregion(fdt, domain_offset, &val32, @@
-337,7 +338,7 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque)

lib/utils/fdt/fdt_domain.c +1 -2
 			continue;
 		if (FDT_DOMAIN_REGION_MAX_COUNT <= val32)
 			return SBI_EINVAL;
-		sbi_memcpy(&regions[val32++], reg, sizeof(*reg));
+		memcpy(&regions[val32++], reg, sizeof(*reg));
 	}
 
 	/* Read "boot-hart" DT property */
--

2.30.1

#9 lore raw

PATCH v2 3/3 lib: utils: Replace strcmp with strncmp

In reply to Daniel Schaefer
---
 lib/utils/fdt/fdt_domain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/utils/fdt/fdt_domain.c +1 -1
index fc8ad423eb88..676c75790829 100644
@@ -96,7 +96,7 @@ static int __fixup_find_domain_offset(void *fdt, int doff, void *p)
 {
 	struct __fixup_find_domain_offset_info *fdo = p;
 
-	if (!strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
+	if (!strncmp(fdo->name, fdt_get_name(fdt, doff, NULL), strlen(fdo->name)))
 		*fdo->doffset = doff;
 
 	return 0;
Signature · 1 line
2.30.1
#10 lore raw

PATCH v2 3/3 lib: utils: Replace strcmp with strncmp

Quoted 10 lines

-----Original Message-----
From: Daniel Schaefer <[email protected]>
Sent: 19 May 2021 13:24
To: opensbi at lists.infradead.org
Cc: Abner Chang <[email protected]>; Anup Patel <[email protected]>; Xiang W <[email protected]>
Subject: [PATCH v2 3/3] lib: utils: Replace strcmp with strncmp

Quoted 5 lines

Looks good to me. I have added some commit description at time of merging this patch.

Regards,
Anup

Quoted 20 lines
---
 lib/utils/fdt/fdt_domain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/utils/fdt/fdt_domain.c index renamed from lib/utils/fdt/fdt_domain.c +0 -0

fc8ad423eb88..676c75790829 100644

lib/utils/fdt/fdt_domain.c +2 -2
@@ -96,7 +96,7 @@ static int __fixup_find_domain_offset(void *fdt, int
 doff, void *p)  {
 	struct __fixup_find_domain_offset_info *fdo = p;
 
-	if (!strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
+	if (!strncmp(fdo->name, fdt_get_name(fdt, doff, NULL),
+strlen(fdo->name)))
 		*fdo->doffset = doff;
 
 	return 0;
--

2.30.1