[PATCH] cxl: Delete an unnecessary check before the function call "of_node_put"

Subsystems: char and misc drivers, the rest

STALE3400d

10 messages, 7 authors, 2016-10-05 · open the first message on its own page

[PATCH] cxl: Delete an unnecessary check before the function call "of_node_put"

From: SF Markus Elfring <hidden>
Date: 2016-07-20 13:21:21

From: Markus Elfring <redacted>
Date: Wed, 20 Jul 2016 15:10:32 +0200

The of_node_put() function tests whether its argument is NULL
and then returns immediately.
Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <redacted>
---
 drivers/misc/cxl/of.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/misc/cxl/of.c b/drivers/misc/cxl/of.c
index edc4583..333256a 100644
--- a/drivers/misc/cxl/of.c
+++ b/drivers/misc/cxl/of.c
@@ -490,8 +490,7 @@ int cxl_of_probe(struct platform_device *pdev)
 		adapter->slices = 0;
 	}
 
-	if (afu_np)
-		of_node_put(afu_np);
+	of_node_put(afu_np);
 	return 0;
 }
 
-- 
2.9.2

Re: [PATCH] cxl: Delete an unnecessary check before the function call "of_node_put"

From: Julia Lawall <hidden>
Date: 2016-07-20 13:38:23


On Wed, 20 Jul 2016, SF Markus Elfring wrote:
quoted hunk
From: Markus Elfring <redacted>
Date: Wed, 20 Jul 2016 15:10:32 +0200

The of_node_put() function tests whether its argument is NULL
and then returns immediately.
Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <redacted>
---
 drivers/misc/cxl/of.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/misc/cxl/of.c b/drivers/misc/cxl/of.c
index edc4583..333256a 100644
--- a/drivers/misc/cxl/of.c
+++ b/drivers/misc/cxl/of.c
@@ -490,8 +490,7 @@ int cxl_of_probe(struct platform_device *pdev)
 		adapter->slices = 0;
 	}

-	if (afu_np)
-		of_node_put(afu_np);
+	of_node_put(afu_np);
 	return 0;
 }
I don't think that the call should be there at all.  The loop only exits
when afu_np is NULL.  Furthermore, the loop should not be written as a for
loop, but rather with for_each_child_of_node.

julia

Re: [PATCH] cxl: Delete an unnecessary check before the function call "of_node_put"

From: Andrew Donnellan <hidden>
Date: 2016-07-27 08:57:49

On 20/07/16 23:38, Julia Lawall wrote:
I don't think that the call should be there at all.  The loop only exits
when afu_np is NULL.  Furthermore, the loop should not be written as a for
loop, but rather with for_each_child_of_node.
Will send a patch to fix both issues shortly.

-- 
Andrew Donnellan              OzLabs, ADL Canberra
andrew.donnellan@au1.ibm.com  IBM Australia Limited

[PATCH] cxl: replace loop with for_each_child_of_node(), remove unneeded of_node_put()

From: Andrew Donnellan <hidden>
Date: 2016-07-29 03:56:48

Rewrite the cxl_guest_init_afu() loop in cxl_of_probe() to use
for_each_child_of_node() rather than a hand-coded for loop.

Remove the useless of_node_put(afu_np) call after the loop, where it's
guaranteed that afu_np == NULL.

Reported-by: SF Markus Elfring <redacted>
Reported-by: Julia Lawall <redacted>
Signed-off-by: Andrew Donnellan <redacted>

---

Checked the of_node_put() with Fred, he thinks it was probably just left
over from an earlier private version of the code and we can just get rid of
it.
---
 drivers/misc/cxl/of.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/misc/cxl/of.c b/drivers/misc/cxl/of.c
index edc4583..ec175ea 100644
--- a/drivers/misc/cxl/of.c
+++ b/drivers/misc/cxl/of.c
@@ -460,7 +460,7 @@ int cxl_of_probe(struct platform_device *pdev)
 	struct device_node *afu_np = NULL;
 	struct cxl *adapter = NULL;
 	int ret;
-	int slice, slice_ok;
+	int slice = 0, slice_ok = 0;
 
 	pr_devel("in %s\n", __func__);
 
@@ -476,13 +476,13 @@ int cxl_of_probe(struct platform_device *pdev)
 	}
 
 	/* init afu */
-	slice_ok = 0;
-	for (afu_np = NULL, slice = 0; (afu_np = of_get_next_child(np, afu_np)); slice++) {
+	for_each_child_of_node(np, afu_np) {
 		if ((ret = cxl_guest_init_afu(adapter, slice, afu_np)))
 			dev_err(&pdev->dev, "AFU %i failed to initialise: %i\n",
 				slice, ret);
 		else
 			slice_ok++;
+		slice++;
 	}
 
 	if (slice_ok == 0) {
@@ -490,8 +490,6 @@ int cxl_of_probe(struct platform_device *pdev)
 		adapter->slices = 0;
 	}
 
-	if (afu_np)
-		of_node_put(afu_np);
 	return 0;
 }
 
