software node: simplify property_entry_read_string_array()
There is no need to treat string arrays and single strings separately, we can go exclusively by the element length in relation to data type size. Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
parent
daeba9bf62
commit
1afc14032e
@ -173,28 +173,21 @@ static int property_entry_read_string_array(const struct property_entry *props,
|
|||||||
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 array_len, length;
|
size_t length;
|
||||||
|
int array_len;
|
||||||
|
|
||||||
/* Find out the array length. */
|
/* Find out the array length. */
|
||||||
prop = property_entry_get(props, propname);
|
array_len = property_entry_count_elems_of_size(props, propname,
|
||||||
if (!prop)
|
sizeof(const char *));
|
||||||
return -EINVAL;
|
if (array_len < 0)
|
||||||
|
return array_len;
|
||||||
if (prop->is_array)
|
|
||||||
/* Find the length of an array. */
|
|
||||||
array_len = property_entry_count_elems_of_size(props, propname,
|
|
||||||
sizeof(const char *));
|
|
||||||
else
|
|
||||||
/* The array length for a non-array string property is 1. */
|
|
||||||
array_len = 1;
|
|
||||||
|
|
||||||
/* Return how many there are if strings is NULL. */
|
/* Return how many there are if strings is NULL. */
|
||||||
if (!strings)
|
if (!strings)
|
||||||
return array_len;
|
return array_len;
|
||||||
|
|
||||||
array_len = min(nval, array_len);
|
array_len = min_t(size_t, nval, array_len);
|
||||||
length = array_len * sizeof(*strings);
|
length = array_len * sizeof(*strings);
|
||||||
|
|
||||||
pointer = property_entry_find(props, propname, length);
|
pointer = property_entry_find(props, propname, length);
|
||||||
|
Loading…
Reference in New Issue
Block a user