devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of: replace strcmp_suffix() with strends()
@ 2025-12-15 15:48 Bartosz Golaszewski
  2025-12-15 19:28 ` Rob Herring
  0 siblings, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2025-12-15 15:48 UTC (permalink / raw)
  To: Rob Herring; +Cc: devicetree, linux-kernel, Bartosz Golaszewski

string.h now provides strends() which fulfills the same role as the
locally implemented strcmp_suffix(). Use it in of/property.c.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
 drivers/of/property.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/drivers/of/property.c b/drivers/of/property.c
index 4e3524227720a..0a68223954f09 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -1294,17 +1294,6 @@ static struct device_node *parse_##fname(struct device_node *np,	  \
 	return parse_prop_cells(np, prop_name, index, name, cells);	  \
 }
 
-static int strcmp_suffix(const char *str, const char *suffix)
-{
-	unsigned int len, suffix_len;
-
-	len = strlen(str);
-	suffix_len = strlen(suffix);
-	if (len <= suffix_len)
-		return -1;
-	return strcmp(str + len - suffix_len, suffix);
-}
-
 /**
  * parse_suffix_prop_cells - Suffix property parsing function for suppliers
  *
@@ -1331,7 +1320,7 @@ static struct device_node *parse_suffix_prop_cells(struct device_node *np,
 {
 	struct of_phandle_args sup_args;
 
-	if (strcmp_suffix(prop_name, suffix))
+	if (strends(prop_name, suffix))
 		return NULL;
 
 	if (of_parse_phandle_with_args(np, prop_name, cells_name, index,
@@ -1416,7 +1405,7 @@ DEFINE_SUFFIX_PROP(gpio, "-gpio", "#gpio-cells")
 static struct device_node *parse_gpios(struct device_node *np,
 				       const char *prop_name, int index)
 {
-	if (!strcmp_suffix(prop_name, ",nr-gpios"))
+	if (!strends(prop_name, ",nr-gpios"))
 		return NULL;
 
 	return parse_suffix_prop_cells(np, prop_name, index, "-gpios",
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] of: replace strcmp_suffix() with strends()
  2025-12-15 15:48 [PATCH] of: replace strcmp_suffix() with strends() Bartosz Golaszewski
@ 2025-12-15 19:28 ` Rob Herring
  2025-12-16  7:45   ` Bartosz Golaszewski
  0 siblings, 1 reply; 5+ messages in thread
From: Rob Herring @ 2025-12-15 19:28 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: devicetree, linux-kernel

On Mon, Dec 15, 2025 at 04:48:09PM +0100, Bartosz Golaszewski wrote:
> string.h now provides strends() which fulfills the same role as the
> locally implemented strcmp_suffix(). Use it in of/property.c.
> 
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
> ---
>  drivers/of/property.c | 15 ++-------------
>  1 file changed, 2 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/of/property.c b/drivers/of/property.c
> index 4e3524227720a..0a68223954f09 100644
> --- a/drivers/of/property.c
> +++ b/drivers/of/property.c
> @@ -1294,17 +1294,6 @@ static struct device_node *parse_##fname(struct device_node *np,	  \
>  	return parse_prop_cells(np, prop_name, index, name, cells);	  \
>  }
>  
> -static int strcmp_suffix(const char *str, const char *suffix)
> -{
> -	unsigned int len, suffix_len;
> -
> -	len = strlen(str);
> -	suffix_len = strlen(suffix);
> -	if (len <= suffix_len)
> -		return -1;
> -	return strcmp(str + len - suffix_len, suffix);
> -}
> -
>  /**
>   * parse_suffix_prop_cells - Suffix property parsing function for suppliers
>   *
> @@ -1331,7 +1320,7 @@ static struct device_node *parse_suffix_prop_cells(struct device_node *np,
>  {
>  	struct of_phandle_args sup_args;
>  
> -	if (strcmp_suffix(prop_name, suffix))
> +	if (strends(prop_name, suffix))
>  		return NULL;
>  
>  	if (of_parse_phandle_with_args(np, prop_name, cells_name, index,
> @@ -1416,7 +1405,7 @@ DEFINE_SUFFIX_PROP(gpio, "-gpio", "#gpio-cells")
>  static struct device_node *parse_gpios(struct device_node *np,
>  				       const char *prop_name, int index)
>  {
> -	if (!strcmp_suffix(prop_name, ",nr-gpios"))
> +	if (!strends(prop_name, ",nr-gpios"))

Don't you need to negate these?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] of: replace strcmp_suffix() with strends()
  2025-12-15 19:28 ` Rob Herring
