diff mbox series

of/address: Fix of_node memory leak in of_dma_is_coherent

Message ID 20201110022825.30895-1-evan.nimmo@alliedtelesis.co.nz
State Accepted
Headers show
Series of/address: Fix of_node memory leak in of_dma_is_coherent | expand

Checks

Context Check Description
robh/checkpatch warning total: 0 errors, 2 warnings, 14 lines checked

Commit Message

Evan Nimmo Nov. 10, 2020, 2:28 a.m. UTC
Commit dabf6b36b83a ("of: Add OF_DMA_DEFAULT_COHERENT & select it on
powerpc") added a check to of_dma_is_coherent which returns early
if OF_DMA_DEFAULT_COHERENT is enabled. This results in the of_node_put()
being skipped causing a memory leak. Moved the of_node_get() below this
check so we now we only get the node if OF_DMA_DEFAULT_COHERENT is not
enabled.

Fixes: dabf6b36b83a ("of: Add OF_DMA_DEFAULT_COHERENT & select it on
powerpc")

Signed-off-by: Evan Nimmo <evan.nimmo@alliedtelesis.co.nz>
---
 drivers/of/address.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Rob Herring Nov. 11, 2020, 7:07 p.m. UTC | #1
On Tue, 10 Nov 2020 15:28:25 +1300, Evan Nimmo wrote:
> Commit dabf6b36b83a ("of: Add OF_DMA_DEFAULT_COHERENT & select it on
> powerpc") added a check to of_dma_is_coherent which returns early
> if OF_DMA_DEFAULT_COHERENT is enabled. This results in the of_node_put()
> being skipped causing a memory leak. Moved the of_node_get() below this
> check so we now we only get the node if OF_DMA_DEFAULT_COHERENT is not
> enabled.
> 
> Fixes: dabf6b36b83a ("of: Add OF_DMA_DEFAULT_COHERENT & select it on
> powerpc")
> 
> Signed-off-by: Evan Nimmo <evan.nimmo@alliedtelesis.co.nz>
> ---
>  drivers/of/address.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 

Applied, thanks!
diff mbox series

Patch

diff --git a/drivers/of/address.c b/drivers/of/address.c
index eb9ab4f1e80b..1c3257a2d4e3 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -1034,11 +1034,13 @@  int of_dma_get_range(struct device_node *np, const struct bus_dma_region **map)
  */
 bool of_dma_is_coherent(struct device_node *np)
 {
-	struct device_node *node = of_node_get(np);
+	struct device_node *node;
 
 	if (IS_ENABLED(CONFIG_OF_DMA_DEFAULT_COHERENT))
 		return true;
 
+	node = of_node_get(np);
+
 	while (node) {
 		if (of_property_read_bool(node, "dma-coherent")) {
 			of_node_put(node);