of: overlay: rework overlay apply and remove kfree()s
authorFrank Rowand <frank.rowand@sony.com>
Wed, 20 Apr 2022 22:25:05 +0000 (17:25 -0500)
committerRob Herring <robh@kernel.org>
Mon, 25 Apr 2022 15:56:11 +0000 (10:56 -0500)
commit067c098766c6af667a9002d4e33cf1f3c998abbe
treed86a99533cbc90d9542846d54fc73cf0f7d09e14
parent1e4089667c7c732dd1b92c4c6bc7bd240ca30213
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
Documentation/devicetree/overlay-notes.rst
drivers/of/overlay.c
include/linux/of.h