-- 
Andrew Donnellan              OzLabs, ADL Canberra
andrew.donnellan@au1.ibm.com  IBM Australia Limited

Re: [PATCH] cxl: replace loop with for_each_child_of_node(), remove unneeded of_node_put()

From: Frederic Barrat <hidden>
Date: 2016-07-29 07:43:31

Le 29/07/2016 à 05:55, Andrew Donnellan a écrit :
Rewrite the cxl_guest_init_afu() loop in cxl_of_probe() to use
for_each_child_of_node() rather than a hand-coded for loop.

Remove the useless of_node_put(afu_np) call after the loop, where it's
guaranteed that afu_np == NULL.

Reported-by: SF Markus Elfring <redacted>
Reported-by: Julia Lawall <redacted>
Signed-off-by: Andrew Donnellan <redacted>

Thanks!

Reviewed-by: Frederic Barrat <redacted>

Re: [PATCH] cxl: replace loop with for_each_child_of_node(), remove unneeded of_node_put()

From: walter harms <hidden>
Date: 2016-07-29 08:47:15


Am 29.07.2016 05:55, schrieb Andrew Donnellan:
quoted hunk
Rewrite the cxl_guest_init_afu() loop in cxl_of_probe() to use
for_each_child_of_node() rather than a hand-coded for loop.

Remove the useless of_node_put(afu_np) call after the loop, where it's
guaranteed that afu_np == NULL.

Reported-by: SF Markus Elfring <redacted>
Reported-by: Julia Lawall <redacted>
Signed-off-by: Andrew Donnellan <redacted>

---

Checked the of_node_put() with Fred, he thinks it was probably just left
over from an earlier private version of the code and we can just get rid of
it.
---
 drivers/misc/cxl/of.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/misc/cxl/of.c b/drivers/misc/cxl/of.c
index edc4583..ec175ea 100644
--- a/drivers/misc/cxl/of.c
+++ b/drivers/misc/cxl/of.c
@@ -460,7 +460,7 @@ int cxl_of_probe(struct platform_device *pdev)
 	struct device_node *afu_np = NULL;
 	struct cxl *adapter = NULL;
 	int ret;
-	int slice, slice_ok;
+	int slice = 0, slice_ok = 0;
 
 	pr_devel("in %s\n", __func__);
 
@@ -476,13 +476,13 @@ int cxl_of_probe(struct platform_device *pdev)
 	}
 
 	/* init afu */
-	slice_ok = 0;
-	for (afu_np = NULL, slice = 0; (afu_np = of_get_next_child(np, afu_np)); slice++) {
+	for_each_child_of_node(np, afu_np) {
 		if ((ret = cxl_guest_init_afu(adapter, slice, afu_np)))
 			dev_err(&pdev->dev, "AFU %i failed to initialise: %i\n",
 				slice, ret);
 		else
 			slice_ok++;
+		slice++;
 	}
while you are here ..
you could move the assign out of the condition..

ret = cxl_guest_init_afu(adapter, slice, afu_np);
if (ret) ....

just my 2 cents,

re,
 wh
quoted hunk
 
 	if (slice_ok == 0) {
@@ -490,8 +490,6 @@ int cxl_of_probe(struct platform_device *pdev)
 		adapter->slices = 0;
 	}
 
-	if (afu_np)
-		of_node_put(afu_np);
 	return 0;
 }
 

Re: [PATCH] cxl: replace loop with for_each_child_of_node(), remove unneeded of_node_put()

From: Julia Lawall <hidden>
Date: 2016-07-29 08:48:51


On Fri, 29 Jul 2016, walter harms wrote:

Am 29.07.2016 05:55, schrieb Andrew Donnellan:
quoted
Rewrite the cxl_guest_init_afu() loop in cxl_of_probe() to use
for_each_child_of_node() rather than a hand-coded for loop.

Remove the useless of_node_put(afu_np) call after the loop, where it's
guaranteed that afu_np == NULL.

Reported-by: SF Markus Elfring <redacted>
Reported-by: Julia Lawall <redacted>
Signed-off-by: Andrew Donnellan <redacted>

---

Checked the of_node_put() with Fred, he thinks it was probably just left
over from an earlier private version of the code and we can just get rid of
it.
---
 drivers/misc/cxl/of.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/misc/cxl/of.c b/drivers/misc/cxl/of.c
