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, 30 Aug 2013 20:07:38 +0800
From:	Axel Lin <axel.lin@...ics.com>
To:	Mark Brown <broonie@...nel.org>
Cc:	Krystian Garbaciak <krystian.garbaciak@...semi.com>,
	Philipp Zabel <p.zabel@...gutronix.de>,
	Liam Girdwood <lgirdwood@...il.com>,
	linux-kernel@...r.kernel.org
Subject: [PATCH 1/2] regulator: da9063: Optimize da9063_set_current_limit
 implementation

All the current limit tables have the values in ascend order.
So we can slightly optimize the for loop iteration because the first match
is the minimal value.

Signed-off-by: Axel Lin <axel.lin@...ics.com>
---
 drivers/regulator/da9063-regulator.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/drivers/regulator/da9063-regulator.c b/drivers/regulator/da9063-regulator.c
index fc2871cb..f29e729 100644
--- a/drivers/regulator/da9063-regulator.c
+++ b/drivers/regulator/da9063-regulator.c
@@ -166,22 +166,15 @@ static int da9063_set_current_limit(struct regulator_dev *rdev,
 {
 	struct da9063_regulator *regl = rdev_get_drvdata(rdev);
 	const struct da9063_regulator_info *rinfo = regl->info;
-	int val = INT_MAX;
-	unsigned sel = 0;
-	int n;
-	int tval;
+	int n, tval;
 
 	for (n = 0; n < rinfo->n_current_limits; n++) {
 		tval = rinfo->current_limits[n];
-		if (tval >= min_uA && tval <= max_uA && val > tval) {
-			val = tval;
-			sel = n;
-		}
+		if (tval >= min_uA && tval <= max_uA)
+			return regmap_field_write(regl->ilimit, n);
 	}
-	if (val == INT_MAX)
-		return -EINVAL;
 
-	return regmap_field_write(regl->ilimit, sel);
+	return -EINVAL;
 }
 
 static int da9063_get_current_limit(struct regulator_dev *rdev)
-- 
1.8.1.2



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