Skip to content

Commit 30c694f

Browse files
Martin Fuzzeybroonie
authored andcommitted
regulator: da9063: better fix null deref with partial DT
Two versions of the original patch were sent but V1 was merged instead of V2 due to a mistake. So update to V2. The advantage of V2 is that it completely avoids dereferencing the pointer, even just to take the address, which may fix problems with some compilers. Both versions work on my gcc 9.4 but use the safer one. Fixes: 98e2dd5 ("regulator: da9063: fix null pointer deref with partial DT config") Signed-off-by: Martin Fuzzey <martin.fuzzey@flowbird.group> Tested-by: Benjamin Bara <benjamin.bara@skidata.com> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20230804083514.1887124-1-martin.fuzzey@flowbird.group Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 5d0c230 commit 30c694f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/regulator/da9063-regulator.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -778,9 +778,6 @@ static int da9063_check_xvp_constraints(struct regulator_config *config)
778778
const struct notification_limit *uv_l = &constr->under_voltage_limits;
779779
const struct notification_limit *ov_l = &constr->over_voltage_limits;
780780

781-
if (!config->init_data) /* No config in DT, pointers will be invalid */
782-
return 0;
783-
784781
/* make sure that only one severity is used to clarify if unchanged, enabled or disabled */
785782
if ((!!uv_l->prot + !!uv_l->err + !!uv_l->warn) > 1) {
786783
dev_err(config->dev, "%s: at most one voltage monitoring severity allowed!\n",
@@ -1031,9 +1028,12 @@ static int da9063_regulator_probe(struct platform_device *pdev)
10311028
config.of_node = da9063_reg_matches[id].of_node;
10321029
config.regmap = da9063->regmap;
10331030

1034-
ret = da9063_check_xvp_constraints(&config);
1035-
if (ret)
1036-
return ret;
1031+
/* Checking constraints requires init_data from DT. */
1032+
if (config.init_data) {
1033+
ret = da9063_check_xvp_constraints(&config);
1034+
if (ret)
1035+
return ret;
1036+
}
10371037

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

0 commit comments

Comments
 (0)