of: device: Fix missing of_node_put() in of_dma_set_restricted_buffer
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.
--- drivers/of/device.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
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); }/*
Signature · 1 line
2.25.1
Rob Herring
maintainerQuoted 15 lines · Liang He
We should use
of_node_put()for the reference 'node' returned byof_parse_phandle()which will increase the refcount.Fixes fec9b625095f ("of: Add plumbing for restricted DMA pool")Co-authored-by Miaoqian Lin <[email protected]>Signed-off-by Liang He <[email protected]>--- drivers/of/device.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/of/device.c +0
-0
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
Quoted 29 lines · Rob Herring
Quoted 15 lines · Liang He
We should use
of_node_put()for the reference 'node' returned byof_parse_phandle()which will increase the refcount.Fixes fec9b625095f ("of: Add plumbing for restricted DMA pool")Co-authored-by Miaoqian Lin <[email protected]>Signed-off-by Liang He <[email protected]>--- drivers/of/device.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/of/device.c +0
-0drivers/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
Quoted 29 lines · Rob Herring
Quoted 15 lines · Liang He
We should use
of_node_put()for the reference 'node' returned byof_parse_phandle()which will increase the refcount.Fixes fec9b625095f ("of: Add plumbing for restricted DMA pool")Co-authored-by Miaoqian Lin <[email protected]>Signed-off-by Liang He <[email protected]>--- drivers/of/device.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/of/device.c +0
-0drivers/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
Rob Herring
maintainerQuoted 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 byof_parse_phandle()which will increase the refcount.Fixes fec9b625095f ("of: Add plumbing for restricted DMA pool")Co-authored-by Miaoqian Lin <[email protected]>Signed-off-by Liang He <[email protected]>--- drivers/of/device.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/of/device.c +0
-0drivers/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()andof_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 useof_for_each_phandle().
Ah, okay. I've applied this now. Thanks.
Rob