[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231129130530.33744-1-liuhaoran14@163.com>
Date: Wed, 29 Nov 2023 05:05:30 -0800
From: Haoran Liu <liuhaoran14@....com>
To: lgirdwood@...il.com
Cc: broonie@...nel.org, linux-kernel@...r.kernel.org,
Haoran Liu <liuhaoran14@....com>
Subject: [PATCH] [regulator] pwm-regulator: Add error handling
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@....com>
---
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
Powered by blists - more mailing lists