@ 2025-12-16  7:45   ` Bartosz Golaszewski
  2025-12-16 12:57     ` Rob Herring
  0 siblings, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2025-12-16  7:45 UTC (permalink / raw)
  To: Rob Herring; +Cc: Bartosz Golaszewski, devicetree, linux-kernel

On Mon, Dec 15, 2025 at 8:44 PM Rob Herring <robh@kernel.org> wrote:
>
> On Mon, Dec 15, 2025 at 04:48:09PM +0100, Bartosz Golaszewski wrote:
> > string.h now provides strends() which fulfills the same role as the
> > locally implemented strcmp_suffix(). Use it in of/property.c.
> >
> > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
> > ---
> > @@ -1416,7 +1405,7 @@ DEFINE_SUFFIX_PROP(gpio, "-gpio", "#gpio-cells")
> >  static struct device_node *parse_gpios(struct device_node *np,
> >                                      const char *prop_name, int index)
> >  {
> > -     if (!strcmp_suffix(prop_name, ",nr-gpios"))
> > +     if (!strends(prop_name, ",nr-gpios"))
>
> Don't you need to negate these?
>

I'm not following, am I not negating this?

Bart

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] of: replace strcmp_suffix() with strends()
  2025-12-16  7:45   ` Bartosz Golaszewski
@ 2025-12-16 12:57     ` Rob Herring
  2025-12-16 14:53       ` Bartosz Golaszewski
  0 siblings, 1 reply; 5+ messages in thread
From: Rob Herring @ 2025-12-16 12:57 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: Bartosz Golaszewski, devicetree, linux-kernel

On Tue, Dec 16, 2025 at 1:45 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>
> On Mon, Dec 15, 2025 at 8:44 PM Rob Herring <robh@kernel.org> wrote:
> >
> > On Mon, Dec 15, 2025 at 04:48:09PM +0100, Bartosz Golaszewski wrote:
> > > string.h now provides strends() which fulfills the same role as the
> > > locally implemented strcmp_suffix(). Use it in of/property.c.
> > >
> > > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
> > > ---
> > > @@ -1416,7 +1405,7 @@ DEFINE_SUFFIX_PROP(gpio, "-gpio", "#gpio-cells")
> > >  static struct device_node *parse_gpios(struct device_node *np,
> > >                                      const char *prop_name, int index)
> > >  {
> > > -     if (!strcmp_suffix(prop_name, ",nr-gpios"))
> > > +     if (!strends(prop_name, ",nr-gpios"))
> >
> > Don't you need to negate these?
> >
>
> I'm not following, am I not negating this?

strcmp() returns 0 on match. strends() returns True on match.

Rob

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] of: replace strcmp_suffix() with strends()
  2025-12-16 12:57     ` Rob Herring
@ 2025-12-16 14:53       ` Bartosz Golaszewski
  0 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2025-12-16 14:53 UTC (permalink / raw)
  To: Rob Herring; +Cc: Bartosz Golaszewski, devicetree, linux-kernel

On Tue, Dec 16, 2025 at 1:58 PM Rob Herring <robh@kernel.org> wrote:
>
> On Tue, Dec 16, 2025 at 1:45 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> >
> > On Mon, Dec 15, 2025 at 8:44 PM Rob Herring <robh@kernel.org> wrote:
> > >
> > > On Mon, Dec 15, 2025 at 04:48:09PM +0100, Bartosz Golaszewski wrote:
> > > > string.h now provides strends() which fulfills the same role as the
> > > > locally implemented strcmp_suffix(). Use it in of/property.c.
> > > >
> > > > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
> > > > ---
> > > > @@ -1416,7 +1405,7 @@ DEFINE_SUFFIX_PROP(gpio, "-gpio", "#gpio-cells")
> > > >  static struct device_node *parse_gpios(struct device_node *np,
> > > >                                      const char *prop_name, int index)
> > > >  {
> > > > -     if (!strcmp_suffix(prop_name, ",nr-gpios"))
> > > > +     if (!strends(prop_name, ",nr-gpios"))
> > >
> > > Don't you need to negate these?
> > >
> >
> > I'm not following, am I not negating this?
>
> strcmp() returns 0 on match. strends() returns True on match.
>

Right, I was under the impression strcmp_suffix() had the same
semantics as strends().

Will send v2.

Bart

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-12-16 14:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-15 15:48 [PATCH] of: replace strcmp_suffix() with strends() Bartosz Golaszewski
2025-12-15 19:28 ` Rob Herring
2025-12-16  7:45   ` Bartosz Golaszewski
2025-12-16 12:57     ` Rob Herring
2025-12-16 14:53       ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).