linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND v2 0/7] power_supply: Decrement the device reference counter
@ 2014-11-04 15:10 Krzysztof Kozlowski
  2014-11-04 15:10 ` [PATCH RESEND v2 1/7] power_supply: Add power_supply_put for decrementing " Krzysztof Kozlowski
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2014-11-04 15:10 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, Linus Walleij,
	Samuel Ortiz, Lee Jones, Sebastian Reichel,
	Dmitry Eremin-Solenikov, David Woodhouse, Konrad Rzeszutek Wilk,
	Rafael J. Wysocki, Lv Zheng, Bjorn Helgaas, linux-kernel,
	linux-arm-kernel, linux-pm
  Cc: Anton Vorontsov, Pavel Machek, Kyungmin Park, Marek Szyprowski,
	Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski

Hi,


Resending with some new acks.
Whole patchset should be taken at once (everything depends on patch 1).
Depends on [1].


Changes since v1:
=================
1. Remove check for non-NULL in power_supply_put (suggested by
   Pavel Machek).
2. Add Pavel Machek's ack.


Description:
============
The reference counter of device allocated for power supply was
incremented with each call to power_supply_get_by_name() and
power_supply_get_by_phandle().

Add a symmetric 'put' operation so the device could be released after
final put_device() call during supply unregistering.


Rebased on next-20141104 + mine [1] patchset.
Tested on Trats2 board (max77693 + charger manager).

Kindly asking for reviewing and testing other drivers.

Best regards,
Krzysztof


[1] power_supply: Add API for safe access of get_property-like function attrs
https://lkml.org/lkml/2014/11/4/527


Krzysztof Kozlowski (7):
  power_supply: Add power_supply_put for decrementing device reference
    counter
  power: charger-manager: Decrement the power supply's device reference
    counter
  x86/olpc/xo1/sci: Use newly added power_supply_put API
  x86/olpc/xo15/sci: Use newly added power_supply_put API
  power: 88pm860x_charger: Decrement the power supply's device reference
    counter
  power: bq2415x_charger: Decrement the power supply's device reference
    counter
  mfd: ab8500: Decrement the power supply's device reference counter

 arch/x86/platform/olpc/olpc-xo1-sci.c  |  4 +-
 arch/x86/platform/olpc/olpc-xo15-sci.c |  4 +-
 drivers/mfd/ab8500-sysctrl.c           |  2 +
 drivers/power/88pm860x_charger.c       | 11 +++++-
 drivers/power/bq2415x_charger.c        |  6 ++-
 drivers/power/charger-manager.c        | 70 +++++++++++++++++++++++-----------
 drivers/power/power_supply_core.c      | 38 ++++++++++++++++++
 include/linux/power_supply.h           |  1 +
 8 files changed, 106 insertions(+), 30 deletions(-)

-- 
1.9.1


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

* [PATCH RESEND v2 1/7] power_supply: Add power_supply_put for decrementing device reference counter
  2014-11-04 15:10 [PATCH RESEND v2 0/7] power_supply: Decrement the device reference counter Krzysztof Kozlowski
@ 2014-11-04 15:10 ` Krzysztof Kozlowski
  2014-11-04 15:10 ` [PATCH RESEND v2 2/7] power: charger-manager: Decrement the power supply's " Krzysztof Kozlowski
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2014-11-04 15:10 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, Linus Walleij,
	Samuel Ortiz, Lee Jones, Sebastian Reichel,
	Dmitry Eremin-Solenikov, David Woodhouse, Konrad Rzeszutek Wilk,
	Rafael J. Wysocki, Lv Zheng, Bjorn Helgaas, linux-kernel,
	linux-arm-kernel, linux-pm
  Cc: Anton Vorontsov, Pavel Machek, Kyungmin Park, Marek Szyprowski,
	Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski

The power_supply_get_by_phandle() and power_supply_get_by_name() use
function class_find_device() for obtaining the reference to power
supply. Each use of class_find_device() increases the power supply's
device reference counter.

However the reference counter was not decreased by users of this API.
Thus final device_unregister() call from power_supply_unregister() could
not release the device and clean up its resources. This lead to memory
leak if at least once power_supply_get_by_*() was called between
registering and unregistering the power supply.

Add and document new API power_supply_put() for decrementing the
reference counter.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Acked-by: Pavel Machek <pavel@ucw.cz>
---
 drivers/power/power_supply_core.c | 38 ++++++++++++++++++++++++++++++++++++++
 include/linux/power_supply.h      |  1 +
 2 files changed, 39 insertions(+)

diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index bd8f5be0d976..cf860d2fd8c9 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -331,6 +331,17 @@ static int power_supply_match_device_by_name(struct device *dev, const void *dat
 	return strcmp(psy->name, name) == 0;
 }
 
+/**
+ * power_supply_get_by_name() - Search for a power supply and returns its ref
+ * @name: Power supply name to fetch
+ *
+ * If power supply was found, it increases reference count for the
+ * internal power supply's device. The user should power_supply_put()
+ * after usage.
+ *
+ * Return: On success returns a reference to a power supply with
+ * matching name equals to @name, a NULL otherwise.
+ */
 struct power_supply *power_supply_get_by_name(const char *name)
 {
 	struct device *dev = class_find_device(power_supply_class, NULL, name,
@@ -340,12 +351,39 @@ struct power_supply *power_supply_get_by_name(const char *name)
 }
 EXPORT_SYMBOL_GPL(power_supply_get_by_name);
 
+/**
+ * power_supply_put() - Drop reference obtained with power_supply_get_by_name
+ * @psy: Reference to put
+ *
+ * The reference to power supply should be put before unregistering
+ * the power supply.
+ */
+void power_supply_put(struct power_supply *psy)
+{
+	might_sleep();
+
+	put_device(psy->dev);
+}
+EXPORT_SYMBOL_GPL(power_supply_put);
+
 #ifdef CONFIG_OF
 static int power_supply_match_device_node(struct device *dev, const void *data)
 {
 	return dev->parent && dev->parent->of_node == data;
 }
 
+/**
+ * power_supply_get_by_phandle() - Search for a power supply and returns its ref
+ * @np: Pointer to device node holding phandle property
+ * @phandle_name: Name of property holding a power supply name
+ *
+ * If power supply was found, it increases reference count for the
+ * internal power supply's device. The user should power_supply_put()
+ * after usage.
+ *
+ * Return: On success returns a reference to a power supply with
+ * matching name equals to value under @property, NULL or ERR_PTR otherwise.
+ */
 struct power_supply *power_supply_get_by_phandle(struct device_node *np,
 							const char *property)
 {
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 0ef515301aaf..9abb2aef55eb 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -262,6 +262,7 @@ extern struct atomic_notifier_head power_supply_notifier;
 extern int power_supply_reg_notifier(struct notifier_block *nb);
 extern void power_supply_unreg_notifier(struct notifier_block *nb);
 extern struct power_supply *power_supply_get_by_name(const char *name);
+extern void power_supply_put(struct power_supply *psy);
 #ifdef CONFIG_OF
 extern struct power_supply *power_supply_get_by_phandle(struct device_node *np,
 							const char *property);
-- 
1.9.1


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

* [PATCH RESEND v2 2/7] power: charger-manager: Decrement the power supply's device reference counter
  2014-11-04 15:10 [PATCH RESEND v2 0/7] power_supply: Decrement the device reference counter Krzysztof Kozlowski
  2014-11-04 15:10 ` [PATCH RESEND v2 1/7] power_supply: Add power_supply_put for decrementing " Krzysztof Kozlowski
