2021-04-12 07:35:19

by Dinghao Liu

[permalink] [raw]
Subject: [PATCH] [v2] spi: spi-zynqmp-gqspi: Fix runtime PM imbalance in zynqmp_qspi_probe

There is a PM usage counter decrement after zynqmp_qspi_init_hw()
without any refcount increment, which leads to refcount leak.Add
a refcount increment to balance the refcount. Also set
auto_runtime_pm to resume suspended spi controller.

Signed-off-by: Dinghao Liu <[email protected]>
---
changelog:

v2: - Add a refcount increment to fix refcout leak instead of the
refcount decrement on error.
Set ctlr->auto_runtime_pm = true.
---
drivers/spi/spi-zynqmp-gqspi.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c
index c8fa6ee18ae7..8b21c7b0e7eb 100644
--- a/drivers/spi/spi-zynqmp-gqspi.c
+++ b/drivers/spi/spi-zynqmp-gqspi.c
@@ -1160,6 +1160,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT);
pm_runtime_set_active(&pdev->dev);
pm_runtime_enable(&pdev->dev);
+ pm_runtime_get_sync(&pdev->dev);
/* QSPI controller initializations */
zynqmp_qspi_init_hw(xqspi);

@@ -1187,6 +1188,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_RX_DUAL | SPI_RX_QUAD |
SPI_TX_DUAL | SPI_TX_QUAD;
ctlr->dev.of_node = np;
+ ctlr->auto_runtime_pm = true;

ret = devm_spi_register_controller(&pdev->dev, ctlr);
if (ret) {
--
2.17.1


2021-04-15 01:24:30

by quanyang wang

[permalink] [raw]
Subject: Re: [PATCH] [v2] spi: spi-zynqmp-gqspi: Fix runtime PM imbalance in zynqmp_qspi_probe

Hi Dinghao,
On Mon, Apr 12, 2021 at 03:31:54PM +0800, Dinghao Liu wrote:
> There is a PM usage counter decrement after zynqmp_qspi_init_hw()
> without any refcount increment, which leads to refcount leak.Add
> a refcount increment to balance the refcount. Also set
> auto_runtime_pm to resume suspended spi controller.
>
> Signed-off-by: Dinghao Liu <[email protected]>
> ---
> changelog:
>
> v2: - Add a refcount increment to fix refcout leak instead of the
> refcount decrement on error.
> Set ctlr->auto_runtime_pm = true.
> ---
> drivers/spi/spi-zynqmp-gqspi.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c
> index c8fa6ee18ae7..8b21c7b0e7eb 100644
> --- a/drivers/spi/spi-zynqmp-gqspi.c
> +++ b/drivers/spi/spi-zynqmp-gqspi.c
> @@ -1160,6 +1160,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
> pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT);
> pm_runtime_set_active(&pdev->dev);
> pm_runtime_enable(&pdev->dev);
> + pm_runtime_get_sync(&pdev->dev);
Please check the return value here, if ret is "< 0", goto error label,
and a pm_runtime_put_sync is needed in error label
> /* QSPI controller initializations */
> zynqmp_qspi_init_hw(xqspi);
>
> @@ -1187,6 +1188,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
> ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_RX_DUAL | SPI_RX_QUAD |
> SPI_TX_DUAL | SPI_TX_QUAD;
> ctlr->dev.of_node = np;
> + ctlr->auto_runtime_pm = true;
>
> ret = devm_spi_register_controller(&pdev->dev, ctlr);
> if (ret) {
These 2 function
pm_runtime_mark_last_busy(&pdev->dev);
pm_runtime_put_autosuspend(&pdev->dev);
are the last operations in probe function since if they runs,
spi_controller will enter suspend state and disable clks after 3s
passing. So please move them just before "return 0".

And would you please cc me when you send V3? I am preparing to send a patch series
to fix clk and suspend/resume issues which bases on the pm_runtime issue.

Thanks,
Quanyang
> --
> 2.17.1
>

2021-04-15 05:29:20

by Dinghao Liu

[permalink] [raw]
Subject: Re: Re: [PATCH] [v2] spi: spi-zynqmp-gqspi: Fix runtime PM imbalance in zynqmp_qspi_probe

> Hi Dinghao,
> On Mon, Apr 12, 2021 at 03:31:54PM +0800, Dinghao Liu wrote:
> > There is a PM usage counter decrement after zynqmp_qspi_init_hw()
> > without any refcount increment, which leads to refcount leak.Add
> > a refcount increment to balance the refcount. Also set
> > auto_runtime_pm to resume suspended spi controller.
> >
> > Signed-off-by: Dinghao Liu <[email protected]>
> > ---
> > changelog:
> >
> > v2: - Add a refcount increment to fix refcout leak instead of the
> > refcount decrement on error.
> > Set ctlr->auto_runtime_pm = true.
> > ---
> > drivers/spi/spi-zynqmp-gqspi.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c
> > index c8fa6ee18ae7..8b21c7b0e7eb 100644
> > --- a/drivers/spi/spi-zynqmp-gqspi.c
> > +++ b/drivers/spi/spi-zynqmp-gqspi.c
> > @@ -1160,6 +1160,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
> > pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT);
> > pm_runtime_set_active(&pdev->dev);
> > pm_runtime_enable(&pdev->dev);
> > + pm_runtime_get_sync(&pdev->dev);
> Please check the return value here, if ret is "< 0", goto error label,
> and a pm_runtime_put_sync is needed in error label
> > /* QSPI controller initializations */
> > zynqmp_qspi_init_hw(xqspi);
> >
> > @@ -1187,6 +1188,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
> > ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_RX_DUAL | SPI_RX_QUAD |
> > SPI_TX_DUAL | SPI_TX_QUAD;
> > ctlr->dev.of_node = np;
> > + ctlr->auto_runtime_pm = true;
> >
> > ret = devm_spi_register_controller(&pdev->dev, ctlr);
> > if (ret) {
> These 2 function
> pm_runtime_mark_last_busy(&pdev->dev);
> pm_runtime_put_autosuspend(&pdev->dev);
> are the last operations in probe function since if they runs,
> spi_controller will enter suspend state and disable clks after 3s
> passing. So please move them just before "return 0".
>
> And would you please cc me when you send V3? I am preparing to send a patch series
> to fix clk and suspend/resume issues which bases on the pm_runtime issue.
>

Thanks for your advice and I will send a new patch soon.

Regards,
Dinghao