[PATCH] regulator: qcom_spmi: do no register unused regulators

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Typically SPMI interface to PMIC regulators on Qualcomm platforms is
used to supplement RPM interface in cases where direct control is
required (e.g. for the APCC or GFX regulators). Registering all possible
regulators is thus not required and may be potentially harmfull if
somebody tries to setup those directly. Thus register only regulators
that are really used in the device tree and ignore all unused
regulators.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@xxxxxxxxxx>
---
 drivers/regulator/qcom_spmi-regulator.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/regulator/qcom_spmi-regulator.c b/drivers/regulator/qcom_spmi-regulator.c
index 41424a3366d0..5e68c3829e50 100644
--- a/drivers/regulator/qcom_spmi-regulator.c
+++ b/drivers/regulator/qcom_spmi-regulator.c
@@ -2147,20 +2147,29 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev)
 			dev_err(dev, "ERROR reading SAW regmap\n");
 	}
 
-	for (reg = match->data; reg->name; reg++) {
-
+	for_each_child_of_node(node, reg_node) {
 		if (saw_regmap) {
-			reg_node = of_get_child_by_name(node, reg->name);
 			reg_prop = of_find_property(reg_node, "qcom,saw-slave",
 						    &lenp);
-			of_node_put(reg_node);
 			if (reg_prop)
 				continue;
 		}
 
+		for (reg = match->data; reg->name; reg++) {
+			if (of_node_name_eq(reg_node, reg->name))
+				break;
+		}
+
+		if (!reg->name) {
+			dev_err(dev, "No regulator matches device node %pOF\n", reg_node);
+			continue;
+		}
+
 		vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL);
-		if (!vreg)
+		if (!vreg) {
+			of_node_put(reg_node);
 			return -ENOMEM;
+		}
 
 		vreg->dev = dev;
 		vreg->base = reg->base;
@@ -2211,6 +2220,7 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev)
 		rdev = devm_regulator_register(dev, &vreg->desc, &config);
 		if (IS_ERR(rdev)) {
 			dev_err(dev, "failed to register %s\n", name);
+			of_node_put(reg_node);
 			return PTR_ERR(rdev);
 		}
 
-- 
2.33.0




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux