Skip to content

Commit 55e95bf

Browse files
Dan Carpenterrobherring
authored andcommitted
of: dynamic: Fix potential memory leak in of_changeset_action()
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 <[email protected]> Closes: https://lore.kernel.org/r/[email protected]/ Signed-off-by: Dan Carpenter <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Rob Herring <[email protected]>
1 parent 0bb80ec commit 55e95bf

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/of/dynamic.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -890,13 +890,13 @@ int of_changeset_action(struct of_changeset *ocs, unsigned long action,
890890
{
891891
struct of_changeset_entry *ce;
892892

893+
if (WARN_ON(action >= ARRAY_SIZE(action_names)))
894+
return -EINVAL;
895+
893896
ce = kzalloc(sizeof(*ce), GFP_KERNEL);
894897
if (!ce)
895898
return -ENOMEM;
896899

897-
if (WARN_ON(action >= ARRAY_SIZE(action_names)))
898-
return -EINVAL;
899-
900900
/* get a reference to the node */
901901
ce->action = action;
902902
ce->np = of_node_get(np);

0 commit comments

Comments
 (0)