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>] [day] [month] [year] [list]
Date:	Fri, 11 Sep 2015 17:32:04 +0530
From:	Viresh Kumar <viresh.kumar@...aro.org>
To:	Rafael Wysocki <rjw@...ysocki.net>, nm@...com, sboyd@...eaurora.org
Cc:	linaro-kernel@...ts.linaro.org, linux-pm@...r.kernel.org,
	rob.herring@...aro.org, lee.jones@...aro.org,
	Viresh Kumar <viresh.kumar@...aro.org>,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@...sung.com>,
	Dmitry Torokhov <dtor@...omium.org>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Len Brown <len.brown@...el.com>,
	linux-kernel@...r.kernel.org (open list),
	Pavel Machek <pavel@....cz>
Subject: [PATCH 08/16] PM / OPP: get/put regulators from OPP core

When the 'supply_names' property is present, the OPP core can request
regulators for them. All the regulators from the 'supply_names' property
must be present, in order to move forward.

If an error occurs, undo all allocations and return the appropriate
error. This also helps in returning error on -EPROBE_DEFER case, where
the driver must try again at a later point of time.

Signed-off-by: Viresh Kumar <viresh.kumar@...aro.org>
---
 drivers/base/power/opp/core.c | 30 +++++++++++++++++++++++++++---
 drivers/base/power/opp/opp.h  |  3 +++
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c
index d6e945ec6467..42ea5a332ddc 100644
--- a/drivers/base/power/opp/core.c
+++ b/drivers/base/power/opp/core.c
@@ -509,8 +509,10 @@ static struct device_opp *_add_device_opp(struct device *dev, int supply_count)
 	if (!IS_ERR(dev_opp))
 		return dev_opp;
 
-	/* Allocate size for supply-names with dev_opp */
-	size = sizeof(*dev_opp) + supply_count * sizeof(*dev_opp->supply_names);
+	/* Allocate memory for supply-names & regulators with dev_opp */
+	size = sizeof(*dev_opp);
+	size += supply_count * sizeof(*dev_opp->supply_names);
+	size += supply_count * sizeof(*dev_opp->regulators);
 
 	/*
 	 * Allocate a new device OPP table. In the infrequent case where a new
@@ -521,7 +523,8 @@ static struct device_opp *_add_device_opp(struct device *dev, int supply_count)
 		return NULL;
 
 	dev_opp->supply_count = supply_count;
-	dev_opp->supply_names = (const char **)(dev_opp + 1);
+	dev_opp->regulators = (struct regulator **)(dev_opp + 1);
+	dev_opp->supply_names = (const char **)(dev_opp->regulators + supply_count);
 
 	INIT_LIST_HEAD(&dev_opp->dev_list);
 
@@ -566,10 +569,15 @@ static void _kfree_device_rcu(struct rcu_head *head)
 static void _remove_device_opp(struct device_opp *dev_opp)
 {
 	struct device_list_opp *list_dev;
+	int count;
 
 	if (!list_empty(&dev_opp->opp_list))
 		return;
 
+	/* Release regulators */
+	for (count = dev_opp->supply_count - 1; count >= 0; count--)
+		regulator_put(dev_opp->regulators[count]);
+
 	list_dev = list_first_entry(&dev_opp->dev_list, struct device_list_opp,
 				    node);
 
@@ -1293,6 +1301,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np)
 	const char **name;
 	int ret = 0, count, supply_count, string_count;
 	bool triplets;
+	struct regulator *reg;
 
 	dev_opp = _managed_opp(opp_np);
 	if (dev_opp) {
@@ -1334,6 +1343,21 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np)
 		}
 	}
 
+	/* Get supply regulators */
+	name = dev_opp->supply_names;
+	for (count = 0; count < supply_count; count++, name++) {
+		/* Parse regulators */
+		reg = regulator_get_optional(dev, *name);
+		if (IS_ERR(reg)) {
+			ret = PTR_ERR(reg);
+			if (ret != -EPROBE_DEFER)
+				dev_err(dev, "%s: no regulator (%s) found: %d\n",
+					__func__, *name, ret);
+			goto free_table;
+		}
+		dev_opp->regulators[count] = reg;
+	}
+
 	/* We have opp-list node now, iterate over it and add OPPs */
 	count = 0;
 	for_each_available_child_of_node(opp_np, np) {
diff --git a/drivers/base/power/opp/opp.h b/drivers/base/power/opp/opp.h
index 16575268f6ce..830c4b654a51 100644
--- a/drivers/base/power/opp/opp.h
+++ b/drivers/base/power/opp/opp.h
@@ -19,6 +19,7 @@
 #include <linux/list.h>
 #include <linux/limits.h>
 #include <linux/pm_opp.h>
+#include <linux/regulator/consumer.h>
 #include <linux/rculist.h>
 #include <linux/rcupdate.h>
 
@@ -135,6 +136,7 @@ struct device_list_opp {
  * @opp_list:	list of opps
  * @np:		struct device_node pointer for opp's DT node.
  * @supply_count: Number of power-supplies
+ * @regulators:	Array of regulators
  * @supply_names: Array of strings containing names of the power-supplies
  * @shared_opp: OPP is shared between multiple devices.
  * @dentry:	debugfs dentry pointer of the real device directory (not links).
@@ -160,6 +162,7 @@ struct device_opp {
 	unsigned long clock_latency_ns_max;
 
 	unsigned int supply_count;
+	struct regulator **regulators;
 	const char **supply_names;
 
 	bool shared_opp;
-- 
2.4.0

--
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