@ 2014-11-04 15:10 ` Krzysztof Kozlowski
  2014-11-04 15:10 ` [PATCH RESEND v2 3/7] x86/olpc/xo1/sci: Use newly added power_supply_put API Krzysztof Kozlowski
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2014-11-04 15:10 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, Linus Walleij,
	Samuel Ortiz, Lee Jones, Sebastian Reichel,
	Dmitry Eremin-Solenikov, David Woodhouse, Konrad Rzeszutek Wilk,
	Rafael J. Wysocki, Lv Zheng, Bjorn Helgaas, linux-kernel,
	linux-arm-kernel, linux-pm
  Cc: Anton Vorontsov, Pavel Machek, Kyungmin Park, Marek Szyprowski,
	Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski

Use power_supply_put() to decrement the power supply's device reference
counter.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Acked-by: Pavel Machek <pavel@ucw.cz>
---
 drivers/power/charger-manager.c | 70 +++++++++++++++++++++++++++--------------
 1 file changed, 47 insertions(+), 23 deletions(-)

diff --git a/drivers/power/charger-manager.c b/drivers/power/charger-manager.c
index c4ca346dcd50..7455ac95ecbc 100644
--- a/drivers/power/charger-manager.c
+++ b/drivers/power/charger-manager.c
@@ -116,6 +116,7 @@ static bool is_batt_present(struct charger_manager *cm)
 				&val);
 		if (ret == 0 && val.intval)
 			present = true;
