Skip to contentSkip to conversation

regulator: da9063: Optimize da9063_set_current_limit implementation

PATCH Applied Axel Lin 2 participants 3 messages Aug 30, 2013

Subsystems (2)
lore
Share & tools
lore

Axel Lin

author
#0 lore raw

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.

---
 drivers/regulator/da9063-regulator.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/regulator/da9063-regulator.c +4 -11
index fc2871cb..f29e729 100644
@@ -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)
Signature · 1 line
1.8.1.2
author
#1 lore raw

PATCH 2/2 regulator: da9063: Use IS_ERR to check return value of regulator_register()

regulator_register() does not return NULL, it returns ERR_PTR on error.

---
 drivers/regulator/da9063-regulator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/regulator/da9063-regulator.c +1 -1
index f29e729..139ad45 100644
@@ -848,7 +848,7 @@ static int da9063_regulator_probe(struct platform_device *pdev)
 			config.of_node = da9063_reg_matches[id].of_node;
 		config.regmap = da9063->regmap;
 		regl->rdev = regulator_register(&regl->desc, &config);
-		if (IS_ERR_OR_NULL(regl->rdev)) {
+		if (IS_ERR(regl->rdev)) {
 			dev_err(&pdev->dev,
 				"Failed to register %s regulator\n",
 				regl->desc.name);
Signature · 1 line
1.8.1.2
maintainer Applied
#2 lore raw
In reply to Axel Lin
Quoted 3 lines · Axel Lin

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.

Applied both, thanks.