Skip to content

Commit 75dd63c

Browse files
dtorrafaeljw
authored andcommitted
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: Dmitry Torokhov <dmitry.torokhov@gmail.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent b871160 commit 75dd63c

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

‎drivers/base/swnode.c‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -337,47 +337,44 @@ static void property_entry_free_data(const struct property_entry *p)
337337
kfree(p->name);
338338
}
339339

340-
static int property_copy_string_array(struct property_entry *dst,
341-
const struct property_entry *src)
340+
static const char * const *
341+
property_copy_string_array(const struct property_entry *src)
342342
{
343343
const char **d;
344344
size_t nval = src->length / sizeof(*d);
345345
int i;
346346

347347
d = kcalloc(nval, sizeof(*d), GFP_KERNEL);
348348
if (!d)
349-
return -ENOMEM;
349+
return NULL;
350350

351351
for (i = 0; i < nval; i++) {
352352
d[i] = kstrdup(src->pointer.str[i], GFP_KERNEL);
353353
if (!d[i] && src->pointer.str[i]) {
354354
while (--i >= 0)
355355
kfree(d[i]);
356356
kfree(d);
357-
return -ENOMEM;
357+
return NULL;
358358
}
359359
}
360360

361-
dst->pointer.str = d;
362-
return 0;
361+
return d;
363362
}
364363

365364
static int property_entry_copy_data(struct property_entry *dst,
366365
const struct property_entry *src)
367366
{
368367
const void *pointer = property_get_pointer(src);
369368
const void *new;
370-
int error;
371369

372370
if (src->is_array) {
373371
if (!src->length)
374372
return -ENODATA;
375373

376374
if (src->type == DEV_PROP_STRING) {
377-
error = property_copy_string_array(dst, src);
378-
if (error)
379-
return error;
380-
new = dst->pointer.str;
375+
new = property_copy_string_array(src);
376+
if (!new)
377+
return -ENOMEM;
381378
} else {
382379
new = kmemdup(pointer, src->length, GFP_KERNEL);
383380
if (!new)

0 commit comments

Comments
 (0)