diff --git a/src/barebox-state/state.c b/src/barebox-state/state.c index 28cfb83..37577a4 100644 --- a/src/barebox-state/state.c +++ b/src/barebox-state/state.c @@ -205,15 +205,19 @@ enum state_convert conv) { struct device_node *child; - struct device_node *root; + struct device_node *root, *state_root; int ret; - root = of_new_node(parent, state->root->name); + state_root = of_find_node_by_path(state->of_path); + if (!state_root) + return ERR_PTR(-ENODEV); + + root = of_new_node(parent, state_root->name); ret = of_property_write_u32(root, "magic", state->magic); if (ret) goto out; - for_each_child_of_node(state->root, child) { + for_each_child_of_node(state_root, child) { ret = state_convert_node_variable(state, child, root, "", conv); if (ret) goto out; @@ -237,7 +241,7 @@ if (create) { conv = STATE_CONVERT_FROM_NODE_CREATE; - state->root = node; + state->of_path = xstrdup(node->full_name); state->magic = magic; } else { conv = STATE_CONVERT_FROM_NODE; @@ -294,7 +298,7 @@ int ret; phandle phandle; - node = of_find_node_by_path_from(root, state->root->full_name); + node = of_find_node_by_path_from(root, state->of_path); if (node) { /* replace existing node - it will be deleted later */ parent = node->parent; @@ -302,7 +306,7 @@ char *of_path, *c; /* look for parent, remove last '/' from path */ - of_path = xstrdup(state->root->full_name); + of_path = xstrdup(state->of_path); c = strrchr(of_path, '/'); if (!c) return -ENODEV; @@ -409,6 +413,7 @@ list_del(&state->list); unregister_device(&state->dev); state_backend_free(&state->backend); + free(state->of_path); free(state); } @@ -549,7 +554,7 @@ struct state *state; list_for_each_entry(state, &state_list, list) { - if (state->root == node) + if (!strcmp(state->of_path, node->full_name)) return state; } diff --git a/src/barebox-state/state.h b/src/barebox-state/state.h index 1befcf4..58de643 100644 --- a/src/barebox-state/state.h +++ b/src/barebox-state/state.h @@ -93,7 +93,7 @@ struct list_head list; /* Entry to enqueue on list of states */ struct device_d dev; - struct device_node *root; + char *of_path; const char *name; uint32_t magic;