Commit b0b027ce authored by Sakari Ailus's avatar Sakari Ailus Committed by Rafael J. Wysocki

device property: fwnode_property_read_string_array() returns nr of strings

Functionally fwnode_property_read_string_array() should match
of_property_read_string_array() and work as a drop-in substitute for the
latter. of_property_read_string_array() returns the number of strings read
if the target string pointer array is non-NULL. Make
fwnode_property_read_string_array() do the same.
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 0f194992
...@@ -714,6 +714,8 @@ static int acpi_data_prop_read_single(struct acpi_device_data *data, ...@@ -714,6 +714,8 @@ static int acpi_data_prop_read_single(struct acpi_device_data *data,
return ret; return ret;
*(char **)val = obj->string.pointer; *(char **)val = obj->string.pointer;
return 1;
} else { } else {
ret = -EINVAL; ret = -EINVAL;
} }
...@@ -723,7 +725,15 @@ static int acpi_data_prop_read_single(struct acpi_device_data *data, ...@@ -723,7 +725,15 @@ static int acpi_data_prop_read_single(struct acpi_device_data *data,
int acpi_dev_prop_read_single(struct acpi_device *adev, const char *propname, int acpi_dev_prop_read_single(struct acpi_device *adev, const char *propname,
enum dev_prop_type proptype, void *val) enum dev_prop_type proptype, void *val)
{ {
return adev ? acpi_data_prop_read_single(&adev->data, propname, proptype, val) : -EINVAL; int ret;
if (!adev)
return -EINVAL;
ret = acpi_data_prop_read_single(&adev->data, propname, proptype, val);
if (ret < 0 || proptype != ACPI_TYPE_STRING)
return ret;
return 0;
} }
static int acpi_copy_property_array_u8(const union acpi_object *items, u8 *val, static int acpi_copy_property_array_u8(const union acpi_object *items, u8 *val,
...@@ -799,7 +809,7 @@ static int acpi_copy_property_array_string(const union acpi_object *items, ...@@ -799,7 +809,7 @@ static int acpi_copy_property_array_string(const union acpi_object *items,
val[i] = items[i].string.pointer; val[i] = items[i].string.pointer;
} }
return 0; return nval;
} }
static int acpi_data_prop_read(struct acpi_device_data *data, static int acpi_data_prop_read(struct acpi_device_data *data,
...@@ -813,7 +823,7 @@ static int acpi_data_prop_read(struct acpi_device_data *data, ...@@ -813,7 +823,7 @@ static int acpi_data_prop_read(struct acpi_device_data *data,
if (val && nval == 1) { if (val && nval == 1) {
ret = acpi_data_prop_read_single(data, propname, proptype, val); ret = acpi_data_prop_read_single(data, propname, proptype, val);
if (!ret) if (ret >= 0)
return ret; return ret;
} }
...@@ -824,7 +834,7 @@ static int acpi_data_prop_read(struct acpi_device_data *data, ...@@ -824,7 +834,7 @@ static int acpi_data_prop_read(struct acpi_device_data *data,
if (!val) if (!val)
return obj->package.count; return obj->package.count;
if (nval > obj->package.count) if (proptype != DEV_PROP_STRING && nval > obj->package.count)
return -EOVERFLOW; return -EOVERFLOW;
else if (nval <= 0) else if (nval <= 0)
return -EINVAL; return -EINVAL;
...@@ -845,7 +855,9 @@ static int acpi_data_prop_read(struct acpi_device_data *data, ...@@ -845,7 +855,9 @@ static int acpi_data_prop_read(struct acpi_device_data *data,
ret = acpi_copy_property_array_u64(items, (u64 *)val, nval); ret = acpi_copy_property_array_u64(items, (u64 *)val, nval);
break; break;
case DEV_PROP_STRING: case DEV_PROP_STRING:
ret = acpi_copy_property_array_string(items, (char **)val, nval); ret = acpi_copy_property_array_string(
items, (char **)val,
min_t(u32, nval, obj->package.count));
break; break;
default: default:
ret = -EINVAL; ret = -EINVAL;
......
...@@ -177,7 +177,7 @@ static int pset_prop_read_string_array(struct property_set *pset, ...@@ -177,7 +177,7 @@ static int pset_prop_read_string_array(struct property_set *pset,
memcpy(strings, pointer, length); memcpy(strings, pointer, length);
return 0; return array_len;
} }
static int pset_prop_read_string(struct property_set *pset, static int pset_prop_read_string(struct property_set *pset,
...@@ -364,8 +364,8 @@ EXPORT_SYMBOL_GPL(device_property_read_u64_array); ...@@ -364,8 +364,8 @@ EXPORT_SYMBOL_GPL(device_property_read_u64_array);
* Function reads an array of string properties with @propname from the device * Function reads an array of string properties with @propname from the device
* firmware description and stores them to @val if found. * firmware description and stores them to @val if found.
* *
* Return: number of values if @val was %NULL, * Return: number of values read on success if @val is non-NULL,
* %0 if the property was found (success), * number of values available on success if @val is NULL,
* %-EINVAL if given arguments are not valid, * %-EINVAL if given arguments are not valid,
* %-ENODATA if the property does not have a value, * %-ENODATA if the property does not have a value,
* %-EPROTO or %-EILSEQ if the property is not an array of strings, * %-EPROTO or %-EILSEQ if the property is not an array of strings,
...@@ -605,8 +605,8 @@ static int __fwnode_property_read_string(struct fwnode_handle *fwnode, ...@@ -605,8 +605,8 @@ static int __fwnode_property_read_string(struct fwnode_handle *fwnode,
* Read an string list property @propname from the given firmware node and store * Read an string list property @propname from the given firmware node and store
* them to @val if found. * them to @val if found.
* *
* Return: number of values if @val was %NULL, * Return: number of values read on success if @val is non-NULL,
* %0 if the property was found (success), * number of values available on success if @val is NULL,
* %-EINVAL if given arguments are not valid, * %-EINVAL if given arguments are not valid,
* %-ENODATA if the property does not have a value, * %-ENODATA if the property does not have a value,
* %-EPROTO or %-EILSEQ if the property is not an array of strings, * %-EPROTO or %-EILSEQ if the property is not an array of strings,
...@@ -653,7 +653,7 @@ int fwnode_property_read_string(struct fwnode_handle *fwnode, ...@@ -653,7 +653,7 @@ int fwnode_property_read_string(struct fwnode_handle *fwnode,
!IS_ERR_OR_NULL(fwnode->secondary)) !IS_ERR_OR_NULL(fwnode->secondary))
ret = __fwnode_property_read_string(fwnode->secondary, ret = __fwnode_property_read_string(fwnode->secondary,
propname, val); propname, val);
return ret; return ret < 0 ? ret : 0;
} }
EXPORT_SYMBOL_GPL(fwnode_property_read_string); EXPORT_SYMBOL_GPL(fwnode_property_read_string);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment