2023-06-20 20:06:12

by Benjamin Bara

[permalink] [raw]
Subject: [PATCH RFC v4 01/13] regulator: da9063: fix null pointer deref with partial DT config

From: Benjamin Bara <[email protected]>

Skip checking the XVP constraints if the regulator has no DT node.
This fixes a null pointer dereference.

Fixes: b8717a80e6ee ("regulator: da9063: implement setter for voltage monitoring")
Reported-by: Martin Fuzzey <[email protected]>
Closes: https://lore.kernel.org/all/[email protected]/
Signed-off-by: Benjamin Bara <[email protected]>
---
drivers/regulator/da9063-regulator.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/regulator/da9063-regulator.c b/drivers/regulator/da9063-regulator.c
index c5dd77be558b..308ad63fcf78 100644
--- a/drivers/regulator/da9063-regulator.c
+++ b/drivers/regulator/da9063-regulator.c
@@ -1028,9 +1028,12 @@ static int da9063_regulator_probe(struct platform_device *pdev)
config.of_node = da9063_reg_matches[id].of_node;
config.regmap = da9063->regmap;

- ret = da9063_check_xvp_constraints(&config);
- if (ret)
- return ret;
+ /* Only check constraints if DT node is available. */
+ if (config.init_data) {
+ ret = da9063_check_xvp_constraints(&config);
+ if (ret)
+ return ret;
+ }

regl->rdev = devm_regulator_register(&pdev->dev, &regl->desc,
&config);

--
2.34.1