+		power_supply_put(psy);
 		break;
 	case CM_CHARGER_STAT:
 		for (i = 0; cm->desc->psy_charger_stat[i]; i++) {
@@ -129,6 +130,7 @@ static bool is_batt_present(struct charger_manager *cm)
 
 			ret = power_supply_get_property(psy,
 				POWER_SUPPLY_PROP_PRESENT, &val);
+			power_supply_put(psy);
 			if (ret == 0 && val.intval) {
 				present = true;
 				break;
@@ -166,6 +168,7 @@ static bool is_ext_pwr_online(struct charger_manager *cm)
 
 		ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_ONLINE,
 				&val);
+		power_supply_put(psy);
 		if (ret == 0 && val.intval) {
 			online = true;
 			break;
@@ -195,6 +198,7 @@ static int get_batt_uV(struct charger_manager *cm, int *uV)
 
 	ret = power_supply_get_property(fuel_gauge,
 				POWER_SUPPLY_PROP_VOLTAGE_NOW, &val);
+	power_supply_put(fuel_gauge);
 	if (ret)
 		return ret;
 
@@ -238,10 +242,13 @@ static bool is_charging(struct charger_manager *cm)
 		if (ret) {
 			dev_warn(cm->dev, "Cannot read ONLINE value from %s\n",
 				 cm->desc->psy_charger_stat[i]);
+			power_supply_put(psy);
 			continue;
 		}
-		if (val.intval == 0)
+		if (val.intval == 0) {
+			power_supply_put(psy);
 			continue;
+		}
 
 		/*
 		 * 3. The charger should not be FULL, DISCHARGING,
@@ -249,6 +256,7 @@ static bool is_charging(struct charger_manager *cm)
 		 */
 		ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_STATUS,
 				&val);
+		power_supply_put(psy);
 		if (ret) {
 			dev_warn(cm->dev, "Cannot read STATUS value from %s\n",
 				 cm->desc->psy_charger_stat[i]);
@@ -276,6 +284,7 @@ static bool is_full_charged(struct charger_manager *cm)
 	struct charger_desc *desc = cm->desc;
 	union power_supply_propval val;
 	struct power_supply *fuel_gauge;
+	bool is_full = false;
 	int ret = 0;
 	int uV;
 
@@ -293,15 +302,19 @@ static bool is_full_charged(struct charger_manager *cm)
 		/* Not full if capacity of fuel gauge isn't full */
 		ret = power_supply_get_property(fuel_gauge,
 				POWER_SUPPLY_PROP_CHARGE_FULL, &val);
-		if (!ret && val.intval > desc->fullbatt_full_capacity)
-			return true;
+		if (!ret && val.intval > desc->fullbatt_full_capacity) {
+			is_full = true;
+			goto out;
+		}
 	}
 
 	/* Full, if it's over the fullbatt voltage */
 	if (desc->fullbatt_uV > 0) {
 		ret = get_batt_uV(cm, &uV);
-		if (!ret && uV >= desc->fullbatt_uV)
-			return true;
+		if (!ret && uV >= desc->fullbatt_uV) {
+			is_full = true;
+			goto out;
+		}
 	}
 
 	/* Full, if the capacity is more than fullbatt_soc */
@@ -310,11 +323,15 @@ static bool is_full_charged(struct charger_manager *cm)
 
 		ret = power_supply_get_property(fuel_gauge,
 				POWER_SUPPLY_PROP_CAPACITY, &val);
-		if (!ret && val.intval >= desc->fullbatt_soc)
-			return true;
+		if (!ret && val.intval >= desc->fullbatt_soc) {
+			is_full = true;
+			goto out;
+		}
 	}
 
