2021-04-08 07:29:25

by Dinghao Liu

[permalink] [raw]
Subject: [PATCH] PCI: tegra: Fix runtime PM imbalance in pex_ep_event_pex_rst_deassert

pm_runtime_get_sync() will increase the runtime PM counter
even it returns an error. Thus a pairing decrement is needed
to prevent refcount leak. Fix this by replacing this API with
pm_runtime_resume_and_get(), which will not change the runtime
PM counter on error.

Signed-off-by: Dinghao Liu <[email protected]>
---
drivers/pci/controller/dwc/pcie-tegra194.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/controller/dwc/pcie-tegra194.c b/drivers/pci/controller/dwc/pcie-tegra194.c
index 6fa216e52d14..0e94190ca4e8 100644
--- a/drivers/pci/controller/dwc/pcie-tegra194.c
+++ b/drivers/pci/controller/dwc/pcie-tegra194.c
@@ -1645,7 +1645,7 @@ static void pex_ep_event_pex_rst_deassert(struct tegra_pcie_dw *pcie)
if (pcie->ep_state == EP_STATE_ENABLED)
return;

- ret = pm_runtime_get_sync(dev);
+ ret = pm_runtime_resume_and_get(dev);
if (ret < 0) {
dev_err(dev, "Failed to get runtime sync for PCIe dev: %d\n",
ret);
--
2.17.1


2021-04-08 12:35:35

by Jon Hunter

[permalink] [raw]
Subject: Re: [PATCH] PCI: tegra: Fix runtime PM imbalance in pex_ep_event_pex_rst_deassert


On 08/04/2021 08:26, Dinghao Liu wrote:
> pm_runtime_get_sync() will increase the runtime PM counter
> even it returns an error. Thus a pairing decrement is needed
> to prevent refcount leak. Fix this by replacing this API with
> pm_runtime_resume_and_get(), which will not change the runtime
> PM counter on error.
>
> Signed-off-by: Dinghao Liu <[email protected]>
> ---
> drivers/pci/controller/dwc/pcie-tegra194.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/pci/controller/dwc/pcie-tegra194.c b/drivers/pci/controller/dwc/pcie-tegra194.c
> index 6fa216e52d14..0e94190ca4e8 100644
> --- a/drivers/pci/controller/dwc/pcie-tegra194.c
> +++ b/drivers/pci/controller/dwc/pcie-tegra194.c
> @@ -1645,7 +1645,7 @@ static void pex_ep_event_pex_rst_deassert(struct tegra_pcie_dw *pcie)
> if (pcie->ep_state == EP_STATE_ENABLED)
> return;
>
> - ret = pm_runtime_get_sync(dev);
> + ret = pm_runtime_resume_and_get(dev);
> if (ret < 0) {
> dev_err(dev, "Failed to get runtime sync for PCIe dev: %d\n",
> ret);
>

There are two places in the driver where pm_runtime_get_sync() is called.

Thanks
Jon

--
nvpublic

2021-04-08 13:10:36

by Thierry Reding

[permalink] [raw]
Subject: Re: [PATCH] PCI: tegra: Fix runtime PM imbalance in pex_ep_event_pex_rst_deassert

On Thu, Apr 08, 2021 at 01:34:37PM +0100, Jon Hunter wrote:
>
> On 08/04/2021 08:26, Dinghao Liu wrote:
> > pm_runtime_get_sync() will increase the runtime PM counter
> > even it returns an error. Thus a pairing decrement is needed
> > to prevent refcount leak. Fix this by replacing this API with
> > pm_runtime_resume_and_get(), which will not change the runtime
> > PM counter on error.
> >
> > Signed-off-by: Dinghao Liu <[email protected]>
> > ---
> > drivers/pci/controller/dwc/pcie-tegra194.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/pci/controller/dwc/pcie-tegra194.c b/drivers/pci/controller/dwc/pcie-tegra194.c
> > index 6fa216e52d14..0e94190ca4e8 100644
> > --- a/drivers/pci/controller/dwc/pcie-tegra194.c
> > +++ b/drivers/pci/controller/dwc/pcie-tegra194.c
> > @@ -1645,7 +1645,7 @@ static void pex_ep_event_pex_rst_deassert(struct tegra_pcie_dw *pcie)
> > if (pcie->ep_state == EP_STATE_ENABLED)
> > return;
> >
> > - ret = pm_runtime_get_sync(dev);
> > + ret = pm_runtime_resume_and_get(dev);
> > if (ret < 0) {
> > dev_err(dev, "Failed to get runtime sync for PCIe dev: %d\n",
> > ret);
> >
>
> There are two places in the driver where pm_runtime_get_sync() is called.

It looks like the second callsite has the proper cleanup code. Although
it might be nice to use pm_runtime_resume_and_get() there as well, and
adjust the cleanup path, to make this consistent.

In any case, this looks good to me:

Acked-by: Thierry Reding <[email protected]>


Attachments:
(No filename) (1.54 kB)
signature.asc (849.00 B)
Download all attachments

2021-04-08 17:09:02

by Lorenzo Pieralisi

[permalink] [raw]
Subject: Re: [PATCH] PCI: tegra: Fix runtime PM imbalance in pex_ep_event_pex_rst_deassert

On Thu, 8 Apr 2021 15:26:58 +0800, Dinghao Liu wrote:
> pm_runtime_get_sync() will increase the runtime PM counter
> even it returns an error. Thus a pairing decrement is needed
> to prevent refcount leak. Fix this by replacing this API with
> pm_runtime_resume_and_get(), which will not change the runtime
> PM counter on error.

Applied to pci/tegra, thanks!

[1/1] PCI: tegra: Fix runtime PM imbalance in pex_ep_event_pex_rst_deassert
https://git.kernel.org/lpieralisi/pci/c/571cdd5294

Thanks,
Lorenzo