mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] dmaengine: mv_xor: fix child node handling and switch to scoped loop
@ 2024-10-11 20:57 Javier Carrasco
  2024-10-11 20:57 ` [PATCH 1/2] dmaengine: mv_xor: fix child node refcount handling in early exit Javier Carrasco
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Javier Carrasco @ 2024-10-11 20:57 UTC (permalink / raw)
  To: Vinod Koul, Thomas Petazzoni
  Cc: dmaengine, linux-kernel, Javier Carrasco, stable

This series fixes a wrong handling of the child node within the
for_each_child_of_node() by adding the missing calls to of_node_put() to
make it compatible with stable kernels that don't provide the scoped
variant of the macro, which is more secure and was introduced early this
year. The switch to the scoped macro is the next patch, which makes the
coe more robust and will avoid such issues in new error paths.

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
Javier Carrasco (2):
      dmaengine: mv_xor: fix child node refcount handling in early exit
      dmaengine: mv_xor: switch to for_each_child_of_node_scoped()

 drivers/dma/mv_xor.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
---
base-commit: d61a00525464bfc5fe92c6ad713350988e492b88
change-id: 20241011-dma_mv_xor_of_node_put-5cc4126746a2

Best regards,
-- 
Javier Carrasco <javier.carrasco.cruz@gmail.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] dmaengine: mv_xor: fix child node refcount handling in early exit
  2024-10-11 20:57 [PATCH 0/2] dmaengine: mv_xor: fix child node handling and switch to scoped loop Javier Carrasco
@ 2024-10-11 20:57 ` Javier Carrasco
  2024-10-11 20:58 ` [PATCH 2/2] dmaengine: mv_xor: switch to for_each_child_of_node_scoped() Javier Carrasco
  2024-12-24 10:42 ` (subset) [PATCH 0/2] dmaengine: mv_xor: fix child node handling and switch to scoped loop Vinod Koul
  2 siblings, 0 replies; 4+ messages in thread
From: Javier Carrasco @ 2024-10-11 20:57 UTC (permalink / raw)
  To: Vinod Koul, Thomas Petazzoni
  Cc: dmaengine, linux-kernel, Javier Carrasco, stable

The for_each_child_of_node() loop requires explicit calls to
of_node_put() to decrement the child's refcount upon early exits (break,
goto, return).

Add the missing calls in the two early exits before the goto
instructions.

Cc: stable@vger.kernel.org
Fixes: f7d12ef53ddf ("dma: mv_xor: add Device Tree binding")
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
 drivers/dma/mv_xor.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/dma/mv_xor.c b/drivers/dma/mv_xor.c
index 43efce77bb57..40b76b40bc30 100644
--- a/drivers/dma/mv_xor.c
+++ b/drivers/dma/mv_xor.c
@@ -1388,6 +1388,7 @@ static int mv_xor_probe(struct platform_device *pdev)
 			irq = irq_of_parse_and_map(np, 0);
 			if (!irq) {
 				ret = -ENODEV;
+				of_node_put(np);
 				goto err_channel_add;
 			}
 
@@ -1396,6 +1397,7 @@ static int mv_xor_probe(struct platform_device *pdev)
 			if (IS_ERR(chan)) {
 				ret = PTR_ERR(chan);
 				irq_dispose_mapping(irq);
+				of_node_put(np);
 				goto err_channel_add;
 			}
 

-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] dmaengine: mv_xor: switch to for_each_child_of_node_scoped()
  2024-10-11 20:57 [PATCH 0/2] dmaengine: mv_xor: fix child node handling and switch to scoped loop Javier Carrasco
  2024-10-11 20:57 ` [PATCH 1/2] dmaengine: mv_xor: fix child node refcount handling in early exit Javier Carrasco
@ 2024-10-11 20:58 ` Javier Carrasco
  2024-12-24 10:42 ` (subset) [PATCH 0/2] dmaengine: mv_xor: fix child node handling and switch to scoped loop Vinod Koul
  2 siblings, 0 replies; 4+ messages in thread
From: Javier Carrasco @ 2024-10-11 20:58 UTC (permalink / raw)
  To: Vinod Koul, Thomas Petazzoni; +Cc: dmaengine, linux-kernel, Javier Carrasco

Introduce the scoped variant of the loop to automatically release the
child node when it goes out of scope, which is more robust than the
non-scoped variant, and accounts for new early exits that could be added
in the future.

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
 drivers/dma/mv_xor.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/dma/mv_xor.c b/drivers/dma/mv_xor.c
index 40b76b40bc30..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;
@@ -1388,7 +1387,6 @@ static int mv_xor_probe(struct platform_device *pdev)
 			irq = irq_of_parse_and_map(np, 0);
 			if (!irq) {
 				ret = -ENODEV;
-				of_node_put(np);
 				goto err_channel_add;
 			}
 
@@ -1397,7 +1395,6 @@ static int mv_xor_probe(struct platform_device *pdev)
 			if (IS_ERR(chan)) {
 				ret = PTR_ERR(chan);
 				irq_dispose_mapping(irq);
-				of_node_put(np);
 				goto err_channel_add;
 			}
 

-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: (subset) [PATCH 0/2] dmaengine: mv_xor: fix child node handling and switch to scoped loop
  2024-10-11 20:57 [PATCH 0/2] dmaengine: mv_xor: fix child node handling and switch to scoped loop Javier Carrasco
  2024-10-11 20:57 ` [PATCH 1/2] dmaengine: mv_xor: fix child node refcount handling in early exit Javier Carrasco
  2024-10-11 20:58 ` [PATCH 2/2] dmaengine: mv_xor: switch to for_each_child_of_node_scoped() Javier Carrasco
@ 2024-12-24 10:42 ` Vinod Koul
  2 siblings, 0 replies; 4+ messages in thread
From: Vinod Koul @ 2024-12-24 10:42 UTC (permalink / raw)
  To: Thomas Petazzoni, Javier Carrasco; +Cc: dmaengine, linux-kernel, stable


On Fri, 11 Oct 2024 22:57:58 +0200, Javier Carrasco wrote:
> This series fixes a wrong handling of the child node within the
> for_each_child_of_node() by adding the missing calls to of_node_put() to
> make it compatible with stable kernels that don't provide the scoped
> variant of the macro, which is more secure and was introduced early this
> year. The switch to the scoped macro is the next patch, which makes the
> coe more robust and will avoid such issues in new error paths.
> 
> [...]

Applied, thanks!

[2/2] dmaengine: mv_xor: switch to for_each_child_of_node_scoped()
      commit: 9f6caa3978b0e859da39e4ace7973b877222dfd4

Best regards,
-- 
~Vinod



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-12-24 10:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-11 20:57 [PATCH 0/2] dmaengine: mv_xor: fix child node handling and switch to scoped loop Javier Carrasco
2024-10-11 20:57 ` [PATCH 1/2] dmaengine: mv_xor: fix child node refcount handling in early exit Javier Carrasco
2024-10-11 20:58 ` [PATCH 2/2] dmaengine: mv_xor: switch to for_each_child_of_node_scoped() Javier Carrasco
2024-12-24 10:42 ` (subset) [PATCH 0/2] dmaengine: mv_xor: fix child node handling and switch to scoped loop Vinod Koul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®