linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCI/hotplug: Remove unneeded of_node_put() in pnv_php
@ 2021-10-20  9:46 Wan Jiabing
  2021-10-20 11:39 ` Nathan Lynch
  2021-10-20 16:53 ` Tyrel Datwyler
  0 siblings, 2 replies; 4+ messages in thread
From: Wan Jiabing @ 2021-10-20  9:46 UTC (permalink / raw)
  To: Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Bjorn Helgaas, linuxppc-dev, linux-pci, linux-kernel
  Cc: kael_w, Wan Jiabing

Fix following coccicheck warning:
./drivers/pci/hotplug/pnv_php.c:161:2-13: ERROR: probable double put.

Device node iterators put the previous value of the index variable, so
an explicit put causes a double put.

Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
---
 drivers/pci/hotplug/pnv_php.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/pci/hotplug/pnv_php.c b/drivers/pci/hotplug/pnv_php.c
index f4c2e6e01be0..f3da4f95d73f 100644
--- a/drivers/pci/hotplug/pnv_php.c
+++ b/drivers/pci/hotplug/pnv_php.c
@@ -158,7 +158,6 @@ static void pnv_php_detach_device_nodes(struct device_node *parent)
 	for_each_child_of_node(parent, dn) {
 		pnv_php_detach_device_nodes(dn);
 
-		of_node_put(dn);
 		of_detach_node(dn);
 	}
 }
-- 
2.20.1


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

* Re: [PATCH] PCI/hotplug: Remove unneeded of_node_put() in pnv_php
  2021-10-20  9:46 [PATCH] PCI/hotplug: Remove unneeded of_node_put() in pnv_php Wan Jiabing
@ 2021-10-20 11:39 ` Nathan Lynch
  2021-10-20 16:57   ` Tyrel Datwyler
  2021-10-20 16:53 ` Tyrel Datwyler
  1 sibling, 1 reply; 4+ messages in thread
From: Nathan Lynch @ 2021-10-20 11:39 UTC (permalink / raw)
  To: Wan Jiabing
  Cc: kael_w, Wan Jiabing, Michael Ellerman, Benjamin Herrenschmidt,
	Paul Mackerras, Bjorn Helgaas, linuxppc-dev, linux-pci,
	linux-kernel, Tyrel Datwyler, ajd

Wan Jiabing <wanjiabing@vivo.com> writes:
> Fix following coccicheck warning:
> ./drivers/pci/hotplug/pnv_php.c:161:2-13: ERROR: probable double put.
>
> Device node iterators put the previous value of the index variable, so
> an explicit put causes a double put.

I suppose Coccinelle doesn't take into account that this code is
detaching and freeing the nodes.


> diff --git a/drivers/pci/hotplug/pnv_php.c b/drivers/pci/hotplug/pnv_php.c
> index f4c2e6e01be0..f3da4f95d73f 100644
> --- a/drivers/pci/hotplug/pnv_php.c
> +++ b/drivers/pci/hotplug/pnv_php.c
> @@ -158,7 +158,6 @@ static void pnv_php_detach_device_nodes(struct device_node *parent)
>  	for_each_child_of_node(parent, dn) {
>  		pnv_php_detach_device_nodes(dn);
>  
> -		of_node_put(dn);
>  		of_detach_node(dn);
>  	}

The code might be improved by comments explaining how the bare
of_node_put() corresponds to a "get" somewhere else in the driver, and
how it doesn't render the ongoing traversal unsafe. It looks suspicious
on first review, but I believe it's intentional and probably correct as
written.

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

* Re: [PATCH] PCI/hotplug: Remove unneeded of_node_put() in pnv_php
  2021-10-20  9:46 [PATCH] PCI/hotplug: Remove unneeded of_node_put() in pnv_php Wan Jiabing
  2021-10-20 11:39 ` Nathan Lynch
