Commit 06ad93c3 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Greg Kroah-Hartman

software node: Introduce software_node_alloc()/software_node_free()

Introduce software_node_alloc() and software_node_free() helpers.
This will help with code readability and maintenance.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20210329151207.36619-2-andriy.shevchenko@linux.intel.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 3f6b6536
...@@ -720,19 +720,30 @@ software_node_find_by_name(const struct software_node *parent, const char *name) ...@@ -720,19 +720,30 @@ software_node_find_by_name(const struct software_node *parent, const char *name)
} }
EXPORT_SYMBOL_GPL(software_node_find_by_name); EXPORT_SYMBOL_GPL(software_node_find_by_name);
static int static struct software_node *software_node_alloc(const struct property_entry *properties)
software_node_register_properties(struct software_node *node,
const struct property_entry *properties)
{ {
struct property_entry *props; struct property_entry *props;
struct software_node *node;
props = property_entries_dup(properties); props = property_entries_dup(properties);
if (IS_ERR(props)) if (IS_ERR(props))
return PTR_ERR(props); return ERR_CAST(props);
node = kzalloc(sizeof(*node), GFP_KERNEL);
if (!node) {
property_entries_free(props);
return ERR_PTR(-ENOMEM);
}
node->properties = props; node->properties = props;
return 0; return node;
}
static void software_node_free(const struct software_node *node)
{
property_entries_free(node->properties);
kfree(node);
} }
static void software_node_release(struct kobject *kobj) static void software_node_release(struct kobject *kobj)
...@@ -746,10 +757,9 @@ static void software_node_release(struct kobject *kobj) ...@@ -746,10 +757,9 @@ static void software_node_release(struct kobject *kobj)
ida_simple_remove(&swnode_root_ids, swnode->id); ida_simple_remove(&swnode_root_ids, swnode->id);
} }
if (swnode->allocated) { if (swnode->allocated)
property_entries_free(swnode->node->properties); software_node_free(swnode->node);
kfree(swnode->node);
}
ida_destroy(&swnode->child_ids); ida_destroy(&swnode->child_ids);
kfree(swnode); kfree(swnode);
} }
...@@ -972,7 +982,6 @@ fwnode_create_software_node(const struct property_entry *properties, ...@@ -972,7 +982,6 @@ fwnode_create_software_node(const struct property_entry *properties,
struct fwnode_handle *fwnode; struct fwnode_handle *fwnode;
struct software_node *node; struct software_node *node;
struct swnode *p = NULL; struct swnode *p = NULL;
int ret;
if (parent) { if (parent) {
if (IS_ERR(parent)) if (IS_ERR(parent))
...@@ -982,23 +991,15 @@ fwnode_create_software_node(const struct property_entry *properties, ...@@ -982,23 +991,15 @@ fwnode_create_software_node(const struct property_entry *properties,
p = to_swnode(parent); p = to_swnode(parent);
} }
node = kzalloc(sizeof(*node), GFP_KERNEL); node = software_node_alloc(properties);
if (!node) if (IS_ERR(node))
return ERR_PTR(-ENOMEM); return ERR_CAST(node);
ret = software_node_register_properties(node, properties);
if (ret) {
kfree(node);
return ERR_PTR(ret);
}
node->parent = p ? p->node : NULL; node->parent = p ? p->node : NULL;
fwnode = swnode_register(node, p, 1); fwnode = swnode_register(node, p, 1);
if (IS_ERR(fwnode)) { if (IS_ERR(fwnode))
property_entries_free(node->properties); software_node_free(node);
kfree(node);
}
return fwnode; return fwnode;
} }
......
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