提交 0f194992 编写于 作者: S Sakari Ailus 提交者: Rafael J. Wysocki

device property: Fix reading pset strings using array access functions

The length field value of non-array string properties is the length of the
string itself. Non-array string properties thus require specific handling.
Fix this.
Signed-off-by: NSakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: NMika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
上级 026b8217
...@@ -147,14 +147,36 @@ static int pset_prop_read_string_array(struct property_set *pset, ...@@ -147,14 +147,36 @@ static int pset_prop_read_string_array(struct property_set *pset,
const char *propname, const char *propname,
const char **strings, size_t nval) const char **strings, size_t nval)
{ {
const struct property_entry *prop;
const void *pointer; const void *pointer;
size_t length = nval * sizeof(*strings); size_t array_len, length;
/* Find out the array length. */
prop = pset_prop_get(pset, propname);
if (!prop)
return -EINVAL;
if (!prop->is_array)
/* The array length for a non-array string property is 1. */
array_len = 1;
else
/* Find the length of an array. */
array_len = pset_prop_count_elems_of_size(pset, propname,
sizeof(const char *));
/* Return how many there are if strings is NULL. */
if (!strings)
return array_len;
array_len = min(nval, array_len);
length = array_len * sizeof(*strings);
pointer = pset_prop_find(pset, propname, length); pointer = pset_prop_find(pset, propname, length);
if (IS_ERR(pointer)) if (IS_ERR(pointer))
return PTR_ERR(pointer); return PTR_ERR(pointer);
memcpy(strings, pointer, length); memcpy(strings, pointer, length);
return 0; return 0;
} }
...@@ -555,12 +577,8 @@ static int __fwnode_property_read_string_array(struct fwnode_handle *fwnode, ...@@ -555,12 +577,8 @@ static int __fwnode_property_read_string_array(struct fwnode_handle *fwnode,
return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING, return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING,
val, nval); val, nval);
else if (is_pset_node(fwnode)) else if (is_pset_node(fwnode))
return val ? return pset_prop_read_string_array(to_pset_node(fwnode),
pset_prop_read_string_array(to_pset_node(fwnode), propname, val, nval);
propname, val, nval) :
pset_prop_count_elems_of_size(to_pset_node(fwnode),
propname,
sizeof(const char *));
return -ENXIO; return -ENXIO;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册