* [PATCH] PCI: kirin: Fix of_node_put() issue in pcie-kirin
@ 2021-11-03 6:25 Wan Jiabing
2021-11-03 14:30 ` Bjorn Helgaas
0 siblings, 1 reply; 4+ messages in thread
From: Wan Jiabing @ 2021-11-03 6:25 UTC (permalink / raw)
To: Xiaowei Song, Binghui Wang, Lorenzo Pieralisi, Rob Herring,
Krzysztof Wilczyński, Bjorn Helgaas, linux-pci,
linux-kernel
Cc: jiabing.wan, Wan Jiabing
Fix following coccicheck warning:
./drivers/pci/controller/dwc/pcie-kirin.c:414:2-34: WARNING: Function
for_each_available_child_of_node should have of_node_put() before return.
Early exits from for_each_available_child_of_node should decrement the
node reference counter. Replace return by goto here.
Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
---
drivers/pci/controller/dwc/pcie-kirin.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c
index 06017e826832..23a2c076ce53 100644
--- a/drivers/pci/controller/dwc/pcie-kirin.c
+++ b/drivers/pci/controller/dwc/pcie-kirin.c
@@ -422,7 +422,8 @@ static int kirin_pcie_parse_port(struct kirin_pcie *pcie,
pcie->num_slots++;
if (pcie->num_slots > MAX_PCI_SLOTS) {
dev_err(dev, "Too many PCI slots!\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto put_node;
}
ret = of_pci_get_devfn(child);
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] PCI: kirin: Fix of_node_put() issue in pcie-kirin
2021-11-03 6:25 [PATCH] PCI: kirin: Fix of_node_put() issue in pcie-kirin Wan Jiabing
@ 2021-11-03 14:30 ` Bjorn Helgaas
2021-11-04 13:56 ` Rob Herring
[not found] ` <AF*AtQCaEjn8dlEJIiS9Xqqm.9.1636034225636.Hmail.wanjiabing@vivo.com>
0 siblings, 2 replies; 4+ messages in thread
From: Bjorn Helgaas @ 2021-11-03 14:30 UTC (permalink / raw)
To: Wan Jiabing, Mauro Carvalho Chehab, Rob Herring
Cc: Xiaowei Song, Binghui Wang, Lorenzo Pieralisi,
Krzysztof Wilczyński, Bjorn Helgaas, linux-pci,
linux-kernel, jiabing.wan
[+to Mauro, author of code being changed,
Rob for "of_pci_get_devfn()" naming question]
On Wed, Nov 03, 2021 at 02:25:18AM -0400, Wan Jiabing wrote:
> Fix following coccicheck warning:
> ./drivers/pci/controller/dwc/pcie-kirin.c:414:2-34: WARNING: Function
> for_each_available_child_of_node should have of_node_put() before return.
>
> Early exits from for_each_available_child_of_node should decrement the
> node reference counter. Replace return by goto here.
>
> Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
> ---
> drivers/pci/controller/dwc/pcie-kirin.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c
> index 06017e826832..23a2c076ce53 100644
> --- a/drivers/pci/controller/dwc/pcie-kirin.c
> +++ b/drivers/pci/controller/dwc/pcie-kirin.c
> @@ -422,7 +422,8 @@ static int kirin_pcie_parse_port(struct kirin_pcie *pcie,
> pcie->num_slots++;
> if (pcie->num_slots > MAX_PCI_SLOTS) {
> dev_err(dev, "Too many PCI slots!\n");
> - return -EINVAL;
> + ret = -EINVAL;
> + goto put_node;
> }
>
> ret = of_pci_get_devfn(child);
This is a change to the code added here:
https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git/commit/?id=31bd24f0cfe0
This fix looks right to me; all the other early exits from the inner
loop drop the "child" reference.
But this is a nested loop and the *outer* loop also increments
refcounts, and I don't see that outer loop reference on "parent" being
dropped at all:
for_each_available_child_of_node(node, parent) {
for_each_available_child_of_node(parent, child) {
...
if (error)
goto put_node;
}
}
put_node:
of_node_put(child);
The "of_pci_get_devfn()" immediately after is unrelated, but possibly
a confusing name. "Get" often suggests a reference count being
increased, but that's not the case with of_pci_get_devfn().
I want to fix this before sending a pull request to Linus, and I can
easily squash it into a local branch, but I need an ack from Mauro
that this patch is correct and also a fix or explanation for the outer
loop reference situation.
Bjorn
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] PCI: kirin: Fix of_node_put() issue in pcie-kirin
2021-11-03 14:30 ` Bjorn Helgaas
@ 2021-11-04 13:56 ` Rob Herring
[not found] ` <AF*AtQCaEjn8dlEJIiS9Xqqm.9.1636034225636.Hmail.wanjiabing@vivo.com>
1 sibling, 0 replies; 4+ messages in thread
From: Rob Herring @ 2021-11-04 13:56 UTC (permalink / raw)
To: Bjorn Helgaas
Cc: Wan Jiabing, Mauro Carvalho Chehab, Xiaowei Song, Binghui Wang,
Lorenzo Pieralisi, Krzysztof Wilczyński, Bjorn Helgaas, PCI,
linux-kernel, jiabing.wan
On Wed, Nov 3, 2021 at 9:31 AM Bjorn Helgaas <helgaas@kernel.org> wrote:
>
> [+to Mauro, author of code being changed,
> Rob for "of_pci_get_devfn()" naming question]
>
> On Wed, Nov 03, 2021 at 02:25:18AM -0400, Wan Jiabing wrote:
> > Fix following coccicheck warning:
> > ./drivers/pci/controller/dwc/pcie-kirin.c:414:2-34: WARNING: Function
> > for_each_available_child_of_node should have of_node_put() before return.
> >
> > Early exits from for_each_available_child_of_node should decrement the
> > node reference counter. Replace return by goto here.
> >
> > Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
> > ---
> > drivers/pci/controller/dwc/pcie-kirin.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c
> > index 06017e826832..23a2c076ce53 100644
> > --- a/drivers/pci/controller/dwc/pcie-kirin.c
> > +++ b/drivers/pci/controller/dwc/pcie-kirin.c
> > @@ -422,7 +422,8 @@ static int kirin_pcie_parse_port(struct kirin_pcie *pcie,
> > pcie->num_slots++;
> > if (pcie->num_slots > MAX_PCI_SLOTS) {
> > dev_err(dev, "Too many PCI slots!\n");
> > - return -EINVAL;
> > + ret = -EINVAL;
> > + goto put_node;
> > }
> >
> > ret = of_pci_get_devfn(child);
>
> This is a change to the code added here:
> https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git/commit/?id=31bd24f0cfe0
>
> This fix looks right to me; all the other early exits from the inner
> loop drop the "child" reference.
>
> But this is a nested loop and the *outer* loop also increments
> refcounts, and I don't see that outer loop reference on "parent" being
> dropped at all:
>
> for_each_available_child_of_node(node, parent) {
> for_each_available_child_of_node(parent, child) {
> ...
> if (error)
> goto put_node;
> }
> }
>
> put_node:
> of_node_put(child);
Indeed. There should be a put on the parent.
This whole function is less than ideal as it assumes the board has 2
levels of PCI nodes. This might be another (like brcmstb thread) place
to use .add_bus(). But that's a problem for another day.
> The "of_pci_get_devfn()" immediately after is unrelated, but possibly
> a confusing name. "Get" often suggests a reference count being
> increased, but that's not the case with of_pci_get_devfn().
I guess you have to know that only nodes are refcounted and property
functions never are.
There's also of_pci_get_max_link_speed() and of_get_pci_domain_nr().
Rob
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] PCI: kirin: Fix of_node_put() issue in pcie-kirin
[not found] ` <AF*AtQCaEjn8dlEJIiS9Xqqm.9.1636034225636.Hmail.wanjiabing@vivo.com>
@ 2021-11-05 1:52 ` Jiabing Wan
0 siblings, 0 replies; 4+ messages in thread
From: Jiabing Wan @ 2021-11-05 1:52 UTC (permalink / raw)
To: Rob Herring, Bjorn Helgaas
Cc: Mauro Carvalho Chehab, Xiaowei Song, Binghui Wang,
Lorenzo Pieralisi, Krzysztof Wilczyński, Bjorn Helgaas, PCI,
linux-kernel, jiabing.wan
On 2021/11/4 21:56, Rob Herring wrote:
> On Wed, Nov 3, 2021 at 9:31 AM Bjorn Helgaas <helgaas@kernel.org> wrote:
>> [+to Mauro, author of code being changed,
>> Rob for "of_pci_get_devfn()" naming question]
>>
>> On Wed, Nov 03, 2021 at 02:25:18AM -0400, Wan Jiabing wrote:
>>> Fix following coccicheck warning:
>>> ./drivers/pci/controller/dwc/pcie-kirin.c:414:2-34: WARNING: Function
>>> for_each_available_child_of_node should have of_node_put() before return.
>>>
>>> Early exits from for_each_available_child_of_node should decrement the
>>> node reference counter. Replace return by goto here.
>>>
>>> Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
>>> ---
>>> drivers/pci/controller/dwc/pcie-kirin.c | 3 ++-
>>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c
>>> index 06017e826832..23a2c076ce53 100644
>>> --- a/drivers/pci/controller/dwc/pcie-kirin.c
>>> +++ b/drivers/pci/controller/dwc/pcie-kirin.c
>>> @@ -422,7 +422,8 @@ static int kirin_pcie_parse_port(struct kirin_pcie *pcie,
>>> pcie->num_slots++;
>>> if (pcie->num_slots > MAX_PCI_SLOTS) {
>>> dev_err(dev, "Too many PCI slots!\n");
>>> - return -EINVAL;
>>> + ret = -EINVAL;
>>> + goto put_node;
>>> }
>>>
>>> ret = of_pci_get_devfn(child);
>> This is a change to the code added here:
>> https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git/commit/?id=31bd24f0cfe0
>>
>> This fix looks right to me; all the other early exits from the inner
>> loop drop the "child" reference.
>>
>> But this is a nested loop and the *outer* loop also increments
>> refcounts, and I don't see that outer loop reference on "parent" being
>> dropped at all:
>>
>> for_each_available_child_of_node(node, parent) {
>> for_each_available_child_of_node(parent, child) {
>> ...
>> if (error)
>> goto put_node;
>> }
>> }
>>
>> put_node:
>> of_node_put(child);
> Indeed. There should be a put on the parent.
OK, I'll fix in v2. Thanks.
Jiabing Wan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-11-05 1:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-03 6:25 [PATCH] PCI: kirin: Fix of_node_put() issue in pcie-kirin Wan Jiabing
2021-11-03 14:30 ` Bjorn Helgaas
2021-11-04 13:56 ` Rob Herring
[not found] ` <AF*AtQCaEjn8dlEJIiS9Xqqm.9.1636034225636.Hmail.wanjiabing@vivo.com>
2021-11-05 1:52 ` Jiabing Wan
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).