* [PATCH 0/3] Use standard C string APIs in FDT helper
@ 2020-07-23 1:54 Abner Chang
2020-07-23 1:54 ` [PATCH 1/3] " Abner Chang
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Abner Chang @ 2020-07-23 1:54 UTC (permalink / raw)
To: opensbi
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(-)
--
2.25.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/3] Use standard C string APIs in FDT helper
2020-07-23 1:54 [PATCH 0/3] Use standard C string APIs in FDT helper Abner Chang
@ 2020-07-23 1:54 ` Abner Chang
2020-07-24 4:37 ` Anup Patel
2020-07-23 1:54 ` [PATCH 2/3] " Abner Chang
2020-07-23 1:54 ` [PATCH 3/3] " Abner Chang
2 siblings, 1 reply; 11+ messages in thread
From: Abner Chang @ 2020-07-23 1:54 UTC (permalink / raw)
To: opensbi
Use strncmp instead of using sbi_strcmp directly in fdthelp.c.
- This commit add implementation of sbi_strncmp.
Signed-off-by: Abner Chang <abner.chang@hpe.com>
Cc: Atish Patra <atish.patra@wdc.com>
Cc: Anup Patel <anup.patel@wdc.com>
Cc: Daniel Schaefer <daniel.schaefer@hpe.com>
---
include/sbi/sbi_string.h | 2 +-
lib/sbi/sbi_string.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/sbi/sbi_string.h b/include/sbi/sbi_string.h
index 338075f..5e7304f 100644
--- a/include/sbi/sbi_string.h
+++ b/include/sbi/sbi_string.h
@@ -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);
diff --git a/lib/sbi/sbi_string.c b/lib/sbi/sbi_string.c
index 38b700b..c29120a 100644
--- a/lib/sbi/sbi_string.c
+++ b/lib/sbi/sbi_string.c
@@ -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;
--
2.25.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/3] Use standard C string APIs in FDT helper
2020-07-23 1:54 [PATCH 0/3] Use standard C string APIs in FDT helper Abner Chang
2020-07-23 1:54 ` [PATCH 1/3] " Abner Chang
@ 2020-07-23 1:54 ` Abner Chang
2020-07-24 4:38 ` Anup Patel
2020-07-23 1:54 ` [PATCH 3/3] " Abner Chang
2 siblings, 1 reply; 11+ messages in thread
From: Abner Chang @ 2020-07-23 1:54 UTC (permalink / raw)
To: opensbi
Use strncmp instead of using sbi_strcmp directly in fdthelp.c.
- This commit add a macro to replace strncmp with sbi_strncmp.
Signed-off-by: Abner Chang <abner.chang@hpe.com>
Cc: Atish Patra <atish.patra@wdc.com>
Cc: Anup Patel <anup.patel@wdc.com>
Cc: Daniel Schaefer <daniel.schaefer@hpe.com>
---
lib/utils/libfdt/libfdt_env.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/utils/libfdt/libfdt_env.h b/lib/utils/libfdt/libfdt_env.h
index 7fcfe01..a9be6a8 100644
--- a/lib/utils/libfdt/libfdt_env.h
+++ b/lib/utils/libfdt/libfdt_env.h
@@ -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;
--
2.25.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/3] Use standard C string APIs in FDT helper
2020-07-23 1:54 [PATCH 0/3] Use standard C string APIs in FDT helper Abner Chang
2020-07-23 1:54 ` [PATCH 1/3] " Abner Chang
2020-07-23 1:54 ` [PATCH 2/3] " Abner Chang
@ 2020-07-23 1:54 ` Abner Chang
2020-07-24 4:40 ` Anup Patel
2 siblings, 1 reply; 11+ messages in thread
From: Abner Chang @ 2020-07-23 1:54 UTC (permalink / raw)
To: opensbi
Use strncmp instead of using sbi_strcmp directly in fdthelp.c.
Signed-off-by: Abner Chang <abner.chang@hpe.com>
Cc: Atish Patra <atish.patra@wdc.com>
Cc: Anup Patel <anup.patel@wdc.com>
Cc: Daniel Schaefer <daniel.schaefer@hpe.com>
---
lib/utils/fdt/fdt_helper.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/utils/fdt/fdt_helper.c b/lib/utils/fdt/fdt_helper.c
index 78077f7..aec73a0 100644
--- a/lib/utils/fdt/fdt_helper.c
+++ b/lib/utils/fdt/fdt_helper.c
@@ -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);
--
2.25.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 1/3] Use standard C string APIs in FDT helper
2020-07-23 1:54 ` [PATCH 1/3] " Abner Chang
@ 2020-07-24 4:37 ` Anup Patel
2020-07-24 5:38 ` Chang, Abner
0 siblings, 1 reply; 11+ messages in thread
From: Anup Patel @ 2020-07-24 4:37 UTC (permalink / raw)
To: opensbi
> -----Original Message-----
> From: Abner Chang <abner.chang@hpe.com>
> Sent: 23 July 2020 07:24
> To: opensbi at lists.infradead.org
> Cc: abner.chang at hpe.com; Atish Patra <Atish.Patra@wdc.com>; Anup Patel
> <Anup.Patel@wdc.com>; Daniel Schaefer <daniel.schaefer@hpe.com>
> Subject: [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.
>
> Signed-off-by: Abner Chang <abner.chang@hpe.com>
>
> Cc: Atish Patra <atish.patra@wdc.com>
> Cc: Anup Patel <anup.patel@wdc.com>
> Cc: Daniel Schaefer <daniel.schaefer@hpe.com>
> ---
> include/sbi/sbi_string.h | 2 +-
> lib/sbi/sbi_string.c | 4 ++--
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/include/sbi/sbi_string.h b/include/sbi/sbi_string.h index
> 338075f..5e7304f 100644
> --- a/include/sbi/sbi_string.h
> +++ b/include/sbi/sbi_string.h
> @@ -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);
>
> diff --git a/lib/sbi/sbi_string.c b/lib/sbi/sbi_string.c index 38b700b..c29120a
> 100644
> --- a/lib/sbi/sbi_string.c
> +++ b/lib/sbi/sbi_string.c
> @@ -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;
> --
> 2.25.0
I think we should keep both sbi_strcmp() and sbi_strncmp().
Otherwise looks good to me.
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Regards,
Anup
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 2/3] Use standard C string APIs in FDT helper
2020-07-23 1:54 ` [PATCH 2/3] " Abner Chang
@ 2020-07-24 4:38 ` Anup Patel
0 siblings, 0 replies; 11+ messages in thread
From: Anup Patel @ 2020-07-24 4:38 UTC (permalink / raw)
To: opensbi
> -----Original Message-----
> From: Abner Chang <abner.chang@hpe.com>
> Sent: 23 July 2020 07:24
> To: opensbi at lists.infradead.org
> Cc: abner.chang at hpe.com; Atish Patra <Atish.Patra@wdc.com>; Anup Patel
> <Anup.Patel@wdc.com>; Daniel Schaefer <daniel.schaefer@hpe.com>
> Subject: [PATCH 2/3] Use standard C string APIs in FDT helper
>
> Use strncmp instead of using sbi_strcmp directly in fdthelp.c.
> - This commit add a macro to replace strncmp with sbi_strncmp.
>
> Signed-off-by: Abner Chang <abner.chang@hpe.com>
>
> Cc: Atish Patra <atish.patra@wdc.com>
> Cc: Anup Patel <anup.patel@wdc.com>
> Cc: Daniel Schaefer <daniel.schaefer@hpe.com>
> ---
> lib/utils/libfdt/libfdt_env.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/utils/libfdt/libfdt_env.h b/lib/utils/libfdt/libfdt_env.h index
> 7fcfe01..a9be6a8 100644
> --- a/lib/utils/libfdt/libfdt_env.h
> +++ b/lib/utils/libfdt/libfdt_env.h
> @@ -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;
> --
> 2.25.0
Looks good to me.
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Regards,
Anup
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 3/3] Use standard C string APIs in FDT helper
2020-07-23 1:54 ` [PATCH 3/3] " Abner Chang
@ 2020-07-24 4:40 ` Anup Patel
0 siblings, 0 replies; 11+ messages in thread
From: Anup Patel @ 2020-07-24 4:40 UTC (permalink / raw)
To: opensbi
> -----Original Message-----
> From: Abner Chang <abner.chang@hpe.com>
> Sent: 23 July 2020 07:24
> To: opensbi at lists.infradead.org
> Cc: abner.chang at hpe.com; Atish Patra <Atish.Patra@wdc.com>; Anup Patel
> <Anup.Patel@wdc.com>; Daniel Schaefer <daniel.schaefer@hpe.com>
> Subject: [PATCH 3/3] Use standard C string APIs in FDT helper
>
> Use strncmp instead of using sbi_strcmp directly in fdthelp.c.
>
> Signed-off-by: Abner Chang <abner.chang@hpe.com>
>
> Cc: Atish Patra <atish.patra@wdc.com>
> Cc: Anup Patel <anup.patel@wdc.com>
> Cc: Daniel Schaefer <daniel.schaefer@hpe.com>
> ---
> lib/utils/fdt/fdt_helper.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/utils/fdt/fdt_helper.c b/lib/utils/fdt/fdt_helper.c index
> 78077f7..aec73a0 100644
> --- a/lib/utils/fdt/fdt_helper.c
> +++ b/lib/utils/fdt/fdt_helper.c
> @@ -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);
> --
> 2.25.0
Looks good to me.
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Regards,
Anup
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/3] Use standard C string APIs in FDT helper
2020-07-24 4:37 ` Anup Patel
@ 2020-07-24 5:38 ` Chang, Abner
2020-07-25 5:21 ` Atish Patra
0 siblings, 1 reply; 11+ messages in thread
From: Chang, Abner @ 2020-07-24 5:38 UTC (permalink / raw)
To: opensbi
> -----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) <abner.chang@hpe.com>;
> opensbi at lists.infradead.org
> Cc: Atish Patra <Atish.Patra@wdc.com>; Schaefer, Daniel (DualStudy)
> <daniel.schaefer@hpe.com>
> Subject: RE: [PATCH 1/3] Use standard C string APIs in FDT helper
>
>
>
> > -----Original Message-----
> > From: Abner Chang <abner.chang@hpe.com>
> > Sent: 23 July 2020 07:24
> > To: opensbi at lists.infradead.org
> > Cc: abner.chang at hpe.com; Atish Patra <Atish.Patra@wdc.com>; Anup
> Patel
> > <Anup.Patel@wdc.com>; Daniel Schaefer <daniel.schaefer@hpe.com>
> > Subject: [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.
> >
> > Signed-off-by: Abner Chang <abner.chang@hpe.com>
> >
> > Cc: Atish Patra <atish.patra@wdc.com>
> > Cc: Anup Patel <anup.patel@wdc.com>
> > Cc: Daniel Schaefer <daniel.schaefer@hpe.com>
> > ---
> > include/sbi/sbi_string.h | 2 +-
> > lib/sbi/sbi_string.c | 4 ++--
> > 2 files changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/include/sbi/sbi_string.h b/include/sbi/sbi_string.h index
> > 338075f..5e7304f 100644
> > --- a/include/sbi/sbi_string.h
> > +++ b/include/sbi/sbi_string.h
> > @@ -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);
> >
> > diff --git a/lib/sbi/sbi_string.c b/lib/sbi/sbi_string.c index
> > 38b700b..c29120a
> > 100644
> > --- a/lib/sbi/sbi_string.c
> > +++ b/lib/sbi/sbi_string.c
> > @@ -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;
> > --
> > 2.25.0
>
> I think we should keep both sbi_strcmp() and sbi_strncmp().
Hi Anup, do you think we should prevent people to use sbi_strcmp()?
Thanks
Abner
>
> Otherwise looks good to me.
>
> Reviewed-by: Anup Patel <anup.patel@wdc.com>
>
> Regards,
> Anup
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/3] Use standard C string APIs in FDT helper
2020-07-24 5:38 ` Chang, Abner
@ 2020-07-25 5:21 ` Atish Patra
2020-07-25 5:22 ` Atish Patra
2020-07-25 9:20 ` Chang, Abner
0 siblings, 2 replies; 11+ messages in thread
From: Atish Patra @ 2020-07-25 5:21 UTC (permalink / raw)
To: opensbi
On Thu, Jul 23, 2020 at 10:38 PM Chang, Abner (HPS SW/FW Technologist)
<abner.chang@hpe.com> wrote:
>
>
>
> > -----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) <abner.chang@hpe.com>;
> > opensbi at lists.infradead.org
> > Cc: Atish Patra <Atish.Patra@wdc.com>; Schaefer, Daniel (DualStudy)
> > <daniel.schaefer@hpe.com>
> > Subject: RE: [PATCH 1/3] Use standard C string APIs in FDT helper
> >
> >
> >
> > > -----Original Message-----
> > > From: Abner Chang <abner.chang@hpe.com>
> > > Sent: 23 July 2020 07:24
> > > To: opensbi at lists.infradead.org
> > > Cc: abner.chang at hpe.com; Atish Patra <Atish.Patra@wdc.com>; Anup
> > Patel
> > > <Anup.Patel@wdc.com>; Daniel Schaefer <daniel.schaefer@hpe.com>
> > > Subject: [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.
> > >
> > > Signed-off-by: Abner Chang <abner.chang@hpe.com>
> > >
> > > Cc: Atish Patra <atish.patra@wdc.com>
> > > Cc: Anup Patel <anup.patel@wdc.com>
> > > Cc: Daniel Schaefer <daniel.schaefer@hpe.com>
> > > ---
> > > include/sbi/sbi_string.h | 2 +-
> > > lib/sbi/sbi_string.c | 4 ++--
> > > 2 files changed, 3 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/include/sbi/sbi_string.h b/include/sbi/sbi_string.h index
> > > 338075f..5e7304f 100644
> > > --- a/include/sbi/sbi_string.h
> > > +++ b/include/sbi/sbi_string.h
> > > @@ -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);
> > >
> > > diff --git a/lib/sbi/sbi_string.c b/lib/sbi/sbi_string.c index
> > > 38b700b..c29120a
> > > 100644
> > > --- a/lib/sbi/sbi_string.c
> > > +++ b/lib/sbi/sbi_string.c
> > > @@ -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;
> > > --
> > > 2.25.0
> >
> > I think we should keep both sbi_strcmp() and sbi_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.
> Thanks
> Abner
> >
> > Otherwise looks good to me.
> >
> > Reviewed-by: Anup Patel <anup.patel@wdc.com>
> >
> > Regards,
> > Anup
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
--
Regards,
Atish
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/3] Use standard C string APIs in FDT helper
2020-07-25 5:21 ` Atish Patra
@ 2020-07-25 5:22 ` Atish Patra
2020-07-25 9:20 ` Chang, Abner
1 sibling, 0 replies; 11+ messages in thread
From: Atish Patra @ 2020-07-25 5:22 UTC (permalink / raw)
To: opensbi
On Fri, Jul 24, 2020 at 10:21 PM Atish Patra <atishp@atishpatra.org> wrote:
>
> On Thu, Jul 23, 2020 at 10:38 PM Chang, Abner (HPS SW/FW Technologist)
> <abner.chang@hpe.com> wrote:
> >
> >
> >
> > > -----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) <abner.chang@hpe.com>;
> > > opensbi at lists.infradead.org
> > > Cc: Atish Patra <Atish.Patra@wdc.com>; Schaefer, Daniel (DualStudy)
> > > <daniel.schaefer@hpe.com>
> > > Subject: RE: [PATCH 1/3] Use standard C string APIs in FDT helper
> > >
> > >
> > >
> > > > -----Original Message-----
> > > > From: Abner Chang <abner.chang@hpe.com>
> > > > Sent: 23 July 2020 07:24
> > > > To: opensbi at lists.infradead.org
> > > > Cc: abner.chang at hpe.com; Atish Patra <Atish.Patra@wdc.com>; Anup
> > > Patel
> > > > <Anup.Patel@wdc.com>; Daniel Schaefer <daniel.schaefer@hpe.com>
> > > > Subject: [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.
> > > >
> > > > Signed-off-by: Abner Chang <abner.chang@hpe.com>
> > > >
> > > > Cc: Atish Patra <atish.patra@wdc.com>
> > > > Cc: Anup Patel <anup.patel@wdc.com>
> > > > Cc: Daniel Schaefer <daniel.schaefer@hpe.com>
> > > > ---
> > > > include/sbi/sbi_string.h | 2 +-
> > > > lib/sbi/sbi_string.c | 4 ++--
> > > > 2 files changed, 3 insertions(+), 3 deletions(-)
> > > >
> > > > diff --git a/include/sbi/sbi_string.h b/include/sbi/sbi_string.h index
> > > > 338075f..5e7304f 100644
> > > > --- a/include/sbi/sbi_string.h
> > > > +++ b/include/sbi/sbi_string.h
> > > > @@ -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);
> > > >
> > > > diff --git a/lib/sbi/sbi_string.c b/lib/sbi/sbi_string.c index
> > > > 38b700b..c29120a
> > > > 100644
> > > > --- a/lib/sbi/sbi_string.c
> > > > +++ b/lib/sbi/sbi_string.c
> > > > @@ -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;
> > > > --
> > > > 2.25.0
> > >
> > > I think we should keep both sbi_strcmp() and sbi_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.
>
> > Thanks
> > Abner
> > >
> > > Otherwise looks good to me.
> > >
> > > Reviewed-by: Anup Patel <anup.patel@wdc.com>
> > >
> > > Regards,
> > > Anup
> >
> >
> > --
> > opensbi mailing list
> > opensbi at lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/opensbi
>
>
>
> --
> Regards,
> Atish
For the entire series:
Reviewed-by: Atish Patra <atish.patra@wdc.com>
--
Regards,
Atish
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/3] Use standard C string APIs in FDT helper
2020-07-25 5:21 ` Atish Patra
2020-07-25 5:22 ` Atish Patra
@ 2020-07-25 9:20 ` Chang, Abner
1 sibling, 0 replies; 11+ messages in thread
From: Chang, Abner @ 2020-07-25 9:20 UTC (permalink / raw)
To: opensbi
> -----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) <abner.chang@hpe.com>
> Cc: Anup Patel <Anup.Patel@wdc.com>; opensbi at lists.infradead.org; Atish
> Patra <Atish.Patra@wdc.com>; Schaefer, Daniel (DualStudy)
> <daniel.schaefer@hpe.com>
> Subject: Re: [PATCH 1/3] Use standard C string APIs in FDT helper
>
> On Thu, Jul 23, 2020 at 10:38 PM Chang, Abner (HPS SW/FW Technologist)
> <abner.chang@hpe.com> wrote:
> >
> >
> >
> > > -----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) <abner.chang@hpe.com>;
> > > opensbi at lists.infradead.org
> > > Cc: Atish Patra <Atish.Patra@wdc.com>; Schaefer, Daniel (DualStudy)
> > > <daniel.schaefer@hpe.com>
> > > Subject: RE: [PATCH 1/3] Use standard C string APIs in FDT helper
> > >
> > >
> > >
> > > > -----Original Message-----
> > > > From: Abner Chang <abner.chang@hpe.com>
> > > > Sent: 23 July 2020 07:24
> > > > To: opensbi at lists.infradead.org
> > > > Cc: abner.chang at hpe.com; Atish Patra <Atish.Patra@wdc.com>; Anup
> > > Patel
> > > > <Anup.Patel@wdc.com>; Daniel Schaefer <daniel.schaefer@hpe.com>
> > > > Subject: [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.
> > > >
> > > > Signed-off-by: Abner Chang <abner.chang@hpe.com>
> > > >
> > > > Cc: Atish Patra <atish.patra@wdc.com>
> > > > Cc: Anup Patel <anup.patel@wdc.com>
> > > > Cc: Daniel Schaefer <daniel.schaefer@hpe.com>
> > > > ---
> > > > include/sbi/sbi_string.h | 2 +-
> > > > lib/sbi/sbi_string.c | 4 ++--
> > > > 2 files changed, 3 insertions(+), 3 deletions(-)
> > > >
> > > > diff --git a/include/sbi/sbi_string.h b/include/sbi/sbi_string.h
> > > > index 338075f..5e7304f 100644
> > > > --- a/include/sbi/sbi_string.h
> > > > +++ b/include/sbi/sbi_string.h
> > > > @@ -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);
> > > >
> > > > diff --git a/lib/sbi/sbi_string.c b/lib/sbi/sbi_string.c index
> > > > 38b700b..c29120a
> > > > 100644
> > > > --- a/lib/sbi/sbi_string.c
> > > > +++ b/lib/sbi/sbi_string.c
> > > > @@ -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;
> > > > --
> > > > 2.25.0
> > >
> > > I think we should keep both sbi_strcmp() and sbi_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.
Understand. I will keep it and resend the patch.
Thanks
>
> > Thanks
> > Abner
> > >
> > > Otherwise looks good to me.
> > >
> > > Reviewed-by: Anup Patel <anup.patel@wdc.com>
> > >
> > > Regards,
> > > Anup
> >
> >
> > --
> > opensbi mailing list
> > opensbi at lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/opensbi
>
>
>
> --
> Regards,
> Atish
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2020-07-25 9:20 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-23 1:54 [PATCH 0/3] Use standard C string APIs in FDT helper Abner Chang
2020-07-23 1:54 ` [PATCH 1/3] " Abner Chang
2020-07-24 4:37 ` Anup Patel
2020-07-24 5:38 ` Chang, Abner
2020-07-25 5:21 ` Atish Patra
2020-07-25 5:22 ` Atish Patra
2020-07-25 9:20 ` Chang, Abner
2020-07-23 1:54 ` [PATCH 2/3] " Abner Chang
2020-07-24 4:38 ` Anup Patel
2020-07-23 1:54 ` [PATCH 3/3] " Abner Chang
2020-07-24 4:40 ` Anup Patel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox