Commit 75dd63c9 authored by Dmitry Torokhov's avatar Dmitry Torokhov Committed by Rafael J. Wysocki

software node: clean up property_copy_string_array()

Because property_copy_string_array() stores the newly allocated pointer in the
destination property, we have an awkward code in property_entry_copy_data()
where we fetch the new pointer from dst.

Let's change property_copy_string_array() to return pointer and rely on the
common path in property_entry_copy_data() to store it in destination structure.
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent b871160f
...@@ -337,8 +337,8 @@ static void property_entry_free_data(const struct property_entry *p) ...@@ -337,8 +337,8 @@ static void property_entry_free_data(const struct property_entry *p)
kfree(p->name); kfree(p->name);
} }
static int property_copy_string_array(struct property_entry *dst, static const char * const *
const struct property_entry *src) property_copy_string_array(const struct property_entry *src)
{ {
const char **d; const char **d;
size_t nval = src->length / sizeof(*d); size_t nval = src->length / sizeof(*d);
...@@ -346,7 +346,7 @@ static int property_copy_string_array(struct property_entry *dst, ...@@ -346,7 +346,7 @@ static int property_copy_string_array(struct property_entry *dst,
d = kcalloc(nval, sizeof(*d), GFP_KERNEL); d = kcalloc(nval, sizeof(*d), GFP_KERNEL);
if (!d) if (!d)
return -ENOMEM; return NULL;
for (i = 0; i < nval; i++) { for (i = 0; i < nval; i++) {
d[i] = kstrdup(src->pointer.str[i], GFP_KERNEL); d[i] = kstrdup(src->pointer.str[i], GFP_KERNEL);
...@@ -354,12 +354,11 @@ static int property_copy_string_array(struct property_entry *dst, ...@@ -354,12 +354,11 @@ static int property_copy_string_array(struct property_entry *dst,
while (--i >= 0) while (--i >= 0)
kfree(d[i]); kfree(d[i]);
kfree(d); kfree(d);
return -ENOMEM; return NULL;
} }
} }
dst->pointer.str = d; return d;
return 0;
} }
static int property_entry_copy_data(struct property_entry *dst, static int property_entry_copy_data(struct property_entry *dst,
...@@ -367,17 +366,15 @@ static int property_entry_copy_data(struct property_entry *dst, ...@@ -367,17 +366,15 @@ static int property_entry_copy_data(struct property_entry *dst,
{ {
const void *pointer = property_get_pointer(src); const void *pointer = property_get_pointer(src);
const void *new; const void *new;
int error;
if (src->is_array) { if (src->is_array) {
if (!src->length) if (!src->length)
return -ENODATA; return -ENODATA;
if (src->type == DEV_PROP_STRING) { if (src->type == DEV_PROP_STRING) {
error = property_copy_string_array(dst, src); new = property_copy_string_array(src);
if (error) if (!new)
return error; return -ENOMEM;
new = dst->pointer.str;
} else { } else {
new = kmemdup(pointer, src->length, GFP_KERNEL); new = kmemdup(pointer, src->length, GFP_KERNEL);
if (!new) if (!new)
......
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