Skip to contentSkip to conversation

of: device: Fix missing of_node_put() in of_dma_set_restricted_buffer

PATCH In review Liang He 2 participants 5 messages Jul 2, 2022 – Jul 12, 2022 Device tree

lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH 1/1 of: device: Fix missing of_node_put() in of_dma_set_restricted_buffer

We should use of_node_put() for the reference 'node' returned by of_parse_phandle() which will increase the refcount.

Fixes fec9b625095f ("of: Add plumbing for restricted DMA pool")
---
 drivers/of/device.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/of/device.c +4 -1
index 874f031442dc..75b6cbffa755 100644
@@ -81,8 +81,11 @@ of_dma_set_restricted_buffer(struct device *dev, struct device_node *np)
 		 * restricted-dma-pool region is allowed.
 		 */
 		if (of_device_is_compatible(node, "restricted-dma-pool") &&
-		    of_device_is_available(node))
+		    of_device_is_available(node)) {
+			of_node_put(node);
 			break;
+		}
+		of_node_put(node);
 	}
 
 	/*
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 15 lines · Liang He

We should use of_node_put() for the reference 'node' returned by of_parse_phandle() which will increase the refcount.

Fixes fec9b625095f ("of: Add plumbing for restricted DMA pool")
---
 drivers/of/device.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/of/device.c +0 -0
index 874f031442dc..75b6cbffa755 100644

drivers/of/device.c of_dma_set_restricted_buffer(struct device *dev, struct device_node *np) · line 88

Quoted 9 lines
drivers/of/device.c +4 -1
@@ -81,8 +81,11 @@ of_dma_set_restricted_buffer(struct device *dev, struct device_node *np)
 		 * restricted-dma-pool region is allowed.
 		 */
 		if (of_device_is_compatible(node, "restricted-dma-pool") &&
-		    of_device_is_available(node))
+		    of_device_is_available(node)) {
+			of_node_put(node);
 			break;
+		}
+		of_node_put(node);

This should be converted to use of_for_each_phandle() iterator instead. That takes care of the put here (but not in the break).

Rob

author
#2 lore raw
Quoted 29 lines · Rob Herring
Quoted 15 lines · Liang He

We should use of_node_put() for the reference 'node' returned by of_parse_phandle() which will increase the refcount.

Fixes fec9b625095f ("of: Add plumbing for restricted DMA pool")
---
 drivers/of/device.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/of/device.c +0 -0
index 874f031442dc..75b6cbffa755 100644

drivers/of/device.c of_dma_set_restricted_buffer(struct device *dev, struct device_node *np) · line 88

Quoted 9 lines
drivers/of/device.c +4 -1
@@ -81,8 +81,11 @@ of_dma_set_restricted_buffer(struct device *dev, struct device_node *np)
 		 * restricted-dma-pool region is allowed.
 		 */
 		if (of_device_is_compatible(node, "restricted-dma-pool") &&
-		    of_device_is_available(node))
+		    of_device_is_available(node)) {
+			of_node_put(node);
 			break;
+		}
+		of_node_put(node);

This should be converted to use of_for_each_phandle() iterator instead. That takes care of the put here (but not in the break).

Quoted 1 line

Rob

Thanks, Rob.

We try to rework the loop using of_for_each_phandle().

Thanks,

Liang

author
#3 lore raw
In reply to Rob Herring
Quoted 29 lines · Rob Herring
Quoted 15 lines · Liang He

We should use of_node_put() for the reference 'node' returned by of_parse_phandle() which will increase the refcount.

Fixes fec9b625095f ("of: Add plumbing for restricted DMA pool")
---
 drivers/of/device.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/of/device.c +0 -0
index 874f031442dc..75b6cbffa755 100644

drivers/of/device.c of_dma_set_restricted_buffer(struct device *dev, struct device_node *np) · line 88

Quoted 9 lines
drivers/of/device.c +4 -1
@@ -81,8 +81,11 @@ of_dma_set_restricted_buffer(struct device *dev, struct device_node *np)
 		 * restricted-dma-pool region is allowed.
 		 */
 		if (of_device_is_compatible(node, "restricted-dma-pool") &&
-		    of_device_is_available(node))
+		    of_device_is_available(node)) {
+			of_node_put(node);
 			break;
+		}
+		of_node_put(node);

This should be converted to use of_for_each_phandle() iterator instead. That takes care of the put here (but not in the break).

Quoted 1 line

Rob

Hi, Rob.

After I carefully read the implementation of of_for_each_phandle() and of_parse_phandle(), I think it is better to keep current coding style as it will change a lot of current code.

Besides, the loop index 'i' will be used in following of_reserved_mem_device_init_by_idx(), so I cannot give a simple and correct way to use of_for_each_phandle().

Thanks,

Liang

maintainer
#4 lore raw
Quoted 34 lines · Liang He
Quoted 29 lines · Rob Herring
Quoted 15 lines · Liang He

We should use of_node_put() for the reference 'node' returned by of_parse_phandle() which will increase the refcount.

Fixes fec9b625095f ("of: Add plumbing for restricted DMA pool")
---
 drivers/of/device.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/of/device.c +0 -0
index 874f031442dc..75b6cbffa755 100644

drivers/of/device.c of_dma_set_restricted_buffer(struct device *dev, struct device_node *np) · line 88

Quoted 9 lines
drivers/of/device.c +4 -1
@@ -81,8 +81,11 @@ of_dma_set_restricted_buffer(struct device *dev, struct device_node *np)
 		 * restricted-dma-pool region is allowed.
 		 */
 		if (of_device_is_compatible(node, "restricted-dma-pool") &&
-		    of_device_is_available(node))
+		    of_device_is_available(node)) {
+			of_node_put(node);
 			break;
+		}
+		of_node_put(node);

This should be converted to use of_for_each_phandle() iterator instead. That takes care of the put here (but not in the break).

Quoted 1 line

Rob

Quoted 7 lines

Hi, Rob.

After I carefully read the implementation of of_for_each_phandle() and of_parse_phandle(), I think it is better to keep current coding style as it will change a lot of current code.

Besides, the loop index 'i' will be used in following of_reserved_mem_device_init_by_idx(), so I cannot give a simple and correct way to use of_for_each_phandle().

Ah, okay. I've applied this now. Thanks.

Rob