of: overlay: do not free changeset when of_overlay_apply returns error
authorFrank Rowand <frank.rowand@sony.com>
Mon, 2 May 2022 18:17:42 +0000 (13:17 -0500)
committerRob Herring <robh@kernel.org>
Tue, 3 May 2022 16:53:15 +0000 (11:53 -0500)
commit421f4d14bc037f708a3d11fbb01274b741767bf9
tree0dcc545c1d08ae4eed261f9f25a0a6c8b0ff5d08
parent992b0dc5c38a4e79dca17577960c5201275b83f1
of: overlay: do not free changeset when of_overlay_apply returns error

New unittests for overlay notifiers reveal a memory leak in
of_overlay_apply() when a notifier returns an error for action
OF_OVERLAY_POST_APPLY.  The pr_err() message is:

   OF: ERROR: memory leak, expected refcount 1 instead of 3,
   of_node_get()/of_node_put() unbalanced - destroy cset entry: attach
   overlay node /testcase-data/overlay-node/test-bus/test-unittest17

Change the error path to no longer call free_overlay_changeset(),
and document that the caller of of_overlay_fdt_apply() may choose
to remove the overlay.

Update the unittest that triggered the error to expect the changed
return values and to call of_overlay_remove().

Signed-off-by: Frank Rowand <frank.rowand@sony.com>
Signed-off-by: Rob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/20220502181742.1402826-4-frowand.list@gmail.com
drivers/of/overlay.c
drivers/of/unittest.c