diff mbox series

memory: mtk-smi: Fix PM usage counter unbalance in mtk_smi ops

Message ID 20201123102118.3866195-1-zhangqilong3@huawei.com (mailing list archive)
State New
Headers show
Series memory: mtk-smi: Fix PM usage counter unbalance in mtk_smi ops | expand

Commit Message

Zhang Qilong Nov. 23, 2020, 10:21 a.m. UTC
pm_runtime_get_sync will increment pm usage counter
even it failed. Forgetting to putting operation will
result in reference leak here. We fix it by replacing
it with pm_runtime_resume_and_get to keep usage counter
balanced.

Fixes: 4f0a1a1ae3519 ("memory: mtk-smi: Invoke pm runtime_callback to enable clocks")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
---
 drivers/memory/mtk-smi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Krzysztof Kozlowski Nov. 25, 2020, 6:32 p.m. UTC | #1
On Mon, Nov 23, 2020 at 06:21:18PM +0800, Zhang Qilong wrote:
> pm_runtime_get_sync will increment pm usage counter
> even it failed. Forgetting to putting operation will
> result in reference leak here. We fix it by replacing
> it with pm_runtime_resume_and_get to keep usage counter
> balanced.
> 
> Fixes: 4f0a1a1ae3519 ("memory: mtk-smi: Invoke pm runtime_callback to enable clocks")
> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> ---
>  drivers/memory/mtk-smi.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c
> index ac350f8d1e20..82d09b88240e 100644
> --- a/drivers/memory/mtk-smi.c
> +++ b/drivers/memory/mtk-smi.c
> @@ -130,7 +130,7 @@ static void mtk_smi_clk_disable(const struct mtk_smi *smi)
>  
>  int mtk_smi_larb_get(struct device *larbdev)
>  {
> -	int ret = pm_runtime_get_sync(larbdev);
> +	int ret = pm_runtime_resume_and_get(larbdev);

Thanks for the patch, but it cannot be applied.

There is no pm_runtime_resume_and_get() in v5.10-rc1. I see you authored it
around middle of November, so don't expect that it gets magically to all
other trees. In such case - when you know that your patch cannot be
applied or you suspect any dependencies, you should describe
requirements for the patch.

Best regards,
Krzysztof
Zhang Qilong Nov. 26, 2020, 1:20 a.m. UTC | #2
> 
> On Mon, Nov 23, 2020 at 06:21:18PM +0800, Zhang Qilong wrote:
> > pm_runtime_get_sync will increment pm usage counter even it failed.
> > Forgetting to putting operation will result in reference leak here. We
> > fix it by replacing it with pm_runtime_resume_and_get to keep usage
> > counter balanced.
> >
> > Fixes: 4f0a1a1ae3519 ("memory: mtk-smi: Invoke pm runtime_callback to
> > enable clocks")
> > Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> > ---
> >  drivers/memory/mtk-smi.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c index
> > ac350f8d1e20..82d09b88240e 100644
> > --- a/drivers/memory/mtk-smi.c
> > +++ b/drivers/memory/mtk-smi.c
> > @@ -130,7 +130,7 @@ static void mtk_smi_clk_disable(const struct
> > mtk_smi *smi)
> >
> >  int mtk_smi_larb_get(struct device *larbdev)  {
> > -	int ret = pm_runtime_get_sync(larbdev);
> > +	int ret = pm_runtime_resume_and_get(larbdev);
> 
> Thanks for the patch, but it cannot be applied.
> 
> There is no pm_runtime_resume_and_get() in v5.10-rc1. I see you authored it
> around middle of November, so don't expect that it gets magically to all other
> trees. In such case - when you know that your patch cannot be applied or you
> suspect any dependencies, you should describe requirements for the patch.

OK, I get it. 

Best regards,
Zhang

> 
> Best regards,
> Krzysztof
Krzysztof Kozlowski Jan. 3, 2021, 4:32 p.m. UTC | #3
On Mon, Nov 23, 2020 at 06:21:18PM +0800, Zhang Qilong wrote:
> pm_runtime_get_sync will increment pm usage counter
> even it failed. Forgetting to putting operation will
> result in reference leak here. We fix it by replacing
> it with pm_runtime_resume_and_get to keep usage counter
> balanced.
> 
> Fixes: 4f0a1a1ae3519 ("memory: mtk-smi: Invoke pm runtime_callback to enable clocks")
> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> ---
>  drivers/memory/mtk-smi.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Thanks, applied.

Best regards,
Krzysztof
diff mbox series

Patch

diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c
index ac350f8d1e20..82d09b88240e 100644
--- a/drivers/memory/mtk-smi.c
+++ b/drivers/memory/mtk-smi.c
@@ -130,7 +130,7 @@  static void mtk_smi_clk_disable(const struct mtk_smi *smi)
 
 int mtk_smi_larb_get(struct device *larbdev)
 {
-	int ret = pm_runtime_get_sync(larbdev);
+	int ret = pm_runtime_resume_and_get(larbdev);
 
 	return (ret < 0) ? ret : 0;
 }
@@ -374,7 +374,7 @@  static int __maybe_unused mtk_smi_larb_resume(struct device *dev)
 	int ret;
 
 	/* Power on smi-common. */
-	ret = pm_runtime_get_sync(larb->smi_common_dev);
+	ret = pm_runtime_resume_and_get(larb->smi_common_dev);
 	if (ret < 0) {
 		dev_err(dev, "Failed to pm get for smi-common(%d).\n", ret);
 		return ret;