diff mbox series

dmaengine: mv_xor: use for_each_child_of_node_scoped to avoid reference leak

Message ID 20241216043147.503192-1-joe@pf.is.s.u-tokyo.ac.jp (mailing list archive)
State New
Headers show
Series dmaengine: mv_xor: use for_each_child_of_node_scoped to avoid reference leak | expand

Commit Message

Joe Hattori Dec. 16, 2024, 4:31 a.m. UTC
Current implementation of mv_xor_probe() leaks OF node references
obtained in for_each_child_of_node. Avoid this by switching to
for_each_child_of_node_scoped.

This bug was found by an experimental static analysis tool that I am
developing.

Fixes: f7d12ef53ddf ("dma: mv_xor: add Device Tree binding")
Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
---
 drivers/dma/mv_xor.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Krzysztof Kozlowski Dec. 17, 2024, 11:04 a.m. UTC | #1
On 16/12/2024 05:31, Joe Hattori wrote:
> Current implementation of mv_xor_probe() leaks OF node references
> obtained in for_each_child_of_node. Avoid this by switching to
> for_each_child_of_node_scoped.
> 
> This bug was found by an experimental static analysis tool that I am
> developing.
> 
> Fixes: f7d12ef53ddf ("dma: mv_xor: add Device Tree binding")
> Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>

Looks like re-doing:
https://lore.kernel.org/all/20241011-dma_mv_xor_of_node_put-v1-2-3c2de819f463@gmail.com/


Best regards,
Krzysztof
diff mbox series

Patch

diff --git a/drivers/dma/mv_xor.c b/drivers/dma/mv_xor.c
index 43efce77bb57..fa6e4646fdc2 100644
--- a/drivers/dma/mv_xor.c
+++ b/drivers/dma/mv_xor.c
@@ -1369,10 +1369,9 @@  static int mv_xor_probe(struct platform_device *pdev)
 		return 0;
 
 	if (pdev->dev.of_node) {
-		struct device_node *np;
 		int i = 0;
 
-		for_each_child_of_node(pdev->dev.of_node, np) {
+		for_each_child_of_node_scoped(pdev->dev.of_node, np) {
 			struct mv_xor_chan *chan;
 			dma_cap_mask_t cap_mask;
 			int irq;