Skip to contentSkip to conversation

drivers: of: check input parameter name for __of_find_property

PATCH In review Peng Fan 2 participants 5 messages Sep 11, 2015 – Sep 16, 2015 Device tree

lore
Share & tools
lore

Peng Fan

author
#0 lore raw

PATCH 1/1 drivers: of: check input parameter name for __of_find_property

Check input parameter 'name' for __of_find_property. If name is NULL, of_prop_cmp->strcasecmp may trigger panic.

Cc Rob Herring <[email protected]>
Cc Frank Rowand <[email protected]>
Cc Grant Likely <[email protected]>
---
 drivers/of/base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/base.c +1 -1
index 8b5a187..e41436d 100644
@@ -215,7 +215,7 @@ static struct property *__of_find_property(const struct device_node *np,
 {
 	struct property *pp;
 
-	if (!np)
+	if (!np || !name)
 		return NULL;
 
 	for (pp = np->properties; pp; pp = pp->next) {
Signature · 1 line
1.8.4
maintainer
#1 lore raw
Quoted 2 lines · Peng Fan

Check input parameter 'name' for __of_find_property. If name is NULL, of_prop_cmp->strcasecmp may trigger panic.

Arguably that could be a feature. Do you have a usecase where name being NULL is valid and panicking is a problem?

Rob

Quoted 23 lines
Cc Rob Herring <[email protected]>
Cc Frank Rowand <[email protected]>
Cc Grant Likely <[email protected]>
---
 drivers/of/base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/base.c +1 -1
index 8b5a187..e41436d 100644
@@ -215,7 +215,7 @@ static struct property *__of_find_property(const struct device_node *np,
 {
 	struct property *pp;
 
-	if (!np)
+	if (!np || !name)
 		return NULL;
 
 	for (pp = np->properties; pp; pp = pp->next) {
author
#2 lore raw

Hi Rob,

Quoted 6 lines · Rob Herring
Quoted 2 lines · Peng Fan

Check input parameter 'name' for __of_find_property. If name is NULL, of_prop_cmp->strcasecmp may trigger panic.

Arguably that could be a feature. Do you have a usecase where name being NULL is valid and panicking is a problem?

In drivers/pinctrl/devicetree.c

195                 propname = kasprintf(GFP_KERNEL, "pinctrl-%d", state);
196                 prop = of_find_property(np, propname, &size);
197                 kfree(propname);
198                 if (!prop)

199 break;

If propname is NULL, of_find_property may trigger panic. Anyway propname should be checked before passing to of_find_property.

I did not met panic message. I wrote this patch when I was reading the piece code. I think the name parameter should be checked before doing string compare.

Regards,
Peng.

Quoted 27 lines

Rob

Quoted 23 lines
Cc Rob Herring <[email protected]>
Cc Frank Rowand <[email protected]>
Cc Grant Likely <[email protected]>
---
 drivers/of/base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/base.c +1 -1
index 8b5a187..e41436d 100644
@@ -215,7 +215,7 @@ static struct property *__of_find_property(const struct device_node *np,
 {
 	struct property *pp;
 
-	if (!np)
+	if (!np || !name)
 		return NULL;
 
 	for (pp = np->properties; pp; pp = pp->next) {
maintainer
#3 lore raw
Quoted 12 lines · Peng Fan

Hi Rob,

Quoted 6 lines · Rob Herring
Quoted 2 lines · Peng Fan

Check input parameter 'name' for __of_find_property. If name is NULL, of_prop_cmp->strcasecmp may trigger panic.

Arguably that could be a feature. Do you have a usecase where name being NULL is valid and panicking is a problem?

In drivers/pinctrl/devicetree.c

Quoted 8 lines
195                 propname = kasprintf(GFP_KERNEL, "pinctrl-%d", state);
196                 prop = of_find_property(np, propname, &size);
197                 kfree(propname);
198                 if (!prop)

199 break;

If propname is NULL, of_find_property may trigger panic. Anyway propname should be checked before passing to of_find_property.

propname will only be NULL if the memory allocation failed which gives you a big warning message. I don't think you would want to continue on in this case.

So I'm inclined to leave this as is with passing NULL to of_find_property to always be an error and fatal.

Rob

Quoted 33 lines

I did not met panic message. I wrote this patch when I was reading the piece code. I think the name parameter should be checked before doing string compare.

Regards,
Peng.

Quoted 27 lines

Rob

Quoted 23 lines
Cc Rob Herring <[email protected]>
Cc Frank Rowand <[email protected]>
Cc Grant Likely <[email protected]>
---
 drivers/of/base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/base.c +1 -1
index 8b5a187..e41436d 100644
@@ -215,7 +215,7 @@ static struct property *__of_find_property(const struct device_node *np,
 {
 	struct property *pp;
 
-	if (!np)
+	if (!np || !name)
 		return NULL;
 
 	for (pp = np->properties; pp; pp = pp->next) {

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#4 lore raw
Quoted 22 lines · Rob Herring
Quoted 12 lines · Peng Fan

Hi Rob,

Quoted 6 lines · Rob Herring
Quoted 2 lines · Peng Fan

Check input parameter 'name' for __of_find_property. If name is NULL, of_prop_cmp->strcasecmp may trigger panic.

Arguably that could be a feature. Do you have a usecase where name being NULL is valid and panicking is a problem?

In drivers/pinctrl/devicetree.c

Quoted 8 lines
195                 propname = kasprintf(GFP_KERNEL, "pinctrl-%d", state);
196                 prop = of_find_property(np, propname, &size);
197                 kfree(propname);
198                 if (!prop)

199 break;

If propname is NULL, of_find_property may trigger panic. Anyway propname should be checked before passing to of_find_property.

Quoted 6 lines

propname will only be NULL if the memory allocation failed which gives you a big warning message. I don't think you would want to continue on in this case.

So I'm inclined to leave this as is with passing NULL to of_find_property to always be an error and fatal.

of_find_property has EXPORT_SYMBOL, it maybe called in different places. And it should handle the case that name is NULL, right? If passing NULL to of_find_property is an error, then why check parameter 'np' like "if (!np)" in of_find_property?

Regards,
Peng.

Quoted 37 lines

Rob

Quoted 33 lines

I did not met panic message. I wrote this patch when I was reading the piece code. I think the name parameter should be checked before doing string compare.

Regards,
Peng.

Quoted 27 lines

Rob

Quoted 23 lines
Cc Rob Herring <[email protected]>
Cc Frank Rowand <[email protected]>
Cc Grant Likely <[email protected]>
---
 drivers/of/base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/base.c +1 -1
index 8b5a187..e41436d 100644
@@ -215,7 +215,7 @@ static struct property *__of_find_property(const struct device_node *np,
 {
 	struct property *pp;
 
-	if (!np)
+	if (!np || !name)
 		return NULL;
 
 	for (pp = np->properties; pp; pp = pp->next) {