Skip to contentSkip to conversation

regulator: Fix the error handling if create_regulator fails

PATCH Applied Axel Lin 2 participants 3 messages Dec 29, 2011 Voltage and current regulator framework

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/2 regulator: Fix the error handling if create_regulator fails

In the case of create_regulator() fails, goto the error path immediately. It does not make sense to update rdev->open_count if create_regulator fails.

---
 drivers/regulator/core.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/regulator/core.c +1 -0
index dbdebed6..fb6ea9b 100644
@@ -1282,6 +1282,7 @@ found:
 	if (regulator == NULL) {
 		regulator = ERR_PTR(-ENOMEM);
 		module_put(rdev->owner);
+		goto out;
 	}
 
 	rdev->open_count++;
Signature · 1 line
1.7.5.4
author
#1 lore raw

PATCH 2/2 regulator: Fix checking return value of create_regulator

create_regulator() returns NULL on fail.

---
 drivers/regulator/core.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
drivers/regulator/core.c +2 -3
index fb6ea9b..5e43906 100644
@@ -985,9 +985,8 @@ static int set_supply(struct regulator_dev *rdev,
 	rdev_info(rdev, "supplied by %s\n", rdev_get_name(supply_rdev));
 
 	rdev->supply = create_regulator(supply_rdev, &rdev->dev, "SUPPLY");
-	if (IS_ERR(rdev->supply)) {
-		err = PTR_ERR(rdev->supply);
-		rdev->supply = NULL;
+	if (rdev->supply == NULL) {
+		err = -ENOMEM;
 		return err;
 	}
 
Signature · 1 line
1.7.5.4
Applied
#2 lore raw
In reply to Axel Lin
Quoted 2 lines · Axel Lin

In the case of create_regulator() fails, goto the error path immediately. It does not make sense to update rdev->open_count if create_regulator fails.

Applied both, thanks.