Use standard C string APIs in FDT helper
cover Use standard C string APIs in FDT helper
Use strncmp instead of using sbi_strcmp directly in fdthelp.c.
- This keeps the consistency with lidfdt implementation and utilizing libfdt_evn.h for the different build environment even fdlhelp.c is not part of standard fdt library.
- In libfdt_evn.h, a macro overrides strncmp with sbi_strncmp.
- For edk2 firmware solution, similar macro is used to repalce strncmp with EDK2 string API.
- Use strncmp instead of strcmp, which is much safer.
Abner Chang (3):
Use standard C string APIs in FDT helper
Use standard C string APIs in FDT helper
Use standard C string APIs in FDT helper
include/sbi/sbi_string.h | 2 +- lib/sbi/sbi_string.c | 4 ++-- lib/utils/fdt/fdt_helper.c | 2 +- lib/utils/libfdt/libfdt_env.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
Signature · 1 line
2.25.0
PATCH 1/3 Use standard C string APIs in FDT helper
Use strncmp instead of using sbi_strcmp directly in fdthelp.c.
- This commit add implementation of sbi_strncmp.
--- include/sbi/sbi_string.h | 2 +- lib/sbi/sbi_string.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
include/sbi/sbi_string.h +1 -1
@@ -12,7 +12,7 @@#include <sbi/sbi_types.h> -int sbi_strcmp (const char *a,const char *b); +int sbi_strncmp (const char *a,const char *b,size_t count);size_t sbi_strlen (const char *str);
lib/sbi/sbi_string.c +2 -2
@@ -14,10 +14,10 @@#include <sbi/sbi_string.h> -int sbi_strcmp (const char *a,const char *b) +int sbi_strncmp (const char *a,const char *b,size_t count) {/* search first diff or end of string */ -for (; *a == *b && *a !='\0' ; a++, b++) +for (; count >0 && *a == *b && *a !='\0' ; a++, b++, count--) ;return *a - *b;
Signature · 1 line
2.25.0
PATCH 2/3 Use standard C string APIs in FDT helper
In reply to Abner ChangUse strncmp instead of using sbi_strcmp directly in fdthelp.c.
- This commit add a macro to replace strncmp with sbi_strncmp.
--- lib/utils/libfdt/libfdt_env.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/utils/libfdt/libfdt_env.h +1 -1
@@ -31,9 +31,9 @@#define strchr sbi_strchr#define strrchr sbi_strrchr#define strcpy sbi_strcpy -#define strcmp sbi_strcmp#define strlen sbi_strlen#define strnlen sbi_strnlen +#define strncmp sbi_strncmp typedef uint16_t FDT_BITWISE fdt16_t; typedef uint32_t FDT_BITWISE fdt32_t;
Signature · 1 line
2.25.0
PATCH 3/3 Use standard C string APIs in FDT helper
In reply to Abner ChangUse strncmp instead of using sbi_strcmp directly in fdthelp.c.
--- lib/utils/fdt/fdt_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/utils/fdt/fdt_helper.c +1 -1
@@ -123,7 +123,7 @@ int fdt_parse_hart_id(void *fdt, int cpu_offset, u32 *hartid) prop =fdt_getprop (fdt, cpu_offset,"device_type" , &len);if (!prop || !len)return SBI_EINVAL ; -if (sbi_strcmp (prop,"cpu" )) +if (strncmp (prop,"cpu" ,strlen ("cpu" )))return SBI_EINVAL ; val =fdt_getprop (fdt, cpu_offset,"reg" , &len);
Signature · 1 line
2.25.0
PATCH 1/3 Use standard C string APIs in FDT helper
In reply to Abner ChangQuoted 54 lines
-----Original Message-----
From: Abner Chang <[email protected]>
Sent: 23 July 2020 07:24
To: opensbi at lists.infradead.org
Cc: abner.chang at hpe.com; Atish Patra <[email protected]>; Anup Patel <[email protected]>; Daniel Schaefer <[email protected]>
Subject: [PATCH 1/3] Use standard C string APIs in FDT helperUse strncmp instead of using
sbi_strcmpdirectly infdthelp.c.
- This commit add implementation ofsbi_strncmp.Signed-off-by Abner Chang <[email protected]>Cc Atish Patra <[email protected]>Cc Anup Patel <[email protected]>Cc Daniel Schaefer <[email protected]>--- include/sbi/sbi_string.h | 2 +- lib/sbi/sbi_string.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)include/sbi/sbi_string.h index renamed from include/sbi/sbi_string.h +0
-0338075f..5e7304f 100644
include/sbi/sbi_string.h +1
-1@@ -12,7 +12,7 @@#include <sbi/sbi_types.h> -int sbi_strcmp (const char *a,const char *b); +int sbi_strncmp (const char *a,const char *b,size_t count);size_t sbi_strlen (const char *str);lib/sbi/sbi_string.c index 38b700b..c29120a renamed from lib/sbi/sbi_string.c +0
-0100644
lib/sbi/sbi_string.c +2
-3@@ -14,10 +14,10 @@#include <sbi/sbi_string.h> -int sbi_strcmp (const char *a,const char *b) +int sbi_strncmp (const char *a,const char *b,size_t count) {/* search first diff or end of string */ -for (; *a == *b && *a !='\0' ; a++, b++) +for (; count >0 && *a == *b && *a !='\0' ; a++, b++, count--) ;return *a - *b; --
Quoted 1 line
2.25.0
I think we should keep both sbi_strcmp() and sbi_strncmp().
Otherwise looks good to me.
Regards,
Anup
PATCH 2/3 Use standard C string APIs in FDT helper
In reply to Abner ChangQuoted 38 lines
-----Original Message-----
From: Abner Chang <[email protected]>
Sent: 23 July 2020 07:24
To: opensbi at lists.infradead.org
Cc: abner.chang at hpe.com; Atish Patra <[email protected]>; Anup Patel <[email protected]>; Daniel Schaefer <[email protected]>
Subject: [PATCH 2/3] Use standard C string APIs in FDT helperUse strncmp instead of using
sbi_strcmpdirectly infdthelp.c.
- This commit add a macro to replace strncmp withsbi_strncmp.Signed-off-by Abner Chang <[email protected]>Cc Atish Patra <[email protected]>Cc Anup Patel <[email protected]>Cc Daniel Schaefer <[email protected]>--- lib/utils/libfdt/libfdt_env.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/utils/libfdt/libfdt_env.h index renamed from lib/utils/libfdt/libfdt_env.h +0
-07fcfe01..a9be6a8 100644
lib/utils/libfdt/libfdt_env.h +1
-2@@ -31,9 +31,9 @@#define strchr sbi_strchr#define strrchr sbi_strrchr#define strcpy sbi_strcpy -#define strcmp sbi_strcmp#define strlen sbi_strlen#define strnlen sbi_strnlen +#define strncmp sbi_strncmp typedef uint16_t FDT_BITWISE fdt16_t; typedef uint32_t FDT_BITWISE fdt32_t; --
Quoted 1 line
2.25.0
Looks good to me.
Regards,
Anup
PATCH 3/3 Use standard C string APIs in FDT helper
In reply to Abner ChangQuoted 34 lines
-----Original Message-----
From: Abner Chang <[email protected]>
Sent: 23 July 2020 07:24
To: opensbi at lists.infradead.org
Cc: abner.chang at hpe.com; Atish Patra <[email protected]>; Anup Patel <[email protected]>; Daniel Schaefer <[email protected]>
Subject: [PATCH 3/3] Use standard C string APIs in FDT helperUse strncmp instead of using
sbi_strcmpdirectly infdthelp.c.Signed-off-by Abner Chang <[email protected]>Cc Atish Patra <[email protected]>Cc Anup Patel <[email protected]>Cc Daniel Schaefer <[email protected]>--- lib/utils/fdt/fdt_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/utils/fdt/fdt_helper.c index renamed from lib/utils/fdt/fdt_helper.c +0
-078077f7..aec73a0 100644
lib/utils/fdt/fdt_helper.c +1
-1@@ -123,7 +123,7 @@ int fdt_parse_hart_id(void *fdt, int cpu_offset, u32 *hartid) prop =fdt_getprop (fdt, cpu_offset,"device_type" , &len);if (!prop || !len)return SBI_EINVAL ; -if (sbi_strcmp (prop,"cpu" )) +if (strncmp (prop,"cpu" ,strlen ("cpu" )))return SBI_EINVAL ;
Quoted 3 lines
val =
fdt_getprop(fdt, cpu_offset, "reg", &len);
--
2.25.0
Looks good to me.
Regards,
Anup
Chang
PATCH 1/3 Use standard C string APIs in FDT helper
In reply to Anup PatelQuoted 65 lines
-----Original Message-----
From: Anup Patel [mailto:Anup.Patel at wdc.com]
Sent: Friday, July 24, 2020 12:37 PM
To: Chang, Abner (HPS SW/FW Technologist) <[email protected]>; opensbi at lists.infradead.org
Cc: Atish Patra <[email protected]>; Schaefer, Daniel (DualStudy) <[email protected]>
Subject: RE: [PATCH 1/3] Use standard C string APIs in FDT helperQuoted 5 lines
-----Original Message-----
From: Abner Chang <[email protected]>
Sent: 23 July 2020 07:24
To: opensbi at lists.infradead.org
Cc: abner.chang at hpe.com; Atish Patra <[email protected]>; AnupPatel
Quoted 46 lines
<[email protected]>; Daniel Schaefer <[email protected]>
Subject: [PATCH 1/3] Use standard C string APIs in FDT helperUse strncmp instead of using
sbi_strcmpdirectly infdthelp.c.
- This commit add implementation ofsbi_strncmp.Signed-off-by Abner Chang <[email protected]>Cc Atish Patra <[email protected]>Cc Anup Patel <[email protected]>Cc Daniel Schaefer <[email protected]>--- include/sbi/sbi_string.h | 2 +- lib/sbi/sbi_string.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)include/sbi/sbi_string.h index renamed from include/sbi/sbi_string.h +0
-0338075f..5e7304f 100644
include/sbi/sbi_string.h +1
-1@@ -12,7 +12,7 @@#include <sbi/sbi_types.h> -int sbi_strcmp (const char *a,const char *b); +int sbi_strncmp (const char *a,const char *b,size_t count);size_t sbi_strlen (const char *str);lib/sbi/sbi_string.c index renamed from lib/sbi/sbi_string.c +0
-038b700b..c29120a
100644lib/sbi/sbi_string.c +2
-2@@ -14,10 +14,10 @@#include <sbi/sbi_string.h> -int sbi_strcmp (const char *a,const char *b) +int sbi_strncmp (const char *a,const char *b,size_t count) {/* search first diff or end of string */ -for (; *a == *b && *a !='\0' ; a++, b++) +for (; count >0 && *a == *b && *a !='\0' ; a++, b++, count--) ;
Quoted 5 lines
Quoted 3 lines
lib/sbi/sbi_string.c +0
-1return *a - *b; --2.25.0
I think we should keep both
sbi_strcmp()andsbi_strncmp().
Hi Anup, do you think we should prevent people to use sbi_strcmp()?
Thanks
Abner
Quoted 7 lines
Otherwise looks good to me.
Reviewed-by Anup Patel <[email protected]>Regards,
Anup
PATCH 1/3 Use standard C string APIs in FDT helper
Quoted 66 lines · Abner (HPS SW/FW Technologist)
Quoted 66 lines
-----Original Message-----
From: Anup Patel [mailto:Anup.Patel at wdc.com]
Sent: Friday, July 24, 2020 12:37 PM
To: Chang, Abner (HPS SW/FW Technologist) <[email protected]>; opensbi at lists.infradead.org
Cc: Atish Patra <[email protected]>; Schaefer, Daniel (DualStudy) <[email protected]>
Subject: RE: [PATCH 1/3] Use standard C string APIs in FDT helperQuoted 5 lines
-----Original Message-----
From: Abner Chang <[email protected]>
Sent: 23 July 2020 07:24
To: opensbi at lists.infradead.org
Cc: abner.chang at hpe.com; Atish Patra <[email protected]>; AnupPatel
Quoted 46 lines
<[email protected]>; Daniel Schaefer <[email protected]>
Subject: [PATCH 1/3] Use standard C string APIs in FDT helperUse strncmp instead of using
sbi_strcmpdirectly infdthelp.c.
- This commit add implementation ofsbi_strncmp.Signed-off-by Abner Chang <[email protected]>Cc Atish Patra <[email protected]>Cc Anup Patel <[email protected]>Cc Daniel Schaefer <[email protected]>--- include/sbi/sbi_string.h | 2 +- lib/sbi/sbi_string.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)include/sbi/sbi_string.h index renamed from include/sbi/sbi_string.h +0
-0338075f..5e7304f 100644
include/sbi/sbi_string.h +1
-1@@ -12,7 +12,7 @@#include <sbi/sbi_types.h> -int sbi_strcmp (const char *a,const char *b); +int sbi_strncmp (const char *a,const char *b,size_t count);size_t sbi_strlen (const char *str);lib/sbi/sbi_string.c index renamed from lib/sbi/sbi_string.c +0
-038b700b..c29120a
100644lib/sbi/sbi_string.c +2
-2@@ -14,10 +14,10 @@#include <sbi/sbi_string.h> -int sbi_strcmp (const char *a,const char *b) +int sbi_strncmp (const char *a,const char *b,size_t count) {/* search first diff or end of string */ -for (; *a == *b && *a !='\0' ; a++, b++) +for (; count >0 && *a == *b && *a !='\0' ; a++, b++, count--) ;
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
lib/sbi/sbi_string.c +0
-1return *a - *b; --2.25.0
I think we should keep both
sbi_strcmp()andsbi_strncmp().Hi Anup, do you think we should prevent people to use
sbi_strcmp()?
The only reason we may want to keep the sbi_strcmp() just for completeness sake. In case, some of the libfdt functions use it in some revision.
If we decide to keep it, we should put a big comment on top sbi_strcmp clearly mentioning that
it is not recommended to use sbi_strcmp at all.
Quoted 15 lines
Thanks
AbnerQuoted 7 lines
Otherwise looks good to me.
Reviewed-by Anup Patel <[email protected]>Regards,
Anup--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Signature · 2 lines
Regards, Atish
PATCH 1/3 Use standard C string APIs in FDT helper
Quoted 101 lines · Atish Patra
Quoted 66 lines · Abner (HPS SW/FW Technologist)
Quoted 66 lines
-----Original Message-----
From: Anup Patel [mailto:Anup.Patel at wdc.com]
Sent: Friday, July 24, 2020 12:37 PM
To: Chang, Abner (HPS SW/FW Technologist) <[email protected]>; opensbi at lists.infradead.org
Cc: Atish Patra <[email protected]>; Schaefer, Daniel (DualStudy) <[email protected]>
Subject: RE: [PATCH 1/3] Use standard C string APIs in FDT helperQuoted 5 lines
-----Original Message-----
From: Abner Chang <[email protected]>
Sent: 23 July 2020 07:24
To: opensbi at lists.infradead.org
Cc: abner.chang at hpe.com; Atish Patra <[email protected]>; AnupPatel
Quoted 46 lines
<[email protected]>; Daniel Schaefer <[email protected]>
Subject: [PATCH 1/3] Use standard C string APIs in FDT helperUse strncmp instead of using
sbi_strcmpdirectly infdthelp.c.
- This commit add implementation ofsbi_strncmp.Signed-off-by Abner Chang <[email protected]>Cc Atish Patra <[email protected]>Cc Anup Patel <[email protected]>Cc Daniel Schaefer <[email protected]>--- include/sbi/sbi_string.h | 2 +- lib/sbi/sbi_string.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)include/sbi/sbi_string.h index renamed from include/sbi/sbi_string.h +0
-0338075f..5e7304f 100644
include/sbi/sbi_string.h +1
-1@@ -12,7 +12,7 @@#include <sbi/sbi_types.h> -int sbi_strcmp (const char *a,const char *b); +int sbi_strncmp (const char *a,const char *b,size_t count);size_t sbi_strlen (const char *str);lib/sbi/sbi_string.c index renamed from lib/sbi/sbi_string.c +0
-038b700b..c29120a
100644lib/sbi/sbi_string.c +2
-2@@ -14,10 +14,10 @@#include <sbi/sbi_string.h> -int sbi_strcmp (const char *a,const char *b) +int sbi_strncmp (const char *a,const char *b,size_t count) {/* search first diff or end of string */ -for (; *a == *b && *a !='\0' ; a++, b++) +for (; count >0 && *a == *b && *a !='\0' ; a++, b++, count--) ;Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
lib/sbi/sbi_string.c +0
-1return *a - *b; --2.25.0
I think we should keep both
sbi_strcmp()andsbi_strncmp().Hi Anup, do you think we should prevent people to use
sbi_strcmp()?The only reason we may want to keep the
sbi_strcmp()just for completeness sake. In case, some of the libfdt functions use it in some revision.If we decide to keep it, we should put a big comment on top
sbi_strcmpclearly mentioning that
it is not recommended to usesbi_strcmpat all.Quoted 7 lines
Thanks
AbnerQuoted 5 lines
Otherwise looks good to me.
Reviewed-by Anup Patel <[email protected]>Quoted 8 lines
Quoted 2 lines
Regards,
Anup--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Quoted 3 lines
--
Regards,
Atish
For the entire series:
Signature · 2 lines
Regards, Atish
Chang
PATCH 1/3 Use standard C string APIs in FDT helper
In reply to Atish PatraQuoted 84 lines
-----Original Message-----
From: Atish Patra [mailto:atishp at atishpatra.org]
Sent: Saturday, July 25, 2020 1:21 PM
To: Chang, Abner (HPS SW/FW Technologist) <[email protected]>
Cc: Anup Patel <[email protected]>; opensbi at lists.infradead.org; Atish Patra <[email protected]>; Schaefer, Daniel (DualStudy) <[email protected]>
Subject: Re: [PATCH 1/3] Use standard C string APIs in FDT helperQuoted 71 lines · Abner (HPS SW/FW Technologist)
Quoted 71 lines
-----Original Message-----
From: Anup Patel [mailto:Anup.Patel at wdc.com]
Sent: Friday, July 24, 2020 12:37 PM
To: Chang, Abner (HPS SW/FW Technologist) <[email protected]>; opensbi at lists.infradead.org
Cc: Atish Patra <[email protected]>; Schaefer, Daniel (DualStudy) <[email protected]>
Subject: RE: [PATCH 1/3] Use standard C string APIs in FDT helperQuoted 5 lines
-----Original Message-----
From: Abner Chang <[email protected]>
Sent: 23 July 2020 07:24
To: opensbi at lists.infradead.org
Cc: abner.chang at hpe.com; Atish Patra <[email protected]>; AnupPatel
Quoted 48 lines
<[email protected]>; Daniel Schaefer <[email protected]>
Subject: [PATCH 1/3] Use standard C string APIs in FDT helperUse strncmp instead of using
sbi_strcmpdirectly infdthelp.c.
- This commit add implementation ofsbi_strncmp.Signed-off-by Abner Chang <[email protected]>Cc Atish Patra <[email protected]>Cc Anup Patel <[email protected]>Cc Daniel Schaefer <[email protected]>--- include/sbi/sbi_string.h | 2 +- lib/sbi/sbi_string.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)include/sbi/sbi_string.h +1
-1@@ -12,7 +12,7 @@#include <sbi/sbi_types.h> -int sbi_strcmp (const char *a,const char *b); +int sbi_strncmp (const char *a,const char *b,size_t count);size_t sbi_strlen (const char *str);lib/sbi/sbi_string.c index renamed from lib/sbi/sbi_string.c +0
-038b700b..c29120a
100644lib/sbi/sbi_string.c +2
-3@@ -14,10 +14,10 @@#include <sbi/sbi_string.h> -int sbi_strcmp (const char *a,const char *b) +int sbi_strncmp (const char *a,const char *b,size_t count) {/* search first diff or end of string */ -for (; *a == *b && *a !='\0' ; a++, b++) +for (; count >0 && *a == *b && *a !='\0' ; a++, b++, count--) ;return *a - *b; --Quoted 1 line
2.25.0
I think we should keep both
sbi_strcmp()andsbi_strncmp().
Quoted 8 lines
Quoted 2 lines
Hi Anup, do you think we should prevent people to use
sbi_strcmp()?The only reason we may want to keep the
sbi_strcmp()just for completeness sake.
In case, some of the libfdt functions use it in some revision.If we decide to keep it, we should put a big comment on top
sbi_strcmpclearly mentioning that it is not recommended to usesbi_strcmpat all.
Understand. I will keep it and resend the patch.
Thanks
Quoted 22 lines
Quoted 8 lines
Thanks
AbnerQuoted 5 lines
Otherwise looks good to me.
Reviewed-by Anup Patel <[email protected]>Quoted 8 lines
Quoted 2 lines
Regards,
Anup--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi--
Regards,
Atish