drivers: of: check input parameter name for __of_find_property
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.
--- drivers/of/base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/base.c +1 -1
@@ -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
Rob Herring
maintainerQuoted 2 lines · Peng Fan
Check input parameter 'name' for
__of_find_property. If name is NULL,of_prop_cmp->strcasecmpmay 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
Signed-off-by Peng Fan <[email protected]>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@@ -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) {
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->strcasecmpmay 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
Signed-off-by Peng Fan <[email protected]>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@@ -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) {
Rob Herring
maintainerQuoted 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->strcasecmpmay 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_propertymay trigger panic. Anyway propname should be checked before passing toof_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
Signed-off-by Peng Fan <[email protected]>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@@ -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
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->strcasecmpmay 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.cQuoted 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_propertymay trigger panic. Anyway propname should be checked before passing toof_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_propertyto 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
Signed-off-by Peng Fan <[email protected]>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@@ -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) {