Linux-SPI Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] spi: spi-zynqmp-gqspi: Fix runtime PM imbalance in zynqmp_qspi_probe
@ 2021-04-08  9:25 Dinghao Liu
  2021-04-08 10:33 ` Michal Simek
  2021-04-08 16:54 ` Mark Brown
  0 siblings, 2 replies; 5+ messages in thread
From: Dinghao Liu @ 2021-04-08  9:25 UTC (permalink / raw)
  To: dinghao.liu, kjlu
  Cc: Mark Brown, Michal Simek, linux-spi, linux-arm-kernel, linux-kernel

When platform_get_irq() fails, a pairing PM usage counter
increment is needed to keep the counter balanced. It's the
same for the following error paths.

Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
 drivers/spi/spi-zynqmp-gqspi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c
index c8fa6ee18ae7..95963a2de64a 100644
--- a/drivers/spi/spi-zynqmp-gqspi.c
+++ b/drivers/spi/spi-zynqmp-gqspi.c
@@ -1197,6 +1197,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
 	return 0;
 
 clk_dis_all:
+	pm_runtime_get_noresume(&pdev->dev);
 	pm_runtime_set_suspended(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 	clk_disable_unprepare(xqspi->refclk);
-- 
2.17.1


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

* Re: [PATCH] spi: spi-zynqmp-gqspi: Fix runtime PM imbalance in zynqmp_qspi_probe
  2021-04-08  9:25 [PATCH] spi: spi-zynqmp-gqspi: Fix runtime PM imbalance in zynqmp_qspi_probe Dinghao Liu
@ 2021-04-08 10:33 ` Michal Simek
  2021-04-09  1:33   ` quanyang.wang
  2021-04-08 16:54 ` Mark Brown
  1 sibling, 1 reply; 5+ messages in thread
From: Michal Simek @ 2021-04-08 10:33 UTC (permalink / raw)
  To: Dinghao Liu, kjlu, Amit Kumar Mahapatra, Quanyang Wang
  Cc: Mark Brown, Michal Simek, linux-spi, linux-arm-kernel, linux-kernel

++

On 4/8/21 11:25 AM, Dinghao Liu wrote:
> When platform_get_irq() fails, a pairing PM usage counter
> increment is needed to keep the counter balanced. It's the
> same for the following error paths.
> 
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
>  drivers/spi/spi-zynqmp-gqspi.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c
> index c8fa6ee18ae7..95963a2de64a 100644
> --- a/drivers/spi/spi-zynqmp-gqspi.c
> +++ b/drivers/spi/spi-zynqmp-gqspi.c
> @@ -1197,6 +1197,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
>  	return 0;
>  
>  clk_dis_all:
> +	pm_runtime_get_noresume(&pdev->dev);
>  	pm_runtime_set_suspended(&pdev->dev);
>  	pm_runtime_disable(&pdev->dev);
>  	clk_disable_unprepare(xqspi->refclk);
> 

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

* Re: [PATCH] spi: spi-zynqmp-gqspi: Fix runtime PM imbalance in zynqmp_qspi_probe
  2021-04-08  9:25 [PATCH] spi: spi-zynqmp-gqspi: Fix runtime PM imbalance in zynqmp_qspi_probe Dinghao Liu
  2021-04-08 10:33 ` Michal Simek
@ 2021-04-08 16:54 ` Mark Brown
  1 sibling, 0 replies; 5+ messages in thread
From: Mark Brown @ 2021-04-08 16:54 UTC (permalink / raw)
  To: kjlu, Dinghao Liu
  Cc: Mark Brown, linux-spi, linux-kernel, Michal Simek, linux-arm-kernel

On Thu, 8 Apr 2021 17:25:59 +0800, Dinghao Liu wrote:
> When platform_get_irq() fails, a pairing PM usage counter
> increment is needed to keep the counter balanced. It's the
> same for the following error paths.

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/1] spi: spi-zynqmp-gqspi: Fix runtime PM imbalance in zynqmp_qspi_probe
      commit: a21fbc42807b15b74b0891bd557063e6acf4fcae

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

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

* Re: [PATCH] spi: spi-zynqmp-gqspi: Fix runtime PM imbalance in zynqmp_qspi_probe
  2021-04-08 10:33 ` Michal Simek
@ 2021-04-09  1:33   ` quanyang.wang
  2021-04-09  7:53     ` dinghao.liu
  0 siblings, 1 reply; 5+ messages in thread
From: quanyang.wang @ 2021-04-09  1:33 UTC (permalink / raw)
  To: Michal Simek, Dinghao Liu, kjlu, Amit Kumar Mahapatra
  Cc: Mark Brown, linux-spi, linux-arm-kernel, linux-kernel

Hi Dinghao,

On 4/8/21 6:33 PM, Michal Simek wrote:
> ++
>
> On 4/8/21 11:25 AM, Dinghao Liu wrote:
>> When platform_get_irq() fails, a pairing PM usage counter
>> increment is needed to keep the counter balanced. It's the
>> same for the following error paths.
>>
>> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
>> ---
>>   drivers/spi/spi-zynqmp-gqspi.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c
>> index c8fa6ee18ae7..95963a2de64a 100644
>> --- a/drivers/spi/spi-zynqmp-gqspi.c
>> +++ b/drivers/spi/spi-zynqmp-gqspi.c
>> @@ -1197,6 +1197,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
>>   	return 0;
>>   
>>   clk_dis_all:
>> +	pm_runtime_get_noresume(&pdev->dev);
>>   	pm_runtime_set_suspended(&pdev->dev);
>>   	pm_runtime_disable(&pdev->dev);
>>   	clk_disable_unprepare(xqspi->refclk);
>>
The imbalance is because pm_runtime_put_autosuspend is called to make 
counter to be -1.

It looks strange that there is no counter increament op before 
pm_runtime_put_autosuspend.

In my limited understanding, it should look like:

......

pm_runtime_enable

pm_runtime_get_sync   //increase counter to one to resume device

DO OPERATIONS HERE

pm_runtime_mark_last_busy
pm_runtime_put_autosuspend   //decrease counter to zero and trigger suspend

return 0;

error_path:

pm_runtime_put_sync

pm_runtime_disable

return err;


Am I missing something?

Thanks,

Quanyang



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

* Re: Re: [PATCH] spi: spi-zynqmp-gqspi: Fix runtime PM imbalance in zynqmp_qspi_probe
  2021-04-09  1:33   ` quanyang.wang
@ 2021-04-09  7:53     ` dinghao.liu
  0 siblings, 0 replies; 5+ messages in thread
From: dinghao.liu @ 2021-04-09  7:53 UTC (permalink / raw)
  To: quanyang.wang
  Cc: Michal Simek, kjlu, Amit Kumar Mahapatra, Mark Brown, linux-spi,
	linux-arm-kernel, linux-kernel

> Hi Dinghao,
> 
> On 4/8/21 6:33 PM, Michal Simek wrote:
> > ++
> >
> > On 4/8/21 11:25 AM, Dinghao Liu wrote:
> >> When platform_get_irq() fails, a pairing PM usage counter
> >> increment is needed to keep the counter balanced. It's the
> >> same for the following error paths.
> >>
> >> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> >> ---
> >>   drivers/spi/spi-zynqmp-gqspi.c | 1 +
> >>   1 file changed, 1 insertion(+)
> >>
> >> diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c
> >> index c8fa6ee18ae7..95963a2de64a 100644
> >> --- a/drivers/spi/spi-zynqmp-gqspi.c
> >> +++ b/drivers/spi/spi-zynqmp-gqspi.c
> >> @@ -1197,6 +1197,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
> >>   	return 0;
> >>   
> >>   clk_dis_all:
> >> +	pm_runtime_get_noresume(&pdev->dev);
> >>   	pm_runtime_set_suspended(&pdev->dev);
> >>   	pm_runtime_disable(&pdev->dev);
> >>   	clk_disable_unprepare(xqspi->refclk);
> >>
> The imbalance is because pm_runtime_put_autosuspend is called to make 
> counter to be -1.
> 
> It looks strange that there is no counter increament op before 
> pm_runtime_put_autosuspend.
> 
> In my limited understanding, it should look like:
> 
> ......
> 
> pm_runtime_enable
> 
> pm_runtime_get_sync   //increase counter to one to resume device
> 
> DO OPERATIONS HERE
> 
> pm_runtime_mark_last_busy
> pm_runtime_put_autosuspend   //decrease counter to zero and trigger suspend
> 
> return 0;
> 
> error_path:
> 
> pm_runtime_put_sync
> 
> pm_runtime_disable
> 
> return err;
> 
> 
> Am I missing something?
> 

Thanks for point out this! Usually there is an increment refcount in a 
_probe function and a decrement refcount in a _remove function. Sometimes 
the refcount decrement is in the _probe and the increment is in the _remove. 
But the refcount is balanced in both cases. So I think zynqmp_qspi_remove()
needs a refcount increment to fix this bug.

Regards,
Dinghao

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

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-08  9:25 [PATCH] spi: spi-zynqmp-gqspi: Fix runtime PM imbalance in zynqmp_qspi_probe Dinghao Liu
2021-04-08 10:33 ` Michal Simek
2021-04-09  1:33   ` quanyang.wang
2021-04-09  7:53     ` dinghao.liu
2021-04-08 16:54 ` Mark Brown

Linux-SPI Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-spi/0 linux-spi/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-spi linux-spi/ https://lore.kernel.org/linux-spi \
		linux-spi@vger.kernel.org
	public-inbox-index linux-spi

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-spi


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git