mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] [regulator] pwm-regulator: Add error handling
@ 2023-11-29 13:05 Haoran Liu
  2023-11-29 13:24 ` Mark Brown
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Haoran Liu @ 2023-11-29 13:05 UTC (permalink / raw)
  To: lgirdwood; +Cc: broonie, linux-kernel, Haoran Liu

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@163.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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-11-29 23:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-29 13:05 [PATCH] [regulator] pwm-regulator: Add error handling Haoran Liu
2023-11-29 13:24 ` Mark Brown
2023-11-29 23:08 ` kernel test robot
2023-11-29 23:11 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®