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-next>] [day] [month] [year] [list]
Date:	Thu, 19 Sep 2013 20:16:28 +0530
From:	Laxman Dewangan <ldewangan@...dia.com>
To:	<broonie@...nel.org>
CC:	<lgirdwood@...il.com>, <linux-kernel@...r.kernel.org>,
	<swarren@...dia.com>, Laxman Dewangan <ldewangan@...dia.com>
Subject: [PATCH] regulator: core: set current constraints while setting machine constraints

Machine constraints is configured during regulator register. If current
constraints are provided through machine constraints then it is observed
that sometime the current configured on rail is out of range what machine
constraint has.

Set the current constraints when setting machine constraints to make
sure that rail's current is within the range of given machine constraints.

Signed-off-by: Laxman Dewangan <ldewangan@...dia.com>
---
 drivers/regulator/core.c |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index b698e2b..617e337 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -904,6 +904,40 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
 	return 0;
 }
 
+static int machine_constraints_current(struct regulator_dev *rdev,
+	struct regulation_constraints *constraints)
+{
+	int current_uA;
+	int ret;
+
+	if (!rdev->desc->ops->set_current_limit ||
+			!rdev->desc->ops->get_current_limit)
+		return 0;
+
+	if (!rdev->constraints->min_uA && !rdev->constraints->max_uA)
+		return 0;
+
+	if (rdev->constraints->min_uA > rdev->constraints->max_uA) {
+		rdev_err(rdev, "Current constraint is invalid\n");
+		return -EINVAL;
+	}
+
+	/* Set regulator current in constraint range */
+	current_uA = rdev->desc->ops->get_current_limit(rdev);
+	if (current_uA < rdev->constraints->min_uA ||
+			current_uA > rdev->constraints->max_uA) {
+		ret = rdev->desc->ops->set_current_limit(rdev,
+				rdev->constraints->min_uA,
+				rdev->constraints->max_uA);
+		if (ret < 0) {
+			rdev_err(rdev,
+				"Failed to set current constraint, %d\n", ret);
+			return ret;
+		}
+	}
+	return 0;
+}
+
 /**
  * set_machine_constraints - sets regulator constraints
  * @rdev: regulator source
@@ -934,6 +968,10 @@ static int set_machine_constraints(struct regulator_dev *rdev,
 	if (ret != 0)
 		goto out;
 
+	ret = machine_constraints_current(rdev, rdev->constraints);
+	if (ret != 0)
+		goto out;
+
 	/* do we need to setup our suspend state */
 	if (rdev->constraints->initial_state) {
 		ret = suspend_prepare(rdev, rdev->constraints->initial_state);
-- 
1.7.1.1

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