-	return false;
+out:
+	power_supply_put(fuel_gauge);
+	return is_full;
 }
 
 /**
@@ -587,14 +604,18 @@ static int cm_get_battery_temperature_by_psy(struct charger_manager *cm,
 					int *temp)
 {
 	struct power_supply *fuel_gauge;
+	int ret;
 
 	fuel_gauge = power_supply_get_by_name(cm->desc->psy_fuel_gauge);
 	if (!fuel_gauge)
 		return -ENODEV;
 
-	return power_supply_get_property(fuel_gauge,
+	ret = power_supply_get_property(fuel_gauge,
 				POWER_SUPPLY_PROP_TEMP,
 				(union power_supply_propval *)temp);
+	power_supply_put(fuel_gauge);
+
+	return ret;
 }
 
 static int cm_get_battery_temperature(struct charger_manager *cm,
@@ -876,7 +897,7 @@ static int charger_get_property(struct power_supply *psy,
 	struct charger_manager *cm = container_of(psy,
 			struct charger_manager, charger_psy);
 	struct charger_desc *desc = cm->desc;
-	struct power_supply *fuel_gauge;
+	struct power_supply *fuel_gauge = NULL;
 	int ret = 0;
 	int uV;
 
@@ -919,18 +940,18 @@ static int charger_get_property(struct power_supply *psy,
 	case POWER_SUPPLY_PROP_TEMP_AMBIENT:
 		return cm_get_battery_temperature(cm, &val->intval);
 	case POWER_SUPPLY_PROP_CAPACITY:
-		fuel_gauge = power_supply_get_by_name(cm->desc->psy_fuel_gauge);
-		if (!fuel_gauge) {
-			ret = -ENODEV;
-			break;
-		}
-
 		if (!is_batt_present(cm)) {
 			/* There is no battery. Assume 100% */
 			val->intval = 100;
 			break;
 		}
 
+		fuel_gauge = power_supply_get_by_name(cm->desc->psy_fuel_gauge);
+		if (!fuel_gauge) {
+			ret = -ENODEV;
+			break;
+		}
+
 		ret = power_supply_get_property(fuel_gauge,
 					POWER_SUPPLY_PROP_CAPACITY, val);
 		if (ret)
@@ -1005,6 +1026,8 @@ static int charger_get_property(struct power_supply *psy,
 	default:
 		return -EINVAL;
 	}
+	if (fuel_gauge)
+		power_supply_put(fuel_gauge);
 	return ret;
 }
 
@@ -1803,13 +1826,7 @@ static int charger_manager_probe(struct platform_device *pdev)
 				desc->psy_charger_stat[i]);
 			return -ENODEV;
 		}
-	}
-
-	fuel_gauge = power_supply_get_by_name(desc->psy_fuel_gauge);
-	if (!fuel_gauge) {
-		dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n",
-			desc->psy_fuel_gauge);
-		return -ENODEV;
+		power_supply_put(psy);
 	}
 
 	if (desc->polling_interval_ms == 0 ||
@@ -1849,6 +1866,12 @@ static int charger_manager_probe(struct platform_device *pdev)
 	cm->charger_psy.num_properties = psy_default.num_properties;
 
 	/* Find which optional psy-properties are available */
+	fuel_gauge = power_supply_get_by_name(desc->psy_fuel_gauge);
+	if (!fuel_gauge) {
+		dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n",
+			desc->psy_fuel_gauge);
+		return -ENODEV;
+	}
 	if (!power_supply_get_property(fuel_gauge,
 					  POWER_SUPPLY_PROP_CHARGE_NOW, &val)) {
 		cm->charger_psy.properties[cm->charger_psy.num_properties] =
@@ -1868,6 +1891,7 @@ static int charger_manager_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "Failed to initialize thermal data\n");
 		cm->desc->measure_battery_temp = false;
 	}
+	power_supply_put(fuel_gauge);
 
 	INIT_DELAYED_WORK(&cm->fullbatt_vchk_work, fullbatt_vchk);
 
-- 
1.9.1


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

