2 * Functions for working with device tree overlays
4 * Copyright (C) 2012 Pantelis Antoniou <panto@antoniou-consulting.com>
5 * Copyright (C) 2012 Texas Instruments Inc.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
12 #define pr_fmt(fmt) "OF: overlay: " fmt
14 #include <linux/kernel.h>
15 #include <linux/module.h>
17 #include <linux/of_device.h>
18 #include <linux/string.h>
19 #include <linux/ctype.h>
20 #include <linux/errno.h>
21 #include <linux/slab.h>
22 #include <linux/err.h>
23 #include <linux/idr.h>
25 #include "of_private.h"
28 * struct fragment - info about fragment nodes in overlay expanded device tree
29 * @target: target of the overlay operation
30 * @overlay: pointer to the __overlay__ node
33 struct device_node
*target
;
34 struct device_node
*overlay
;
38 * struct overlay_changeset
39 * @ovcs_list: list on which we are located
40 * @overlay_tree: expanded device tree that contains the fragment nodes
41 * @count: count of fragment structures
42 * @fragments: fragment nodes in the overlay expanded device tree
43 * @symbols_fragment: last element of @fragments[] is the __symbols__ node
44 * @cset: changeset to apply fragments to live device tree
46 struct overlay_changeset
{
48 struct list_head ovcs_list
;
49 struct device_node
*overlay_tree
;
51 struct fragment
*fragments
;
52 bool symbols_fragment
;
53 struct of_changeset cset
;
56 /* flags are sticky - once set, do not reset */
57 static int devicetree_state_flags
;
58 #define DTSF_APPLY_FAIL 0x01
59 #define DTSF_REVERT_FAIL 0x02
62 * If a changeset apply or revert encounters an error, an attempt will
63 * be made to undo partial changes, but may fail. If the undo fails
64 * we do not know the state of the devicetree.
66 static int devicetree_corrupt(void)
68 return devicetree_state_flags
&
69 (DTSF_APPLY_FAIL
| DTSF_REVERT_FAIL
);
72 static int build_changeset_next_level(struct overlay_changeset
*ovcs
,
73 struct device_node
*target_node
,
74 const struct device_node
*overlay_node
);
77 * of_resolve_phandles() finds the largest phandle in the live tree.
78 * of_overlay_apply() may add a larger phandle to the live tree.
79 * Do not allow race between two overlays being applied simultaneously:
80 * mutex_lock(&of_overlay_phandle_mutex)
81 * of_resolve_phandles()
83 * mutex_unlock(&of_overlay_phandle_mutex)
85 static DEFINE_MUTEX(of_overlay_phandle_mutex
);
87 void of_overlay_mutex_lock(void)
89 mutex_lock(&of_overlay_phandle_mutex
);
92 void of_overlay_mutex_unlock(void)
94 mutex_unlock(&of_overlay_phandle_mutex
);
98 static LIST_HEAD(ovcs_list
);
99 static DEFINE_IDR(ovcs_idr
);
101 static BLOCKING_NOTIFIER_HEAD(overlay_notify_chain
);
103 int of_overlay_notifier_register(struct notifier_block
*nb
)
105 return blocking_notifier_chain_register(&overlay_notify_chain
, nb
);
107 EXPORT_SYMBOL_GPL(of_overlay_notifier_register
);
109 int of_overlay_notifier_unregister(struct notifier_block
*nb
)
111 return blocking_notifier_chain_unregister(&overlay_notify_chain
, nb
);
113 EXPORT_SYMBOL_GPL(of_overlay_notifier_unregister
);
115 static char *of_overlay_action_name
[] = {
122 static int overlay_notify(struct overlay_changeset
*ovcs
,
123 enum of_overlay_notify_action action
)
125 struct of_overlay_notify_data nd
;
128 for (i
= 0; i
< ovcs
->count
; i
++) {
129 struct fragment
*fragment
= &ovcs
->fragments
[i
];
131 nd
.target
= fragment
->target
;
132 nd
.overlay
= fragment
->overlay
;
134 ret
= blocking_notifier_call_chain(&overlay_notify_chain
,
136 if (ret
== NOTIFY_OK
|| ret
== NOTIFY_STOP
)
139 ret
= notifier_to_errno(ret
);
140 pr_err("overlay changeset %s notifier error %d, target: %pOF\n",
141 of_overlay_action_name
[action
], ret
, nd
.target
);
150 * The values of properties in the "/__symbols__" node are paths in
151 * the ovcs->overlay_tree. When duplicating the properties, the paths
152 * need to be adjusted to be the correct path for the live device tree.
154 * The paths refer to a node in the subtree of a fragment node's "__overlay__"
155 * node, for example "/fragment@0/__overlay__/symbol_path_tail",
156 * where symbol_path_tail can be a single node or it may be a multi-node path.
158 * The duplicated property value will be modified by replacing the
159 * "/fragment_name/__overlay/" portion of the value with the target
160 * path from the fragment node.
162 static struct property
*dup_and_fixup_symbol_prop(
163 struct overlay_changeset
*ovcs
, const struct property
*prop
)
165 struct fragment
*fragment
;
166 struct property
*new_prop
;
167 struct device_node
*fragment_node
;
168 struct device_node
*overlay_node
;
170 const char *path_tail
;
171 const char *target_path
;
173 int overlay_name_len
;
180 if (strnlen(prop
->value
, prop
->length
) >= prop
->length
)
183 path_len
= strlen(path
);
187 fragment_node
= __of_find_node_by_path(ovcs
->overlay_tree
, path
+ 1);
188 overlay_node
= __of_find_node_by_path(fragment_node
, "__overlay__/");
189 of_node_put(fragment_node
);
190 of_node_put(overlay_node
);
192 for (k
= 0; k
< ovcs
->count
; k
++) {
193 fragment
= &ovcs
->fragments
[k
];
194 if (fragment
->overlay
== overlay_node
)
197 if (k
>= ovcs
->count
)
200 overlay_name_len
= snprintf(NULL
, 0, "%pOF", fragment
->overlay
);
202 if (overlay_name_len
> path_len
)
204 path_tail
= path
+ overlay_name_len
;
205 path_tail_len
= strlen(path_tail
);
207 target_path
= kasprintf(GFP_KERNEL
, "%pOF", fragment
->target
);
210 target_path_len
= strlen(target_path
);
212 new_prop
= kzalloc(sizeof(*new_prop
), GFP_KERNEL
);
214 goto err_free_target_path
;
216 new_prop
->name
= kstrdup(prop
->name
, GFP_KERNEL
);
217 new_prop
->length
= target_path_len
+ path_tail_len
+ 1;
218 new_prop
->value
= kzalloc(new_prop
->length
, GFP_KERNEL
);
219 if (!new_prop
->name
|| !new_prop
->value
)
220 goto err_free_new_prop
;
222 strcpy(new_prop
->value
, target_path
);
223 strcpy(new_prop
->value
+ target_path_len
, path_tail
);
225 of_property_set_flag(new_prop
, OF_DYNAMIC
);
230 kfree(new_prop
->name
);
231 kfree(new_prop
->value
);
233 err_free_target_path
:
240 * add_changeset_property() - add @overlay_prop to overlay changeset
241 * @ovcs: overlay changeset
242 * @target_node: where to place @overlay_prop in live tree
243 * @overlay_prop: property to add or update, from overlay tree
244 * @is_symbols_prop: 1 if @overlay_prop is from node "/__symbols__"
246 * If @overlay_prop does not already exist in @target_node, add changeset entry
247 * to add @overlay_prop in @target_node, else add changeset entry to update
248 * value of @overlay_prop.
250 * Some special properties are not updated (no error returned).
252 * Update of property in symbols node is not allowed.
254 * Returns 0 on success, -ENOMEM if memory allocation failure, or -EINVAL if
257 static int add_changeset_property(struct overlay_changeset
*ovcs
,
258 struct device_node
*target_node
,
259 struct property
*overlay_prop
,
260 bool is_symbols_prop
)
262 struct property
*new_prop
= NULL
, *prop
;
265 prop
= of_find_property(target_node
, overlay_prop
->name
, NULL
);
267 if (!of_prop_cmp(overlay_prop
->name
, "name") ||
268 !of_prop_cmp(overlay_prop
->name
, "phandle") ||
269 !of_prop_cmp(overlay_prop
->name
, "linux,phandle"))
272 if (is_symbols_prop
) {
275 new_prop
= dup_and_fixup_symbol_prop(ovcs
, overlay_prop
);
277 new_prop
= __of_prop_dup(overlay_prop
, GFP_KERNEL
);
284 ret
= of_changeset_add_property(&ovcs
->cset
, target_node
,
287 ret
= of_changeset_update_property(&ovcs
->cset
, target_node
,
291 kfree(new_prop
->name
);
292 kfree(new_prop
->value
);
299 * add_changeset_node() - add @node (and children) to overlay changeset
300 * @ovcs: overlay changeset
301 * @target_node: where to place @node in live tree
302 * @node: node from within overlay device tree fragment
304 * If @node does not already exist in @target_node, add changeset entry
305 * to add @node in @target_node.
307 * If @node already exists in @target_node, and the existing node has
308 * a phandle, the overlay node is not allowed to have a phandle.
310 * If @node has child nodes, add the children recursively via
311 * build_changeset_next_level().
313 * NOTE: Multiple mods of created nodes not supported.
314 * If more than one fragment contains a node that does not already exist
315 * in the live tree, then for each fragment of_changeset_attach_node()
316 * will add a changeset entry to add the node. When the changeset is
317 * applied, __of_attach_node() will attach the node twice (once for
318 * each fragment). At this point the device tree will be corrupted.
320 * TODO: add integrity check to ensure that multiple fragments do not
321 * create the same node.
323 * Returns 0 on success, -ENOMEM if memory allocation failure, or -EINVAL if
326 static int add_changeset_node(struct overlay_changeset
*ovcs
,
327 struct device_node
*target_node
, struct device_node
*node
)
329 const char *node_kbasename
;
330 struct device_node
*tchild
;
333 node_kbasename
= kbasename(node
->full_name
);
335 for_each_child_of_node(target_node
, tchild
)
336 if (!of_node_cmp(node_kbasename
, kbasename(tchild
->full_name
)))
340 tchild
= __of_node_dup(node
, "%pOF/%s",
341 target_node
, node_kbasename
);
345 tchild
->parent
= target_node
;
347 ret
= of_changeset_attach_node(&ovcs
->cset
, tchild
);
351 return build_changeset_next_level(ovcs
, tchild
, node
);
354 if (node
->phandle
&& tchild
->phandle
)
357 ret
= build_changeset_next_level(ovcs
, tchild
, node
);
364 * build_changeset_next_level() - add level of overlay changeset
365 * @ovcs: overlay changeset
366 * @target_node: where to place @overlay_node in live tree
367 * @overlay_node: node from within an overlay device tree fragment
369 * Add the properties (if any) and nodes (if any) from @overlay_node to the
370 * @ovcs->cset changeset. If an added node has child nodes, they will
371 * be added recursively.
373 * Do not allow symbols node to have any children.
375 * Returns 0 on success, -ENOMEM if memory allocation failure, or -EINVAL if
376 * invalid @overlay_node.
378 static int build_changeset_next_level(struct overlay_changeset
*ovcs
,
379 struct device_node
*target_node
,
380 const struct device_node
*overlay_node
)
382 struct device_node
*child
;
383 struct property
*prop
;
386 for_each_property_of_node(overlay_node
, prop
) {
387 ret
= add_changeset_property(ovcs
, target_node
, prop
, 0);
389 pr_debug("Failed to apply prop @%pOF/%s, err=%d\n",
390 target_node
, prop
->name
, ret
);
395 for_each_child_of_node(overlay_node
, child
) {
396 ret
= add_changeset_node(ovcs
, target_node
, child
);
398 pr_debug("Failed to apply node @%pOF/%s, err=%d\n",
399 target_node
, child
->name
, ret
);
409 * Add the properties from __overlay__ node to the @ovcs->cset changeset.
411 static int build_changeset_symbols_node(struct overlay_changeset
*ovcs
,
412 struct device_node
*target_node
,
413 const struct device_node
*overlay_symbols_node
)
415 struct property
*prop
;
418 for_each_property_of_node(overlay_symbols_node
, prop
) {
419 ret
= add_changeset_property(ovcs
, target_node
, prop
, 1);
421 pr_debug("Failed to apply prop @%pOF/%s, err=%d\n",
422 target_node
, prop
->name
, ret
);
431 * build_changeset() - populate overlay changeset in @ovcs from @ovcs->fragments
432 * @ovcs: Overlay changeset
434 * Create changeset @ovcs->cset to contain the nodes and properties of the
435 * overlay device tree fragments in @ovcs->fragments[]. If an error occurs,
436 * any portions of the changeset that were successfully created will remain
439 * Returns 0 on success, -ENOMEM if memory allocation failure, or -EINVAL if
440 * invalid overlay in @ovcs->fragments[].
442 static int build_changeset(struct overlay_changeset
*ovcs
)
444 struct fragment
*fragment
;
445 int fragments_count
, i
, ret
;
448 * if there is a symbols fragment in ovcs->fragments[i] it is
449 * the final element in the array
451 if (ovcs
->symbols_fragment
)
452 fragments_count
= ovcs
->count
- 1;
454 fragments_count
= ovcs
->count
;
456 for (i
= 0; i
< fragments_count
; i
++) {
457 fragment
= &ovcs
->fragments
[i
];
459 ret
= build_changeset_next_level(ovcs
, fragment
->target
,
462 pr_debug("apply failed '%pOF'\n", fragment
->target
);
467 if (ovcs
->symbols_fragment
) {
468 fragment
= &ovcs
->fragments
[ovcs
->count
- 1];
469 ret
= build_changeset_symbols_node(ovcs
, fragment
->target
,
472 pr_debug("apply failed '%pOF'\n", fragment
->target
);
481 * Find the target node using a number of different strategies
482 * in order of preference:
484 * 1) "target" property containing the phandle of the target
485 * 2) "target-path" property containing the path of the target
487 static struct device_node
*find_target_node(struct device_node
*info_node
)
493 ret
= of_property_read_u32(info_node
, "target", &val
);
495 return of_find_node_by_phandle(val
);
497 ret
= of_property_read_string(info_node
, "target-path", &path
);
499 return of_find_node_by_path(path
);
501 pr_err("Failed to find target for node %p (%s)\n",
502 info_node
, info_node
->name
);
508 * init_overlay_changeset() - initialize overlay changeset from overlay tree
509 * @ovcs Overlay changeset to build
510 * @tree: Contains all the overlay fragments and overlay fixup nodes
512 * Initialize @ovcs. Populate @ovcs->fragments with node information from
513 * the top level of @tree. The relevant top level nodes are the fragment
514 * nodes and the __symbols__ node. Any other top level node will be ignored.
516 * Returns 0 on success, -ENOMEM if memory allocation failure, -EINVAL if error
517 * detected in @tree, or -ENOSPC if idr_alloc() error.
519 static int init_overlay_changeset(struct overlay_changeset
*ovcs
,
520 struct device_node
*tree
)
522 struct device_node
*node
, *overlay_node
;
523 struct fragment
*fragment
;
524 struct fragment
*fragments
;
528 * Warn for some issues. Can not return -EINVAL for these until
529 * of_unittest_apply_overlay() is fixed to pass these checks.
531 if (!of_node_check_flag(tree
, OF_DYNAMIC
))
532 pr_debug("%s() tree is not dynamic\n", __func__
);
534 if (!of_node_check_flag(tree
, OF_DETACHED
))
535 pr_debug("%s() tree is not detached\n", __func__
);
537 if (!of_node_is_root(tree
))
538 pr_debug("%s() tree is not root\n", __func__
);
540 ovcs
->overlay_tree
= tree
;
542 INIT_LIST_HEAD(&ovcs
->ovcs_list
);
544 of_changeset_init(&ovcs
->cset
);
546 id
= idr_alloc(&ovcs_idr
, ovcs
, 1, 0, GFP_KERNEL
);
553 for_each_child_of_node(tree
, node
) {
554 overlay_node
= of_get_child_by_name(node
, "__overlay__");
557 of_node_put(overlay_node
);
561 node
= of_get_child_by_name(tree
, "__symbols__");
567 fragments
= kcalloc(cnt
, sizeof(*fragments
), GFP_KERNEL
);
574 for_each_child_of_node(tree
, node
) {
575 overlay_node
= of_get_child_by_name(node
, "__overlay__");
579 fragment
= &fragments
[cnt
];
580 fragment
->overlay
= overlay_node
;
581 fragment
->target
= find_target_node(node
);
582 if (!fragment
->target
) {
583 of_node_put(fragment
->overlay
);
585 goto err_free_fragments
;
592 * if there is a symbols fragment in ovcs->fragments[i] it is
593 * the final element in the array
595 node
= of_get_child_by_name(tree
, "__symbols__");
597 ovcs
->symbols_fragment
= 1;
598 fragment
= &fragments
[cnt
];
599 fragment
->overlay
= node
;
600 fragment
->target
= of_find_node_by_path("/__symbols__");
602 if (!fragment
->target
) {
603 pr_err("symbols in overlay, but not in live tree\n");
605 goto err_free_fragments
;
613 goto err_free_fragments
;
618 ovcs
->fragments
= fragments
;
625 idr_remove(&ovcs_idr
, id
);
627 pr_err("%s() failed, ret = %d\n", __func__
, ret
);
632 static void free_overlay_changeset(struct overlay_changeset
*ovcs
)
636 if (ovcs
->cset
.entries
.next
)
637 of_changeset_destroy(&ovcs
->cset
);
640 idr_remove(&ovcs_idr
, ovcs
->id
);
642 for (i
= 0; i
< ovcs
->count
; i
++) {
643 of_node_put(ovcs
->fragments
[i
].target
);
644 of_node_put(ovcs
->fragments
[i
].overlay
);
646 kfree(ovcs
->fragments
);
652 * of_overlay_apply() - Create and apply an overlay changeset
653 * @tree: Expanded overlay device tree
654 * @ovcs_id: Pointer to overlay changeset id
656 * Creates and applies an overlay changeset.
658 * If an error occurs in a pre-apply notifier, then no changes are made
659 * to the device tree.
662 * A non-zero return value will not have created the changeset if error is from:
664 * - building the changeset
665 * - overlay changeset pre-apply notifier
667 * If an error is returned by an overlay changeset pre-apply notifier
668 * then no further overlay changeset pre-apply notifier will be called.
670 * A non-zero return value will have created the changeset if error is from:
671 * - overlay changeset entry notifier
672 * - overlay changeset post-apply notifier
674 * If an error is returned by an overlay changeset post-apply notifier
675 * then no further overlay changeset post-apply notifier will be called.
677 * If more than one notifier returns an error, then the last notifier
678 * error to occur is returned.
680 * If an error occurred while applying the overlay changeset, then an
681 * attempt is made to revert any changes that were made to the
682 * device tree. If there were any errors during the revert attempt
683 * then the state of the device tree can not be determined, and any
684 * following attempt to apply or remove an overlay changeset will be
687 * Returns 0 on success, or a negative error number. Overlay changeset
688 * id is returned to *ovcs_id.
691 int of_overlay_apply(struct device_node
*tree
, int *ovcs_id
)
693 struct overlay_changeset
*ovcs
;
694 int ret
= 0, ret_revert
, ret_tmp
;
698 if (devicetree_corrupt()) {
699 pr_err("devicetree state suspect, refuse to apply overlay\n");
704 ovcs
= kzalloc(sizeof(*ovcs
), GFP_KERNEL
);
710 of_overlay_mutex_lock();
711 mutex_lock(&of_mutex
);
713 ret
= of_resolve_phandles(tree
);
715 goto err_free_overlay_changeset
;
717 ret
= init_overlay_changeset(ovcs
, tree
);
719 goto err_free_overlay_changeset
;
721 ret
= overlay_notify(ovcs
, OF_OVERLAY_PRE_APPLY
);
723 pr_err("overlay changeset pre-apply notify error %d\n", ret
);
724 goto err_free_overlay_changeset
;
727 ret
= build_changeset(ovcs
);
729 goto err_free_overlay_changeset
;
732 ret
= __of_changeset_apply_entries(&ovcs
->cset
, &ret_revert
);
735 pr_debug("overlay changeset revert error %d\n",
737 devicetree_state_flags
|= DTSF_APPLY_FAIL
;
739 goto err_free_overlay_changeset
;
742 ret
= __of_changeset_apply_notify(&ovcs
->cset
);
744 pr_err("overlay changeset entry notify error %d\n", ret
);
745 /* notify failure is not fatal, continue */
747 list_add_tail(&ovcs
->ovcs_list
, &ovcs_list
);
750 ret_tmp
= overlay_notify(ovcs
, OF_OVERLAY_POST_APPLY
);
752 pr_err("overlay changeset post-apply notify error %d\n",
760 err_free_overlay_changeset
:
761 free_overlay_changeset(ovcs
);
764 mutex_unlock(&of_mutex
);
765 of_overlay_mutex_unlock();
768 pr_debug("%s() err=%d\n", __func__
, ret
);
772 EXPORT_SYMBOL_GPL(of_overlay_apply
);
777 * Returns 1 if @np is @tree or is contained in @tree, else 0
779 static int find_node(struct device_node
*tree
, struct device_node
*np
)
781 struct device_node
*child
;
786 for_each_child_of_node(tree
, child
) {
787 if (find_node(child
, np
)) {
797 * Is @remove_ce_node a child of, a parent of, or the same as any
798 * node in an overlay changeset more topmost than @remove_ovcs?
800 * Returns 1 if found, else 0
802 static int node_overlaps_later_cs(struct overlay_changeset
*remove_ovcs
,
803 struct device_node
*remove_ce_node
)
805 struct overlay_changeset
*ovcs
;
806 struct of_changeset_entry
*ce
;
808 list_for_each_entry_reverse(ovcs
, &ovcs_list
, ovcs_list
) {
809 if (ovcs
== remove_ovcs
)
812 list_for_each_entry(ce
, &ovcs
->cset
.entries
, node
) {
813 if (find_node(ce
->np
, remove_ce_node
)) {
814 pr_err("%s: #%d overlaps with #%d @%pOF\n",
815 __func__
, remove_ovcs
->id
, ovcs
->id
,
819 if (find_node(remove_ce_node
, ce
->np
)) {
820 pr_err("%s: #%d overlaps with #%d @%pOF\n",
821 __func__
, remove_ovcs
->id
, ovcs
->id
,
832 * We can safely remove the overlay only if it's the top-most one.
833 * Newly applied overlays are inserted at the tail of the overlay list,
834 * so a top most overlay is the one that is closest to the tail.
836 * The topmost check is done by exploiting this property. For each
837 * affected device node in the log list we check if this overlay is
838 * the one closest to the tail. If another overlay has affected this
839 * device node and is closest to the tail, then removal is not permited.
841 static int overlay_removal_is_ok(struct overlay_changeset
*remove_ovcs
)
843 struct of_changeset_entry
*remove_ce
;
845 list_for_each_entry(remove_ce
, &remove_ovcs
->cset
.entries
, node
) {
846 if (node_overlaps_later_cs(remove_ovcs
, remove_ce
->np
)) {
847 pr_err("overlay #%d is not topmost\n", remove_ovcs
->id
);
856 * of_overlay_remove() - Revert and free an overlay changeset
857 * @ovcs_id: Pointer to overlay changeset id
859 * Removes an overlay if it is permissible. @ovcs_id was previously returned
860 * by of_overlay_apply().
862 * If an error occurred while attempting to revert the overlay changeset,
863 * then an attempt is made to re-apply any changeset entry that was
864 * reverted. If an error occurs on re-apply then the state of the device
865 * tree can not be determined, and any following attempt to apply or remove
866 * an overlay changeset will be refused.
868 * A non-zero return value will not revert the changeset if error is from:
870 * - overlay changeset pre-remove notifier
871 * - overlay changeset entry revert
873 * If an error is returned by an overlay changeset pre-remove notifier
874 * then no further overlay changeset pre-remove notifier will be called.
876 * If more than one notifier returns an error, then the last notifier
877 * error to occur is returned.
879 * A non-zero return value will revert the changeset if error is from:
880 * - overlay changeset entry notifier
881 * - overlay changeset post-remove notifier
883 * If an error is returned by an overlay changeset post-remove notifier
884 * then no further overlay changeset post-remove notifier will be called.
886 * Returns 0 on success, or a negative error number. *ovcs_id is set to
887 * zero after reverting the changeset, even if a subsequent error occurs.
889 int of_overlay_remove(int *ovcs_id
)
891 struct overlay_changeset
*ovcs
;
892 int ret
, ret_apply
, ret_tmp
;
896 if (devicetree_corrupt()) {
897 pr_err("suspect devicetree state, refuse to remove overlay\n");
902 mutex_lock(&of_mutex
);
904 ovcs
= idr_find(&ovcs_idr
, *ovcs_id
);
907 pr_err("remove: Could not find overlay #%d\n", *ovcs_id
);
911 if (!overlay_removal_is_ok(ovcs
)) {
916 ret
= overlay_notify(ovcs
, OF_OVERLAY_PRE_REMOVE
);
918 pr_err("overlay changeset pre-remove notify error %d\n", ret
);
922 list_del(&ovcs
->ovcs_list
);
925 ret
= __of_changeset_revert_entries(&ovcs
->cset
, &ret_apply
);
928 devicetree_state_flags
|= DTSF_REVERT_FAIL
;
932 ret
= __of_changeset_revert_notify(&ovcs
->cset
);
934 pr_err("overlay changeset entry notify error %d\n", ret
);
935 /* notify failure is not fatal, continue */
939 ret_tmp
= overlay_notify(ovcs
, OF_OVERLAY_POST_REMOVE
);
941 pr_err("overlay changeset post-remove notify error %d\n",
947 free_overlay_changeset(ovcs
);
950 mutex_unlock(&of_mutex
);
953 pr_debug("%s() err=%d\n", __func__
, ret
);
957 EXPORT_SYMBOL_GPL(of_overlay_remove
);
960 * of_overlay_remove_all() - Reverts and frees all overlay changesets
962 * Removes all overlays from the system in the correct order.
964 * Returns 0 on success, or a negative error number
966 int of_overlay_remove_all(void)
968 struct overlay_changeset
*ovcs
, *ovcs_n
;
971 /* the tail of list is guaranteed to be safe to remove */
972 list_for_each_entry_safe_reverse(ovcs
, ovcs_n
, &ovcs_list
, ovcs_list
) {
973 ret
= of_overlay_remove(&ovcs
->id
);
980 EXPORT_SYMBOL_GPL(of_overlay_remove_all
);