diff mbox series

hwmon: (ina3221) Fix PM usage counter unbalance in ina3221_write_enable

Message ID 20201123102000.3864999-1-zhangqilong3@huawei.com (mailing list archive)
State Changes Requested
Headers show
Series hwmon: (ina3221) Fix PM usage counter unbalance in ina3221_write_enable | expand

Commit Message

Zhang Qilong Nov. 23, 2020, 10:20 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: 323aeb0eb5d9a ("hwmon: (ina3221) Add PM runtime support")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
---
 drivers/hwmon/ina3221.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Guenter Roeck Nov. 25, 2020, 2:41 p.m. UTC | #1
On Mon, Nov 23, 2020 at 06:20:00PM +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: 323aeb0eb5d9a ("hwmon: (ina3221) Add PM runtime support")
> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/ina3221.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
> index 72cfdc007e60..d80bd3efcd6d 100644
> --- a/drivers/hwmon/ina3221.c
> +++ b/drivers/hwmon/ina3221.c
> @@ -489,7 +489,7 @@ static int ina3221_write_enable(struct device *dev, int channel, bool enable)
>  
>  	/* For enabling routine, increase refcount and resume() at first */
>  	if (enable) {
> -		ret = pm_runtime_get_sync(ina->pm_dev);
> +		ret = pm_runtime_resume_and_get(ina->pm_dev);
>  		if (ret < 0) {
>  			dev_err(dev, "Failed to get PM runtime\n");
>  			return ret;
Guenter Roeck Nov. 29, 2020, 3:04 a.m. UTC | #2
On Mon, Nov 23, 2020 at 06:20:00PM +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.
> 
Turns out this function doesn't exist in the mainline kernel,
meaning it can not be used to fix a patch in the mainline kernel.
I dropped this patch from my queue.

Guenter

> Fixes: 323aeb0eb5d9a ("hwmon: (ina3221) Add PM runtime support")
> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> ---
>  drivers/hwmon/ina3221.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
> index 72cfdc007e60..d80bd3efcd6d 100644
> --- a/drivers/hwmon/ina3221.c
> +++ b/drivers/hwmon/ina3221.c
> @@ -489,7 +489,7 @@ static int ina3221_write_enable(struct device *dev, int channel, bool enable)
>  
>  	/* For enabling routine, increase refcount and resume() at first */
>  	if (enable) {
> -		ret = pm_runtime_get_sync(ina->pm_dev);
> +		ret = pm_runtime_resume_and_get(ina->pm_dev);
>  		if (ret < 0) {
>  			dev_err(dev, "Failed to get PM runtime\n");
>  			return ret;
Zhang Qilong Dec. 2, 2020, 2:27 p.m. UTC | #3
HI,

> 
> On Mon, Nov 23, 2020 at 06:20:00PM +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.
> >
> Turns out this function doesn't exist in the mainline kernel, meaning it can not
> be used to fix a patch in the mainline kernel.
> I dropped this patch from my queue.
> 

I am sorry ,I forgot to add the dependency, the commit is as flowing:

	https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v5.10-rc6&id=dd8088d5a8969dc2b42f71d7bc01c25c61a78066

I will update the description next version.

Best regards,
Zhang Qilong  

> Guenter
> 
> > Fixes: 323aeb0eb5d9a ("hwmon: (ina3221) Add PM runtime support")
> > Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> > ---
> >  drivers/hwmon/ina3221.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c index
> > 72cfdc007e60..d80bd3efcd6d 100644
> > --- a/drivers/hwmon/ina3221.c
> > +++ b/drivers/hwmon/ina3221.c
> > @@ -489,7 +489,7 @@ static int ina3221_write_enable(struct device
> > *dev, int channel, bool enable)
> >
> >  	/* For enabling routine, increase refcount and resume() at first */
> >  	if (enable) {
> > -		ret = pm_runtime_get_sync(ina->pm_dev);
> > +		ret = pm_runtime_resume_and_get(ina->pm_dev);
> >  		if (ret < 0) {
> >  			dev_err(dev, "Failed to get PM runtime\n");
> >  			return ret;
diff mbox series

Patch

diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
index 72cfdc007e60..d80bd3efcd6d 100644
--- a/drivers/hwmon/ina3221.c
+++ b/drivers/hwmon/ina3221.c
@@ -489,7 +489,7 @@  static int ina3221_write_enable(struct device *dev, int channel, bool enable)
 
 	/* For enabling routine, increase refcount and resume() at first */
 	if (enable) {
-		ret = pm_runtime_get_sync(ina->pm_dev);
+		ret = pm_runtime_resume_and_get(ina->pm_dev);
 		if (ret < 0) {
 			dev_err(dev, "Failed to get PM runtime\n");
 			return ret;