summaryrefslogtreecommitdiffstats
path: root/Documentation/devicetree/overlay-notes.rst
diff options
context:
space:
mode:
authorFrank Rowand <frank.rowand@sony.com>2022-04-20 17:25:05 -0500
committerRob Herring <robh@kernel.org>2022-04-25 10:56:11 -0500
commit067c098766c6af667a9002d4e33cf1f3c998abbe (patch)
treed86a99533cbc90d9542846d54fc73cf0f7d09e14 /Documentation/devicetree/overlay-notes.rst
parent1e4089667c7c732dd1b92c4c6bc7bd240ca30213 (diff)
downloadlinux-067c098766c6af667a9002d4e33cf1f3c998abbe.tar.gz
linux-067c098766c6af667a9002d4e33cf1f3c998abbe.tar.bz2
linux-067c098766c6af667a9002d4e33cf1f3c998abbe.zip
of: overlay: rework overlay apply and remove kfree()s
Fix various kfree() issues related to of_overlay_apply(). - Double kfree() of fdt and tree when init_overlay_changeset() returns an error. - free_overlay_changeset() free the root of the unflattened overlay (variable tree) instead of the memory that contains the unflattened overlay. - For the case of a failure during applying an overlay, move kfree() of new_fdt and overlay_mem into free_overlay_changeset(), which is called by the function that allocated them. - For the case of removing an overlay, the kfree() of new_fdt and overlay_mem remains in free_overlay_changeset(). - Check return value of of_fdt_unflatten_tree() for error instead of checking the returned value of overlay_root. - When storing pointers to allocated objects in ovcs, do so as near to the allocation as possible instead of in deeply layered function. More clearly document policy related to lifetime of pointers into overlay memory. Double kfree() Reported-by: Slawomir Stepien <slawomir.stepien@nokia.com> Signed-off-by: Frank Rowand <frank.rowand@sony.com> Signed-off-by: Rob Herring <robh@kernel.org> Link: https://lore.kernel.org/r/20220420222505.928492-3-frowand.list@gmail.com
Diffstat (limited to 'Documentation/devicetree/overlay-notes.rst')
-rw-r--r--Documentation/devicetree/overlay-notes.rst30
1 files changed, 26 insertions, 4 deletions
diff --git a/Documentation/devicetree/overlay-notes.rst b/Documentation/devicetree/overlay-notes.rst
index b2b8db765b8c..e139f22b363e 100644
--- a/Documentation/devicetree/overlay-notes.rst
+++ b/Documentation/devicetree/overlay-notes.rst
@@ -119,10 +119,32 @@ Finally, if you need to remove all overlays in one-go, just call
of_overlay_remove_all() which will remove every single one in the correct
order.
-In addition, there is the option to register notifiers that get called on
+There is the option to register notifiers that get called on
overlay operations. See of_overlay_notifier_register/unregister and
enum of_overlay_notify_action for details.
-Note that a notifier callback is not supposed to store pointers to a device
-tree node or its content beyond OF_OVERLAY_POST_REMOVE corresponding to the
-respective node it received.
+A notifier callback for OF_OVERLAY_PRE_APPLY, OF_OVERLAY_POST_APPLY, or
+OF_OVERLAY_PRE_REMOVE may store pointers to a device tree node in the overlay
+or its content but these pointers must not persist past the notifier callback
+for OF_OVERLAY_POST_REMOVE. The memory containing the overlay will be
+kfree()ed after OF_OVERLAY_POST_REMOVE notifiers are called. Note that the
+memory will be kfree()ed even if the notifier for OF_OVERLAY_POST_REMOVE
+returns an error.
+
+The changeset notifiers in drivers/of/dynamic.c are a second type of notifier
+that could be triggered by applying or removing an overlay. These notifiers
+are not allowed to store pointers to a device tree node in the overlay
+or its content. The overlay code does not protect against such pointers
+remaining active when the memory containing the overlay is freed as a result
+of removing the overlay.
+
+Any other code that retains a pointer to the overlay nodes or data is
+considered to be a bug because after removing the overlay the pointer
+will refer to freed memory.
+
+Users of overlays must be especially aware of the overall operations that
+occur on the system to ensure that other kernel code does not retain any
+pointers to the overlay nodes or data. Any example of an inadvertent use
+of such pointers is if a driver or subsystem module is loaded after an
+overlay has been applied, and the driver or subsystem scans the entire
+devicetree or a large portion of it, including the overlay nodes.