[PATCH] [regulator] pwm-regulator: Add error handling
From: Haoran Liu
Date: Wed Nov 29 2023 - 08:05:53 EST
This patch enhances the pwm_regulator_init_continuous function
in drivers/regulator/pwm-regulator.c by adding error handling
for of_property_read_u32_array and of_property_read_u32 calls.
Previously, the function did not properly handle failures from
these of_property_read functions, potentially leading to
incorrect behavior if the required DT properties were not found
or were malformed.
Signed-off-by: Haoran Liu <liuhaoran14@xxxxxxx>
---
drivers/regulator/pwm-regulator.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/drivers/regulator/pwm-regulator.c b/drivers/regulator/pwm-regulator.c
index 2aff6db748e2..8eb142180ddb 100644
--- a/drivers/regulator/pwm-regulator.c
+++ b/drivers/regulator/pwm-regulator.c
@@ -296,11 +296,23 @@ static int pwm_regulator_init_continuous(struct platform_device *pdev,
drvdata->desc.ops = &pwm_regulator_voltage_continuous_ops;
drvdata->desc.continuous_voltage_range = true;
- of_property_read_u32_array(pdev->dev.of_node,
- "pwm-dutycycle-range",
- dutycycle_range, 2);
- of_property_read_u32(pdev->dev.of_node, "pwm-dutycycle-unit",
- &dutycycle_unit);
+ ret = of_property_read_u32_array(pdev->dev.of_node,
+ "pwm-dutycycle-range",
+ dutycycle_range, 2);
+ if (ret) {
+ dev_err(&pdev->dev,
+ "Failed to read pwm-dutycycle-range: %d\n", ret);
+ return ret;
+ }
+
+ ret = of_property_read_u32(pdev->dev.of_node,
+ "pwm-dutycycle-unit",
+ &dutycycle_unit);
+ if (ret) {
+ dev_err(&pdev->dev,
+ "Failed to read pwm-dutycycle-unit: %d\n", ret);
+ return ret;
+ }
if (dutycycle_range[0] > dutycycle_unit ||
dutycycle_range[1] > dutycycle_unit)
--
2.17.1