* [PATCH RESEND v2 3/7] x86/olpc/xo1/sci: Use newly added power_supply_put API
  2014-11-04 15:10 [PATCH RESEND v2 0/7] power_supply: Decrement the device reference counter Krzysztof Kozlowski
  2014-11-04 15:10 ` [PATCH RESEND v2 1/7] power_supply: Add power_supply_put for decrementing " Krzysztof Kozlowski
  2014-11-04 15:10 ` [PATCH RESEND v2 2/7] power: charger-manager: Decrement the power supply's " Krzysztof Kozlowski
@ 2014-11-04 15:10 ` Krzysztof Kozlowski
  2014-11-04 15:10 ` [PATCH RESEND v2 4/7] x86/olpc/xo15/sci: " Krzysztof Kozlowski
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2014-11-04 15:10 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, Linus Walleij,
	Samuel Ortiz, Lee Jones, Sebastian Reichel,
	Dmitry Eremin-Solenikov, David Woodhouse, Konrad Rzeszutek Wilk,
	Rafael J. Wysocki, Lv Zheng, Bjorn Helgaas, linux-kernel,
	linux-arm-kernel, linux-pm
  Cc: Anton Vorontsov, Pavel Machek, Kyungmin Park, Marek Szyprowski,
	Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski

Replace direct usage of put_device() with new API: power_supply_put().

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Acked-by: Pavel Machek <pavel@ucw.cz>
---
 arch/x86/platform/olpc/olpc-xo1-sci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/platform/olpc/olpc-xo1-sci.c b/arch/x86/platform/olpc/olpc-xo1-sci.c
index 9a2e590dd202..7fa8b3b53bc0 100644
--- a/arch/x86/platform/olpc/olpc-xo1-sci.c
+++ b/arch/x86/platform/olpc/olpc-xo1-sci.c
@@ -61,7 +61,7 @@ static void battery_status_changed(void)
 
 	if (psy) {
 		power_supply_changed(psy);
-		put_device(psy->dev);
+		power_supply_put(psy);
 	}
 }
 
@@ -71,7 +71,7 @@ static void ac_status_changed(void)
 
 	if (psy) {
 		power_supply_changed(psy);
-		put_device(psy->dev);
+		power_supply_put(psy);
 	}
 }
 
-- 
1.9.1


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

* [PATCH RESEND v2 4/7] x86/olpc/xo15/sci: Use newly added power_supply_put API
  2014-11-04 15:10 [PATCH RESEND v2 0/7] power_supply: Decrement the device reference counter Krzysztof Kozlowski
                   ` (2 preceding siblings ...)
  2014-11-04 15:10 ` [PATCH RESEND v2 3/7] x86/olpc/xo1/sci: Use newly added power_supply_put API Krzysztof Kozlowski
@ 2014-11-04 15:10 ` Krzysztof Kozlowski
  2014-11-04 15:10 ` [PATCH RESEND v2 5/7] power: 88pm860x_charger: Decrement the power supply's device reference counter Krzysztof Kozlowski
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2014-11-04 15:10 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, Linus Walleij,
	Samuel Ortiz, Lee Jones, Sebastian Reichel,
	Dmitry Eremin-Solenikov, David Woodhouse, Konrad Rzeszutek Wilk,
	Rafael J. Wysocki, Lv Zheng, Bjorn Helgaas, linux-kernel,
	linux-arm-kernel, linux-pm
  Cc: Anton Vorontsov, Pavel Machek, Kyungmin Park, Marek Szyprowski,
	Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski

Replace direct usage of put_device() with new API: power_supply_put().

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Acked-by: Pavel Machek <pavel@ucw.cz>
---
 arch/x86/platform/olpc/olpc-xo15-sci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/platform/olpc/olpc-xo15-sci.c b/arch/x86/platform/olpc/olpc-xo15-sci.c
index 08e350e757dc..55130846ac87 100644
--- a/arch/x86/platform/olpc/olpc-xo15-sci.c
+++ b/arch/x86/platform/olpc/olpc-xo15-sci.c
@@ -83,7 +83,7 @@ static void battery_status_changed(void)
 
 	if (psy) {
 		power_supply_changed(psy);
-		put_device(psy->dev);
+		power_supply_put(psy);
 	}
 }
 
@@ -93,7 +93,7 @@ static void ac_status_changed(void)
 
 	if (psy) {
 		power_supply_changed(psy);
-		put_device(psy->dev);
+		power_supply_put(psy);
 	}
 }
 
-- 
1.9.1


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

