Skip to contentSkip to conversation

of: replace strcmp_suffix() with strends()

PATCH Superseded Bartosz Golaszewski 4 participants 5 messages Dec 15, 2025 – Dec 16, 2025 Device tree

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 of: replace strcmp_suffix() with strends()

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

---
 drivers/of/property.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)
drivers/of/property.c +2 -13
index 4e3524227720a..0a68223954f09 100644
@@ -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",
Signature · 1 line
2.51.0
maintainer
#1 lore raw
Quoted 40 lines · Bartosz Golaszewski

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

---
 drivers/of/property.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)
drivers/of/property.c +1 -12
index 4e3524227720a..0a68223954f09 100644
@@ -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,

drivers/of/property.c DEFINE_SUFFIX_PROP(gpio, "-gpio", "#gpio-cells") · line 1408

Quoted 5 lines
drivers/of/property.c +1 -1
@@ -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?

#2 lore raw
Quoted 5 lines · Rob Herring
Quoted 3 lines · Bartosz Golaszewski

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

Quoted 11 lines

drivers/of/property.c DEFINE_SUFFIX_PROP(gpio, "-gpio", "#gpio-cells") · line 1408

Quoted 8 lines

---

drivers/of/property.c +1 -1
@@ -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

maintainer
#3 lore raw
Quoted 19 lines · Bartosz Golaszewski
Quoted 5 lines · Rob Herring
Quoted 3 lines · Bartosz Golaszewski

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

Quoted 11 lines

drivers/of/property.c DEFINE_SUFFIX_PROP(gpio, "-gpio", "#gpio-cells") · line 1408

Quoted 8 lines

---

drivers/of/property.c +1 -1
@@ -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?

Quoted 1 line

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

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

Rob

#4 lore raw
Quoted 21 lines · Rob Herring
Quoted 19 lines · Bartosz Golaszewski
Quoted 16 lines · Rob Herring

drivers/of/property.c DEFINE_SUFFIX_PROP(gpio, "-gpio", "#gpio-cells") · line 1408

Quoted 11 lines · Bartosz Golaszewski

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

---

drivers/of/property.c +1 -1
@@ -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?

Quoted 4 lines
Quoted 1 line

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