lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20150224043350.4243.92949.stgit@notabene.brown>
Date:	Tue, 24 Feb 2015 15:33:50 +1100
From:	NeilBrown <neilb@...e.de>
To:	Samuel Ortiz <sameo@...ux.intel.com>,
	Tony Lindgren <tony@...mide.com>,
	Lee Jones <lee.jones@...aro.org>,
	Sebastian Reichel <sre@...nel.org>,
	Dmitry Eremin-Solenikov <dbaryshkov@...il.com>,
	David Woodhouse <dwmw2@...radead.org>
Cc:	GTA04 owners <gta04-owner@...delico.com>,
	linux-omap@...r.kernel.org, linux-kernel@...r.kernel.org,
	linux-pm@...r.kernel.org
Subject: [PATCH 01/15] power_supply core: support use of devres to
 register/unregister a power supply.

Using devm_power_supply_register allows the unregister to happen
automatically on error or final put.

Signed-off-by: NeilBrown <neilb@...e.de>
---
 drivers/power/power_supply_core.c |   45 +++++++++++++++++++++++++++++++++++++
 include/linux/power_supply.h      |    4 +++
 2 files changed, 49 insertions(+)

diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index 694e8cddd5c1..44c810456212 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -617,6 +617,51 @@ int power_supply_register_no_ws(struct device *parent, struct power_supply *psy)
 }
 EXPORT_SYMBOL_GPL(power_supply_register_no_ws);
 
+static void devm_power_supply_release(struct device *dev, void *res)
+{
+	struct power_supply **psy = res;
+
+	power_supply_unregister(*psy);
+}
+
+int devm_power_supply_register(struct device *parent, struct power_supply *psy)
+{
+	struct power_supply **ptr = devres_alloc(devm_power_supply_release,
+						 sizeof(*ptr), GFP_KERNEL);
+	int ret;
+
+	if (!ptr)
+		return -ENOMEM;
+	ret = __power_supply_register(parent, psy, true);
+	if (ret < 0)
+		devres_free(ptr);
+	else {
+		*ptr = psy;
+		devres_add(parent, ptr);
+	}
+	return ret;
+}
+EXPORT_SYMBOL_GPL(devm_power_supply_register);
+
+int devm_power_supply_register_no_ws(struct device *parent, struct power_supply *psy)
+{
+	struct power_supply **ptr = devres_alloc(devm_power_supply_release,
+						 sizeof(*ptr), GFP_KERNEL);
+	int ret;
+
+	if (!ptr)
+		return -ENOMEM;
+	ret = __power_supply_register(parent, psy, false);
+	if (ret < 0)
+		devres_free(ptr);
+	else {
+		*ptr = psy;
+		devres_add(parent, ptr);
+	}
+	return ret;
+}
+EXPORT_SYMBOL_GPL(devm_power_supply_register_no_ws);
+
 void power_supply_unregister(struct power_supply *psy)
 {
 	cancel_work_sync(&psy->changed_work);
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 096dbced02ac..f606d6b4bd56 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -278,6 +278,10 @@ extern int power_supply_register(struct device *parent,
 				 struct power_supply *psy);
 extern int power_supply_register_no_ws(struct device *parent,
 				 struct power_supply *psy);
+extern int devm_power_supply_register(struct device *parent,
+				 struct power_supply *psy);
+extern int devm_power_supply_register_no_ws(struct device *parent,
+				 struct power_supply *psy);
 extern void power_supply_unregister(struct power_supply *psy);
 extern int power_supply_powers(struct power_supply *psy, struct device *dev);
 


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