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:	Fri, 21 Mar 2014 11:31:25 +0900
From:	Jonghwan Choi <jhbird.choi@...sung.com>
To:	'open list' <linux-kernel@...r.kernel.org>
Cc:	'Liam Girdwood' <lgirdwood@...il.com>,
	'Mark Brown' <broonie@...nel.org>
Subject: [PATCH] regulator: core: Reduce busy-wait looping

Commit 5df529d440("regulator: core: Reduce busy-wait looping")
can also be used in regulator_do_set_voltage.

Signed-off-by: Jonghwan Choi <jhbird.choi@...sung.com>
---
 drivers/regulator/core.c |   39 +++++++++++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index afca1bc..c375bfb 100644
--- a/drivers/regulator/core.c
+++ b/d728099474rivers/regulator/core.c
@@ -2355,12 +2355,39 @@ static int _regulator_do_set_voltage(struct
regulator_dev *rdev,
 			delay = 0;
 		}
 
-		/* Insert any necessary delays */
-		if (delay >= 1000) {
-			mdelay(delay / 1000);
-			udelay(delay % 1000);
-		} else if (delay) {
-			udelay(delay);
+		/*
+		 * Delay for the requested amount of time as per the
guidelines in:
+		 *
+		 *     Documentation/timers/timers-howto.txt
+		 *
+		 * The assumption here is that regulators will never set the
voltage in
+		 * atomic context and therefore sleeping functions can be
used.
+		 */
+		if (delay) {
+			unsigned int ms = delay / 1000;
+			unsigned int us = delay % 1000;
+
+			if (ms > 0) {
+				/*
+				 * For small enough values, handle
super-millisecond
+				 * delays in the usleep_range() call below.
+				 */
+				if (ms < 20)
+					us += ms * 1000;
+				else
+					msleep(ms);
+			}
+
+			/*
+			 * Give the scheduler some room to coalesce with any
other
+			 * wakeup sources. For delays shorter than 10 us,
don't even
+			 * bother setting up high-resolution timers and just
busy-
+			 * loop.
+			 */
+			if (us >= 10)
+				usleep_range(us, us + 100);
+			else
+				udelay(us);
 		}
 	}
 
-- 
1.7.10.4

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