diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 088b41ac95063a9b19afe7dc5e443e8b134e27d0..a40055edaae456c3f59d0d7fa7e432c90e362c19 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1263,12 +1263,13 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
 	if (rdev)
 		goto found;
 
+	regulator = ERR_PTR(ret);
+
 	/*
 	 * If we have return value from dev_lookup fail, we do not expect to
 	 * succeed, so, quit with appropriate error value
 	 */
 	if (ret && ret != -ENODEV) {
-		regulator = ERR_PTR(ret);
 		goto out;
 	}