@ 2021-10-20 16:53 ` Tyrel Datwyler
  1 sibling, 0 replies; 4+ messages in thread
From: Tyrel Datwyler @ 2021-10-20 16:53 UTC (permalink / raw)
  To: Wan Jiabing, Michael Ellerman, Benjamin Herrenschmidt,
	Paul Mackerras, Bjorn Helgaas, linuxppc-dev, linux-pci,
	linux-kernel
  Cc: kael_w

On 10/20/21 2:46 AM, Wan Jiabing wrote:
> Fix following coccicheck warning:
> ./drivers/pci/hotplug/pnv_php.c:161:2-13: ERROR: probable double put.
> 
> Device node iterators put the previous value of the index variable, so
> an explicit put causes a double put.
> 
> Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>

NACK

This is a false positive from coccicheck. This is a case were a node is being
dynamically removed and the long reference needs to be dropped. Otherwise, the
reference count doesn't go to zero and trigger cleanup. This would result in us
ending up in a leaked device node.

-Tyrel

> ---
>  drivers/pci/hotplug/pnv_php.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/drivers/pci/hotplug/pnv_php.c b/drivers/pci/hotplug/pnv_php.c
> index f4c2e6e01be0..f3da4f95d73f 100644
> --- a/drivers/pci/hotplug/pnv_php.c
> +++ b/drivers/pci/hotplug/pnv_php.c
> @@ -158,7 +158,6 @@ static void pnv_php_detach_device_nodes(struct device_node *parent)
>  	for_each_child_of_node(parent, dn) {
>  		pnv_php_detach_device_nodes(dn);
> 
> -		of_node_put(dn);
>  		of_detach_node(dn);
>  	}
>  }
> 


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

* Re: [PATCH] PCI/hotplug: Remove unneeded of_node_put() in pnv_php
  2021-10-20 11:39 ` Nathan Lynch
@ 2021-10-20 16:57   ` Tyrel Datwyler
  0 siblings, 0 replies; 4+ messages in thread
From: Tyrel Datwyler @ 2021-10-20 16:57 UTC (permalink / raw)
  To: Nathan Lynch, Wan Jiabing
  Cc: kael_w, Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Bjorn Helgaas, linuxppc-dev, linux-pci, linux-kernel, ajd

On 10/20/21 4:39 AM, Nathan Lynch wrote:
> Wan Jiabing <wanjiabing@vivo.com> writes:
>> Fix following coccicheck warning:
>> ./drivers/pci/hotplug/pnv_php.c:161:2-13: ERROR: probable double put.
>>
>> Device node iterators put the previous value of the index variable, so
>> an explicit put causes a double put.
> 
> I suppose Coccinelle doesn't take into account that this code is
> detaching and freeing the nodes.
> 
> 
>> diff --git a/drivers/pci/hotplug/pnv_php.c b/drivers/pci/hotplug/pnv_php.c
>> index f4c2e6e01be0..f3da4f95d73f 100644
>> --- a/drivers/pci/hotplug/pnv_php.c
>> +++ b/drivers/pci/hotplug/pnv_php.c
>> @@ -158,7 +158,6 @@ static void pnv_php_detach_device_nodes(struct device_node *parent)
>>  	for_each_child_of_node(parent, dn) {
>>  		pnv_php_detach_device_nodes(dn);
>>  
>> -		of_node_put(dn);
>>  		of_detach_node(dn);
>>  	}
> 
> The code might be improved by comments explaining how the bare
> of_node_put() corresponds to a "get" somewhere else in the driver, and
> how it doesn't render the ongoing traversal unsafe. It looks suspicious
> on first review, but I believe it's intentional and probably correct as
> written.
> 

This is a common usage pattern which if we put a comment about the pattern here
we need to do it every where. I suppose a better solution is to wrap this put in
a more descriptive function name like of_node_long_put() or something of the
sort the makes it obvious we are dropping a long held global scope reference.

-Tyrel

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

end of thread, other threads:[~2021-10-20 16:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-20  9:46 [PATCH] PCI/hotplug: Remove unneeded of_node_put() in pnv_php Wan Jiabing
2021-10-20 11:39 ` Nathan Lynch
2021-10-20 16:57   ` Tyrel Datwyler
2021-10-20 16:53 ` Tyrel Datwyler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).