All of lore.kernel.org
 help / color / mirror / Atom feed
From: Haoran Liu <liuhaoran14@163.com>
To: lgirdwood@gmail.com
Cc: broonie@kernel.org, linux-kernel@vger.kernel.org,
	Haoran Liu <liuhaoran14@163.com>
Subject: [PATCH] [regulator] pwm-regulator: Add error handling
Date: Wed, 29 Nov 2023 05:05:30 -0800	[thread overview]
Message-ID: <20231129130530.33744-1-liuhaoran14@163.com> (raw)

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


             reply	other threads:[~2023-11-29 13:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-29 13:05 Haoran Liu [this message]
2023-11-29 13:24 ` [PATCH] [regulator] pwm-regulator: Add error handling Mark Brown
2023-11-29 23:08 ` kernel test robot
2023-11-29 23:11 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231129130530.33744-1-liuhaoran14@163.com \
    --to=liuhaoran14@163.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.