max77779_fg: plug memleak: case 2.2.2: for_each_child_of_node() (v6.12 prep)
Case 2.2.2 from below bug:
If returning or breaking early from within
for_each_child_of_node(), a reference to the current device_node
remains and needs to be dropped, either right away, or later if
used past that loop to avoid a memleak.
This driver uses for_each_child_of_node() to find the battery child
node. While for_each_child_of_node() free's each node using
of_node_put() during loop iteration and normal loop exit, drivers have
to do that explicitly if they exit the loop early, as is the case here
(in max77779_fg_find_batt_node()), to avoid a memory leak.
The battery child node needs to remain while this driver is active, so
it's correct to keep the reference past max77779_fg_find_batt_node(),
but it does need to be free'd during driver unload to avoid a memleak.
Add the missing of_node_put() during driver cleanup.
Test: TH
Bug: 370679843
Change-Id: I51298451cb5ce64a75753fbc44fc663c63944b98
Signed-off-by: André Draszik <[email protected]>
Signed-off-by: Will McVicker <[email protected]>
diff --git a/max77779_fg.c b/max77779_fg.c
index d32dfca..b9fdb26 100644
--- a/max77779_fg.c
+++ b/max77779_fg.c
@@ -3939,6 +3939,8 @@
power_supply_unregister(chip->psy);
maxfg_free_capture_buf(&chip->cb_lh);
+
+ of_node_put(chip->batt_node);
}
EXPORT_SYMBOL_GPL(max77779_fg_remove);