index edc4583..ec175ea 100644
--- a/drivers/misc/cxl/of.c
+++ b/drivers/misc/cxl/of.c
@@ -460,7 +460,7 @@ int cxl_of_probe(struct platform_device *pdev)
 	struct device_node *afu_np = NULL;
 	struct cxl *adapter = NULL;
 	int ret;
-	int slice, slice_ok;
+	int slice = 0, slice_ok = 0;

 	pr_devel("in %s\n", __func__);
@@ -476,13 +476,13 @@ int cxl_of_probe(struct platform_device *pdev)
 	}

 	/* init afu */
-	slice_ok = 0;
-	for (afu_np = NULL, slice = 0; (afu_np = of_get_next_child(np, afu_np)); slice++) {
+	for_each_child_of_node(np, afu_np) {
 		if ((ret = cxl_guest_init_afu(adapter, slice, afu_np)))
 			dev_err(&pdev->dev, "AFU %i failed to initialise: %i\n",
 				slice, ret);
 		else
 			slice_ok++;
+		slice++;
 	}
while you are here ..
you could move the assign out of the condition..

ret = cxl_guest_init_afu(adapter, slice, afu_np);
if (ret) ....
Yes, please.

julia

just my 2 cents,

re,
 wh
quoted
 	if (slice_ok == 0) {
@@ -490,8 +490,6 @@ int cxl_of_probe(struct platform_device *pdev)
 		adapter->slices = 0;
 	}

-	if (afu_np)
-		of_node_put(afu_np);
 	return 0;
 }
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Re: [PATCH] cxl: replace loop with for_each_child_of_node(), remove unneeded of_node_put()

From: Michael Ellerman <mpe@ellerman.id.au>
Date: 2016-07-29 11:38:56

Andrew Donnellan [off-list ref] writes:
Rewrite the cxl_guest_init_afu() loop in cxl_of_probe() to use
for_each_child_of_node() rather than a hand-coded for loop.

Remove the useless of_node_put(afu_np) call after the loop, where it's
guaranteed that afu_np == NULL.

Reported-by: SF Markus Elfring <redacted>
Reported-by: Julia Lawall <redacted>
Signed-off-by: Andrew Donnellan <redacted>

---

Checked the of_node_put() with Fred, he thinks it was probably just left
over from an earlier private version of the code and we can just get rid of
it.
But who does keep a reference on the device_node? I can't see it anywhere. Which
means in theory the device_node can be freed out from under you.

You have a reference for afu_np as part of for_each_child_of_node(), but it's
dropped as soon as you go around the loop.

The typical pattern would be that cxl_guest_init_afu() takes an additional
reference once it's done all its setup and can't fail.

That way at the end of the loop when the loop construct has dropped all
references, the nodes you actually init'ed have their reference count
incremented by 1.

cheers

Re: [PATCH] cxl: replace loop with for_each_child_of_node(), remove unneeded of_node_put()

From: Frederic Barrat <hidden>
Date: 2016-08-01 17:32:53

Le 29/07/2016 à 13:38, Michael Ellerman a écrit :
But who does keep a reference on the device_node? I can't see it anywhere. Which
means in theory the device_node can be freed out from under you.

You have a reference for afu_np as part of for_each_child_of_node(), but it's
dropped as soon as you go around the loop.

The typical pattern would be that cxl_guest_init_afu() takes an additional
reference once it's done all its setup and can't fail.

That way at the end of the loop when the loop construct has dropped all
references, the nodes you actually init'ed have their reference count
incremented by 1.

We don't keep a reference on the AFU device_node. Once we've read the 
config of the AFU, the AFU device_node is never accessed again. So I 
guess it's possible (though unexpected) that it's freed from under us, 
but it should not affect the driver.

The AFU is really dependent on the adapter itself, which is one level up 
in the device tree, and for which we create a device through 
of_platform_device_create(). The properties under the AFU device node 
are read directly from the PCI config space in the bare-metal case, 
where the cxl adapter is a PCI device.

Do we really have a problem here?

   Fred

Re: cxl: replace loop with for_each_child_of_node(), remove unneeded of_node_put()

From: Michael Ellerman <hidden>
Date: 2016-10-05 02:36:33

On Fri, 2016-29-07 at 03:55:34 UTC, Andrew Donnellan wrote:
Rewrite the cxl_guest_init_afu() loop in cxl_of_probe() to use
for_each_child_of_node() rather than a hand-coded for loop.

Remove the useless of_node_put(afu_np) call after the loop, where it's
guaranteed that afu_np == NULL.

Reported-by: SF Markus Elfring <redacted>
Reported-by: Julia Lawall <redacted>
Signed-off-by: Andrew Donnellan <redacted>
Reviewed-by: Frederic Barrat <redacted>
Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/735840b44bcc998e2574faf63d1aaa

cheers
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help