2023-11-29 13:06:59

by Haoran Liu

[permalink] [raw]
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 <[email protected]>
---
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


2023-11-29 13:24:56

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] [regulator] pwm-regulator: Add error handling

On Wed, Nov 29, 2023 at 05:05:30AM -0800, Haoran Liu wrote:

> + 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;
> + }

These properties are both optiona..


Attachments:
(No filename) (582.00 B)
signature.asc (499.00 B)
Download all attachments

2023-11-29 23:10:49

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] [regulator] pwm-regulator: Add error handling

Hi Haoran,

kernel test robot noticed the following build errors:

[auto build test ERROR on v6.7-rc3]
[also build test ERROR on linus/master next-20231129]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Haoran-Liu/pwm-regulator-Add-error-handling/20231129-210930
base: v6.7-rc3
patch link: https://lore.kernel.org/r/20231129130530.33744-1-liuhaoran14%40163.com
patch subject: [PATCH] [regulator] pwm-regulator: Add error handling
config: x86_64-buildonly-randconfig-004-20231130 (https://download.01.org/0day-ci/archive/20231130/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231130/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/regulator/pwm-regulator.c: In function 'pwm_regulator_init_continuous':
>> drivers/regulator/pwm-regulator.c:299:9: error: 'ret' undeclared (first use in this function); did you mean 'net'?
299 | ret = of_property_read_u32_array(pdev->dev.of_node,
| ^~~
| net
drivers/regulator/pwm-regulator.c:299:9: note: each undeclared identifier is reported only once for each function it appears in


vim +299 drivers/regulator/pwm-regulator.c

289
290 static int pwm_regulator_init_continuous(struct platform_device *pdev,
291 struct pwm_regulator_data *drvdata)
292 {
293 u32 dutycycle_range[2] = { 0, 100 };
294 u32 dutycycle_unit = 100;
295
296 drvdata->desc.ops = &pwm_regulator_voltage_continuous_ops;
297 drvdata->desc.continuous_voltage_range = true;
298
> 299 ret = of_property_read_u32_array(pdev->dev.of_node,
300 "pwm-dutycycle-range",
301 dutycycle_range, 2);
302 if (ret) {
303 dev_err(&pdev->dev,
304 "Failed to read pwm-dutycycle-range: %d\n", ret);
305 return ret;
306 }
307
308 ret = of_property_read_u32(pdev->dev.of_node,
309 "pwm-dutycycle-unit",
310 &dutycycle_unit);
311 if (ret) {
312 dev_err(&pdev->dev,
313 "Failed to read pwm-dutycycle-unit: %d\n", ret);
314 return ret;
315 }
316
317 if (dutycycle_range[0] > dutycycle_unit ||
318 dutycycle_range[1] > dutycycle_unit)
319 return -EINVAL;
320
321 drvdata->continuous.dutycycle_unit = dutycycle_unit;
322 drvdata->continuous.min_uV_dutycycle = dutycycle_range[0];
323 drvdata->continuous.max_uV_dutycycle = dutycycle_range[1];
324
325 return 0;
326 }
327

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

2023-11-29 23:13:25

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] [regulator] pwm-regulator: Add error handling

Hi Haoran,

kernel test robot noticed the following build errors:

[auto build test ERROR on v6.7-rc3]
[also build test ERROR on linus/master next-20231129]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Haoran-Liu/pwm-regulator-Add-error-handling/20231129-210930
base: v6.7-rc3
patch link: https://lore.kernel.org/r/20231129130530.33744-1-liuhaoran14%40163.com
patch subject: [PATCH] [regulator] pwm-regulator: Add error handling
config: i386-randconfig-r081-20231130 (https://download.01.org/0day-ci/archive/20231130/[email protected]/config)
compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231130/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/regulator/pwm-regulator.c:299:2: error: use of undeclared identifier 'ret'
ret = of_property_read_u32_array(pdev->dev.of_node,
^
drivers/regulator/pwm-regulator.c:302:6: error: use of undeclared identifier 'ret'
if (ret) {
^
drivers/regulator/pwm-regulator.c:304:48: error: use of undeclared identifier 'ret'
"Failed to read pwm-dutycycle-range: %d\n", ret);
^
drivers/regulator/pwm-regulator.c:305:10: error: use of undeclared identifier 'ret'
return ret;
^
drivers/regulator/pwm-regulator.c:308:2: error: use of undeclared identifier 'ret'
ret = of_property_read_u32(pdev->dev.of_node,
^
drivers/regulator/pwm-regulator.c:311:6: error: use of undeclared identifier 'ret'
if (ret) {
^
drivers/regulator/pwm-regulator.c:313:47: error: use of undeclared identifier 'ret'
"Failed to read pwm-dutycycle-unit: %d\n", ret);
^
drivers/regulator/pwm-regulator.c:314:10: error: use of undeclared identifier 'ret'
return ret;
^
8 errors generated.


vim +/ret +299 drivers/regulator/pwm-regulator.c

289
290 static int pwm_regulator_init_continuous(struct platform_device *pdev,
291 struct pwm_regulator_data *drvdata)
292 {
293 u32 dutycycle_range[2] = { 0, 100 };
294 u32 dutycycle_unit = 100;
295
296 drvdata->desc.ops = &pwm_regulator_voltage_continuous_ops;
297 drvdata->desc.continuous_voltage_range = true;
298
> 299 ret = of_property_read_u32_array(pdev->dev.of_node,
300 "pwm-dutycycle-range",
301 dutycycle_range, 2);
302 if (ret) {
303 dev_err(&pdev->dev,
304 "Failed to read pwm-dutycycle-range: %d\n", ret);
305 return ret;
306 }
307
308 ret = of_property_read_u32(pdev->dev.of_node,
309 "pwm-dutycycle-unit",
310 &dutycycle_unit);
311 if (ret) {
312 dev_err(&pdev->dev,
313 "Failed to read pwm-dutycycle-unit: %d\n", ret);
314 return ret;
315 }
316
317 if (dutycycle_range[0] > dutycycle_unit ||
318 dutycycle_range[1] > dutycycle_unit)
319 return -EINVAL;
320
321 drvdata->continuous.dutycycle_unit = dutycycle_unit;
322 drvdata->continuous.min_uV_dutycycle = dutycycle_range[0];
323 drvdata->continuous.max_uV_dutycycle = dutycycle_range[1];
324
325 return 0;
326 }
327

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki