Skip to contentSkip to conversation

device property: check fwnode type in to_of_node()

PATCH In review Andy Shevchenko 3 participants 8 messages Aug 10, 2015 – Aug 25, 2015

Subsystems (4)
lore
Share & tools
lore

Andy Shevchenko

author reviewer
#0 lore raw

PATCH 1/3 device property: check fwnode type in to_of_node()

Potentially one of platform can support both ACPI and OF. In that case when we call to_of_node() for non-OF fwnode types we will get non-NULL result, which is wrong. Check for the type and return a correspondent result.

---
 include/linux/of.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/of.h +2 -1
index edc068d..2194b8c 100644
@@ -136,7 +136,8 @@ static inline bool is_of_node(struct fwnode_handle *fwnode)
 
 static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
 {
-	return fwnode ? container_of(fwnode, struct device_node, fwnode) : NULL;
+	return is_of_node(fwnode) ?
+		container_of(fwnode, struct device_node, fwnode) : NULL;
 }
 
 static inline bool of_have_populated_dt(void)
Signature · 1 line
2.5.0
author reviewer
#1 lore raw

PATCH 2/3 device property: fallback to pset when gettng one string

The one string as an equivalent to an array of one element. Allow user to read one string as a plain string.

---
 drivers/base/property.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/base/property.c +2 -1
index 37a7bb7..841b15c 100644
@@ -462,7 +462,8 @@ int fwnode_property_read_string(struct fwnode_handle *fwnode,
 		return acpi_dev_prop_read(to_acpi_node(fwnode), propname,
 					  DEV_PROP_STRING, val, 1);
 
-	return -ENXIO;
+	return pset_prop_read_array(to_pset(fwnode), propname,
+				    DEV_PROP_STRING, val, 1);
 }
 EXPORT_SYMBOL_GPL(fwnode_property_read_string);
 
Signature · 1 line
2.5.0
author reviewer
#3 lore raw

PATCH 3/3 device property: attach 'else if' to the proper 'if'

In reply to Andy Shevchenko

Obviously in the current place the 'else' keyword is redundant, though it seems quite correct when we check if nval is in allowed range.

Reattach the condition branch there.

---
 drivers/acpi/property.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/acpi/property.c +4 -4
index 7836e2e..a28752c 100644
@@ -528,13 +528,14 @@ int acpi_dev_prop_read(struct acpi_device *adev, const char *propname,
 
 	if (!val)
 		return obj->package.count;
-	else if (nval <= 0)
-		return -EINVAL;
 
 	if (nval > obj->package.count)
 		return -EOVERFLOW;
+	else if (nval <= 0)
+		return -EINVAL;
 
 	items = obj->package.elements;
+
 	switch (proptype) {
 	case DEV_PROP_U8:
 		ret = acpi_copy_property_array_u8(items, (u8 *)val, nval);
@@ -552,8 +553,7 @@ int acpi_dev_prop_read(struct acpi_device *adev, const char *propname,
 		ret = acpi_copy_property_array_string(items, (char **)val, nval);
 		break;
 	default:
-		ret = -EINVAL;
-		break;
+		return -EINVAL;
 	}
 	return ret;
 }
Signature · 1 line
2.5.0
author reviewer
#4 lore raw

Re: [PATCH v1 3/3] device property: attach 'else if' to the proper 'if'

Quoted 5 lines · Andy Shevchenko

Obviously in the current place the 'else' keyword is redundant, though it seems
quite correct when we check if nval is in allowed range.

Reattach the condition branch there.

Rafael, it would be nice to have these fixes in 4.3 as well if you have no objections.

One comment below.

Quoted 15 lines
---
 drivers/acpi/property.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/acpi/property.c +0 -0
index 7836e2e..a28752c 100644
@@ -528,13 +528,14 @@ int acpi_dev_prop_read(struct acpi_device 
 *adev, const char *propname,
 
 	if (!val)
 		return obj->package.count;

drivers/acpi/property.c int acpi_dev_prop_read(struct acpi_device · line 539

Quoted 10 lines
drivers/acpi/property.c +3 -2
-	else if (nval <= 0)
-		return -EINVAL;
 
 	if (nval > obj->package.count)
 		return -EOVERFLOW;
+	else if (nval <= 0)
+		return -EINVAL;
 
 	items = obj->package.elements;
+

This…

drivers/acpi/property.c int acpi_dev_prop_read(struct acpi_device *adev, · line 558

Quoted 13 lines
drivers/acpi/property.c +0 -0
 	switch (proptype) {
 	case DEV_PROP_U8:

ret = acpi_copy_property_array_u8(items, (u8 *)val,
nval);

drivers/acpi/property.c +1 -2
@@ -552,8 +553,7 @@ int acpi_dev_prop_read(struct acpi_device *adev, 
 const char *propname,
 		ret = acpi_copy_property_array_string(items, (char 
 **)val, nval);
 		break;
 	default:
-		ret = -EINVAL;
-		break;
+		return -EINVAL;

…and this seem left overs. If you wish I can resend this patch without them.

Quoted 3 lines
drivers/acpi/property.c +0 -0
 	}

return ret;
}

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
Reviewed-by on v1 3/3
#5 lore raw

Re: [PATCH v1 3/3] device property: attach 'else if' to the proper 'if'

In reply to Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

Obviously in the current place the 'else' keyword is redundant, though it seems quite correct when we check if nval is in allowed range.

Reattach the condition branch there.

When the leftovers you mentioned are dropped you can add my,

#7 lore raw
In reply to Andy Shevchenko
Quoted 5 lines · Andy Shevchenko

Potentially one of platform can support both ACPI and OF. In that case when we call to_of_node() for non-OF fwnode types we will get non-NULL result, which is wrong. Check for the type and return a correspondent result.

Added [1/3] to the 4.3 queue with a minor change in [3/3] (dropped the last hunk) and the Reviewed-by tags from Mika.

Thanks!

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.