* [PATCH RESEND v2 5/7] power: 88pm860x_charger: Decrement the power supply's device reference counter
  2014-11-04 15:10 [PATCH RESEND v2 0/7] power_supply: Decrement the device reference counter Krzysztof Kozlowski
                   ` (3 preceding siblings ...)
  2014-11-04 15:10 ` [PATCH RESEND v2 4/7] x86/olpc/xo15/sci: " Krzysztof Kozlowski
@ 2014-11-04 15:10 ` Krzysztof Kozlowski
  2014-11-04 15:10 ` [PATCH RESEND v2 6/7] power: bq2415x_charger: " Krzysztof Kozlowski
  2014-11-04 15:10 ` [PATCH RESEND v2 7/7] mfd: ab8500: " Krzysztof Kozlowski
  6 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2014-11-04 15:10 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, Linus Walleij,
	Samuel Ortiz, Lee Jones, Sebastian Reichel,
	Dmitry Eremin-Solenikov, David Woodhouse, Konrad Rzeszutek Wilk,
	Rafael J. Wysocki, Lv Zheng, Bjorn Helgaas, linux-kernel,
	linux-arm-kernel, linux-pm
  Cc: Anton Vorontsov, Pavel Machek, Kyungmin Park, Marek Szyprowski,
	Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski

Use power_supply_put() to decrement the power supply's device reference
counter.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Acked-by: Pavel Machek <pavel@ucw.cz>
---
 drivers/power/88pm860x_charger.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/power/88pm860x_charger.c b/drivers/power/88pm860x_charger.c
index 534b3e2e3487..48aa0d829cb0 100644
--- a/drivers/power/88pm860x_charger.c
+++ b/drivers/power/88pm860x_charger.c
@@ -298,13 +298,18 @@ static int set_charging_fsm(struct pm860x_charger_info *info)
 		return -EINVAL;
 	ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_VOLTAGE_NOW,
 			&data);
-	if (ret)
+	if (ret) {
+		power_supply_put(psy);
 		return ret;
+	}
 	vbatt = data.intval / 1000;
 
 	ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_PRESENT, &data);
-	if (ret)
+	if (ret) {
+		power_supply_put(psy);
 		return ret;
+	}
+	power_supply_put(psy);
 
 	mutex_lock(&info->lock);
 	info->present = data.intval;
@@ -447,6 +452,7 @@ static irqreturn_t pm860x_temp_handler(int irq, void *data)
 
 	set_charging_fsm(info);
 out:
+	power_supply_put(psy);
 	return IRQ_HANDLED;
 }
 
@@ -507,6 +513,7 @@ static irqreturn_t pm860x_done_handler(int irq, void *data)
 
 out:
 	mutex_unlock(&info->lock);
+	power_supply_put(psy);
 	dev_dbg(info->dev, "%s, Allowed: %d\n", __func__, info->allowed);
 	set_charging_fsm(info);
 
-- 
1.9.1


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

* [PATCH RESEND v2 6/7] power: bq2415x_charger: Decrement the power supply's device reference counter
  2014-11-04 15:10 [PATCH RESEND v2 0/7] power_supply: Decrement the device reference counter Krzysztof Kozlowski
                   ` (4 preceding siblings ...)
  2014-11-04 15:10 ` [PATCH RESEND v2 5/7] power: 88pm860x_charger: Decrement the power supply's device reference counter Krzysztof Kozlowski
@ 2014-11-04 15:10 ` Krzysztof Kozlowski
  2014-11-04 15:10 ` [PATCH RESEND v2 7/7] mfd: ab8500: " Krzysztof Kozlowski
  6 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2014-11-04 15:10 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, Linus Walleij,
	Samuel Ortiz, Lee Jones, Sebastian Reichel,
	Dmitry Eremin-Solenikov, David Woodhouse, Konrad Rzeszutek Wilk,
	Rafael J. Wysocki, Lv Zheng, Bjorn Helgaas, linux-kernel,
	linux-arm-kernel, linux-pm
  Cc: Anton Vorontsov, Pavel Machek, Kyungmin Park, Marek Szyprowski,
	Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski

Use power_supply_put() to decrement the power supply's device reference
counter (increased by power_supply_get_by_name() or
power_supply_get_by_phandle()).

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Acked-by: Pavel Machek <pavel@ucw.cz>
---
 drivers/power/bq2415x_charger.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c
index 2f80de0410d9..00809dcdd34e 100644
--- a/drivers/power/bq2415x_charger.c
+++ b/drivers/power/bq2415x_charger.c
@@ -1686,6 +1686,8 @@ error_4:
 error_3:
 	bq2415x_power_supply_exit(bq);
 error_2:
+	if (!IS_ERR(bq->notify_psy))
+		power_supply_put(bq->notify_psy);
 	kfree(name);
 error_1:
 	mutex_lock(&bq2415x_id_mutex);
@@ -1701,8 +1703,10 @@ static int bq2415x_remove(struct i2c_client *client)
 {
 	struct bq2415x_device *bq = i2c_get_clientdata(client);
 
-	if (bq->notify_psy)
+	if (bq->notify_psy) {
 		power_supply_unreg_notifier(&bq->nb);
+		power_supply_put(bq->notify_psy);
+	}
 
 	bq2415x_sysfs_exit(bq);
 	bq2415x_power_supply_exit(bq);
-- 
1.9.1


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

* [PATCH RESEND v2 7/7] mfd: ab8500: Decrement the power supply's device reference counter
  2014-11-04 15:10 [PATCH RESEND v2 0/7] power_supply: Decrement the device reference counter Krzysztof Kozlowski
                   ` (5 preceding siblings ...)
  2014-11-04 15:10 ` [PATCH RESEND v2 6/7] power: bq2415x_charger: " Krzysztof Kozlowski
@ 2014-11-04 15:10 ` Krzysztof Kozlowski
  6 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2014-11-04 15:10 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, Linus Walleij,
	Samuel Ortiz, Lee Jones, Sebastian Reichel,
	Dmitry Eremin-Solenikov, David Woodhouse, Konrad Rzeszutek Wilk,
	Rafael J. Wysocki, Lv Zheng, Bjorn Helgaas, linux-kernel,
	linux-arm-kernel, linux-pm
  Cc: Anton Vorontsov, Pavel Machek, Kyungmin Park, Marek Szyprowski,
	Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski

