soc: dove: release node before breaking child_of_node loop

Message ID Y+e+90hi6KwoB/xh@ubun2204.myguest.virtualbox.org
State New
Headers
Series soc: dove: release node before breaking child_of_node loop |

Commit Message

Deepak R Varma Feb. 11, 2023, 4:14 p.m. UTC
  The iterator for_each_available_child_of_node() increments the refcount
of the child node it is processing. Release such a reference when the
loop needs to break due to an error during its execution.
Issue identified using for_each_child.cocci Coccinelle semantic patch.

Signed-off-by: Deepak R Varma <drv@mailo.com>
---
Please note: The proposed change is compile tested only. I do not have the
necessary hardware to perform additional testing. Please suggest if there is an
alternate means available to further test this change.
 drivers/soc/dove/pmu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Andrew Lunn Feb. 11, 2023, 5:51 p.m. UTC | #1
On Sat, Feb 11, 2023 at 09:44:47PM +0530, Deepak R Varma wrote:
> The iterator for_each_available_child_of_node() increments the refcount
> of the child node it is processing. Release such a reference when the
> loop needs to break due to an error during its execution.
> Issue identified using for_each_child.cocci Coccinelle semantic patch.
> 
> Signed-off-by: Deepak R Varma <drv@mailo.com>

Looks reasonable.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
  

Patch

diff --git a/drivers/soc/dove/pmu.c b/drivers/soc/dove/pmu.c
index ffc5311c0ed8..6202dbcd20a8 100644
--- a/drivers/soc/dove/pmu.c
+++ b/drivers/soc/dove/pmu.c
@@ -410,13 +410,16 @@  int __init dove_init_pmu(void)
 		struct pmu_domain *domain;
 
 		domain = kzalloc(sizeof(*domain), GFP_KERNEL);
-		if (!domain)
+		if (!domain) {
+			of_node_put(np);
 			break;
+		}
 
 		domain->pmu = pmu;
 		domain->base.name = kasprintf(GFP_KERNEL, "%pOFn", np);
 		if (!domain->base.name) {
 			kfree(domain);
+			of_node_put(np);
 			break;
 		}