@@ -362,10 +362,49 @@ void of_node_release(struct kobject *kobj)
fwnode_links_purge(of_fwnode_handle(node));
kfree(node->full_name);
+ if (node->full_name != (const char *)(node + 1))
+ kfree(node->full_name);
+
kfree(node->data);
kfree(node);
}
+/**
+ * of_node_alloc - Allocate a node dynamically.
+ * @name: Node name
+ *
+ * Create a node by dynamically allocating the memory of both the
+ * node structure and the node name & contents. The node's
+ * flags have the OF_DYNAMIC & OF_DETACHED bit set so that we can
+ * differentiate between dynamically allocated nodes and not.
+ *
+ * Return: The newly allocated node or NULL on out of memory error.
+ */
+struct device_node *of_node_alloc(const char *name)
+{
+ struct device_node *node;
+ int name_len = 0;
+
+ if (name)
+ name_len = strlen(name) + 1;
+
+ node = kzalloc(sizeof(*node) + name_len, GFP_KERNEL);
+ if (!node)
+ return NULL;
+
+ if (name) {
+ node->full_name = (const char *)(node + 1);
+ strcpy((char *)node->full_name, name);
+ }
+
+ of_node_set_flag(node, OF_DYNAMIC);
+ of_node_set_flag(node, OF_DETACHED);
+ of_node_init(node);
+
+ return node;
+}
+EXPORT_SYMBOL(of_node_alloc);
+
/**
* __of_prop_dup - Copy a property dynamically.
* @prop: Property to copy
@@ -426,18 +465,9 @@ struct device_node *__of_node_dup(const struct device_node *np,
{
struct device_node *node;
- node = kzalloc(sizeof(*node), GFP_KERNEL);
+ node = of_node_alloc(full_name);
if (!node)
return NULL;
- node->full_name = kstrdup(full_name, GFP_KERNEL);
- if (!node->full_name) {
- kfree(node);
- return NULL;
- }
-
- of_node_set_flag(node, OF_DYNAMIC);
- of_node_set_flag(node, OF_DETACHED);
- of_node_init(node);
/* Iterate over and duplicate all properties */
if (np) {
@@ -1462,6 +1462,8 @@ enum of_reconfig_change {
};
#ifdef CONFIG_OF_DYNAMIC
+struct device_node *of_node_alloc(const char *name);
+
extern int of_reconfig_notifier_register(struct notifier_block *);
extern int of_reconfig_notifier_unregister(struct notifier_block *);
extern int of_reconfig_notify(unsigned long, struct of_reconfig_data *rd);
@@ -1506,6 +1508,11 @@ static inline int of_changeset_update_property(struct of_changeset *ocs,
return of_changeset_action(ocs, OF_RECONFIG_UPDATE_PROPERTY, np, prop);
}
#else /* CONFIG_OF_DYNAMIC */
+static inline struct device_node *of_node_alloc(const char *name)
+{
+ return NULL;
+}
+
static inline int of_reconfig_notifier_register(struct notifier_block *nb)
{
return -EINVAL;