Message ID | 20200723015404.17667-2-abner.chang@hpe.com |
---|---|
State | Superseded |
Headers | show |
Series | Use standard C string APIs in FDT helper | expand |
> -----Original Message----- > From: Abner Chang <abner.chang@hpe.com> > Sent: 23 July 2020 07:24 > To: opensbi@lists.infradead.org > Cc: abner.chang@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
> -----Original Message----- > From: Anup Patel [mailto:Anup.Patel@wdc.com] > Sent: Friday, July 24, 2020 12:37 PM > To: Chang, Abner (HPS SW/FW Technologist) <abner.chang@hpe.com>; > opensbi@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@lists.infradead.org > > Cc: abner.chang@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
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@wdc.com] > > Sent: Friday, July 24, 2020 12:37 PM > > To: Chang, Abner (HPS SW/FW Technologist) <abner.chang@hpe.com>; > > opensbi@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@lists.infradead.org > > > Cc: abner.chang@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@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/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@wdc.com] > > > Sent: Friday, July 24, 2020 12:37 PM > > > To: Chang, Abner (HPS SW/FW Technologist) <abner.chang@hpe.com>; > > > opensbi@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@lists.infradead.org > > > > Cc: abner.chang@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@lists.infradead.org > > http://lists.infradead.org/mailman/listinfo/opensbi > > > > -- > Regards, > Atish For the entire series: Reviewed-by: Atish Patra <atish.patra@wdc.com>
> -----Original Message----- > From: Atish Patra [mailto:atishp@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@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@wdc.com] > > > Sent: Friday, July 24, 2020 12:37 PM > > > To: Chang, Abner (HPS SW/FW Technologist) <abner.chang@hpe.com>; > > > opensbi@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@lists.infradead.org > > > > Cc: abner.chang@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@lists.infradead.org > > http://lists.infradead.org/mailman/listinfo/opensbi > > > > -- > Regards, > Atish
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;
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(-)