Linux-Hwmon Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] hwmon: (ina3221) Fix reference count leak in ina3221_write_enable
@ 2020-06-14  3:38 Aditya Pakki
  2020-06-14  9:38 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Aditya Pakki @ 2020-06-14  3:38 UTC (permalink / raw)
  To: pakki001
  Cc: kjlu, wu000273, Jean Delvare, Guenter Roeck, linux-hwmon, linux-kernel

ina3221_write_enable() calls pm_runtime_get_sync() that increments
the reference counter. In case of failure, decrement the reference
count and return the error.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
---
 drivers/hwmon/ina3221.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
index f335d0cb0c77..9a3b46160de1 100644
--- a/drivers/hwmon/ina3221.c
+++ b/drivers/hwmon/ina3221.c
@@ -492,6 +492,7 @@ static int ina3221_write_enable(struct device *dev, int channel, bool enable)
 		ret = pm_runtime_get_sync(ina->pm_dev);
 		if (ret < 0) {
 			dev_err(dev, "Failed to get PM runtime\n");
+			pm_runtime_put_sync(ina->pm_dev);
 			return ret;
 		}
 	}
-- 
2.25.1


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

* Re: [PATCH] hwmon: (ina3221) Fix reference count leak in ina3221_write_enable
  2020-06-14  3:38 [PATCH] hwmon: (ina3221) Fix reference count leak in ina3221_write_enable Aditya Pakki
@ 2020-06-14  9:38 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2020-06-14  9:38 UTC (permalink / raw)
  To: Aditya Pakki; +Cc: kjlu, wu000273, Jean Delvare, linux-hwmon, linux-kernel

On 6/13/20 8:38 PM, Aditya Pakki wrote:
> ina3221_write_enable() calls pm_runtime_get_sync() that increments
> the reference counter. In case of failure, decrement the reference
> count and return the error.
> 
> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> ---
>  drivers/hwmon/ina3221.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
> index f335d0cb0c77..9a3b46160de1 100644
> --- a/drivers/hwmon/ina3221.c
> +++ b/drivers/hwmon/ina3221.c
> @@ -492,6 +492,7 @@ static int ina3221_write_enable(struct device *dev, int channel, bool enable)
>  		ret = pm_runtime_get_sync(ina->pm_dev);
>  		if (ret < 0) {
>  			dev_err(dev, "Failed to get PM runtime\n");
> +			pm_runtime_put_sync(ina->pm_dev);
>  			return ret;
>  		}
>  	}
> 

Looking into other code handling this error, a call to pm_runtime_put_noidle()
may be more appropriate in this situation.

Guenter

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-14  3:38 [PATCH] hwmon: (ina3221) Fix reference count leak in ina3221_write_enable Aditya Pakki
2020-06-14  9:38 ` Guenter Roeck

Linux-Hwmon Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-hwmon/0 linux-hwmon/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-hwmon linux-hwmon/ https://lore.kernel.org/linux-hwmon \
		linux-hwmon@vger.kernel.org
	public-inbox-index linux-hwmon

Example config snippet for mirrors

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


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