Skip to content

Commit

Permalink
of: dynamic: Fix potential memory leak in of_changeset_action()
Browse files Browse the repository at this point in the history
commit 55e95bf upstream.

Smatch complains that the error path where "action" is invalid leaks
the "ce" allocation:
    drivers/of/dynamic.c:935 of_changeset_action()
    warn: possible memory leak of 'ce'

Fix this by doing the validation before the allocation.

Note that there is not any actual problem with upstream kernels. All
callers of of_changeset_action() are static inlines with fixed action
values.

Fixes: 914d9d8 ("of: dynamic: Refactor action prints to not use "%pOF" inside devtree_lock")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/r/202309011059.EOdr4im9-lkp@intel.com/
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/7dfaf999-30ad-491c-9615-fb1138db121c@moroto.mountain
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Dan Carpenter authored and gregkh committed Oct 10, 2023
1 parent 9c480fb commit 315ae63
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/of/dynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -902,13 +902,13 @@ int of_changeset_action(struct of_changeset *ocs, unsigned long action,
{
struct of_changeset_entry *ce;

if (WARN_ON(action >= ARRAY_SIZE(action_names)))
return -EINVAL;

ce = kzalloc(sizeof(*ce), GFP_KERNEL);
if (!ce)
return -ENOMEM;

if (WARN_ON(action >= ARRAY_SIZE(action_names)))
return -EINVAL;

/* get a reference to the node */
ce->action = action;
ce->np = of_node_get(np);
Expand Down

0 comments on commit 315ae63

Please sign in to comment.