[PATCH] fix: regulator: s5m8767_pmic_dt_parse_pdata: fix leaked device_node references on buck configuration error
From: WenTao Liang
Date: Fri Jun 26 2026 - 12:11:46 EST
In s5m8767_pmic_dt_parse_pdata(), for_each_child_of_node() acquires
device_node references for each regulator child stored in
rdata->reg_node. On error paths where buck2/buck3/buck4 configuration
validation fails, the function returns -EINVAL without releasing
previously acquired child node references.
Add an err_out label that releases all stored reg_node references before
returning an error.
Cc: stable@xxxxxxxxxxxxxxx
Fixes: 9767ec7fe8d9 ("regulator: Add S5M8767A regulator driver")
Signed-off-by: WenTao Liang <vulab@xxxxxxxxxxx>
---
drivers/regulator/s5m8767.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c
index a49b28786dd0..0f6903101314 100644
--- a/drivers/regulator/s5m8767.c
+++ b/drivers/regulator/s5m8767.c
@@ -571,8 +571,7 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
"s5m8767,pmic-buck2-dvs-voltage",
pdata->buck2_voltage, dvs_voltage_nr)) {
dev_err(iodev->dev, "buck2 voltages not specified\n");
- of_node_put(reg_np);
- return -EINVAL;
+ goto err_out;
}
}
@@ -583,8 +582,7 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
"s5m8767,pmic-buck3-dvs-voltage",
pdata->buck3_voltage, dvs_voltage_nr)) {
dev_err(iodev->dev, "buck3 voltages not specified\n");
- of_node_put(reg_np);
- return -EINVAL;
+ goto err_out;
}
}
@@ -595,8 +593,7 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
"s5m8767,pmic-buck4-dvs-voltage",
pdata->buck4_voltage, dvs_voltage_nr)) {
dev_err(iodev->dev, "buck4 voltages not specified\n");
- of_node_put(reg_np);
- return -EINVAL;
+ goto err_out;
}
}
@@ -627,6 +624,11 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
}
return 0;
+
+err_out:
+ for (i = 0; i < pdata->num_regulators; i++)
+ of_node_put(pdata->regulators[i].reg_node);
+ return -EINVAL;
}
#else
static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
--
2.39.5 (Apple Git-154)