Use power_supply_put() to decrement the power supply's device reference
counter.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Acked-by: Pavel Machek <pavel@ucw.cz>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/mfd/ab8500-sysctrl.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/mfd/ab8500-sysctrl.c b/drivers/mfd/ab8500-sysctrl.c
index f7f44b34896a..962f32492647 100644
--- a/drivers/mfd/ab8500-sysctrl.c
+++ b/drivers/mfd/ab8500-sysctrl.c
@@ -51,6 +51,7 @@ static void ab8500_power_off(void)
 
 		ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_ONLINE,
 				&val);
+		power_supply_put(psy);
 
 		if (!ret && val.intval) {
 			charger_present = true;
@@ -73,6 +74,7 @@ static void ab8500_power_off(void)
 			       pss[i]);
 			machine_restart("charging");
 		}
+		power_supply_put(psy);
 	}
 
 shutdown:
-- 
1.9.1


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

end of thread, other threads:[~2014-11-04 15:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-04 15:10 [PATCH RESEND v2 0/7] power_supply: Decrement the device reference counter Krzysztof Kozlowski
2014-11-04 15:10 ` [PATCH RESEND v2 1/7] power_supply: Add power_supply_put for decrementing " Krzysztof Kozlowski
2014-11-04 15:10 ` [PATCH RESEND v2 2/7] power: charger-manager: Decrement the power supply's " Krzysztof Kozlowski
2014-11-04 15:10 ` [PATCH RESEND v2 3/7] x86/olpc/xo1/sci: Use newly added power_supply_put API Krzysztof Kozlowski
2014-11-04 15:10 ` [PATCH RESEND v2 4/7] x86/olpc/xo15/sci: " Krzysztof Kozlowski
2014-11-04 15:10 ` [PATCH RESEND v2 5/7] power: 88pm860x_charger: Decrement the power supply's device reference counter Krzysztof Kozlowski
2014-11-04 15:10 ` [PATCH RESEND v2 6/7] power: bq2415x_charger: " Krzysztof Kozlowski
2014-11-04 15:10 ` [PATCH RESEND v2 7/7] mfd: ab8500: " Krzysztof Kozlowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).