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

From: Benjamin Bara
Date: Tue Jun 20 2023 - 16:03:44 EST


From: Benjamin Bara <benjamin.bara@xxxxxxxxxxx>

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 <martin.fuzzey@flowbird.group>
Closes: https://lore.kernel.org/all/20230616143736.2946173-1-martin.fuzzey@flowbird.group/
Signed-off-by: Benjamin Bara <benjamin.bara@xxxxxxxxxxx>
---
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