Unlike recent versions of Linux, barebox represents the dummy regulator as a NULL pointer and regulator API is supposed to anticipate operation on a NULL pointer. When regulator_get_voltage was ported from Linux, this was not taken into consideration, which leads to regulator_get_voltage(NULL) crashing with a NULL pointer dereference. Fix this by returning -EINVAL for dummy regulators. This aligns us with how Linux would behave in this situation. Fixes: 6ee83ce08b24 ("regulator: add regulator_get_voltage() to API") Reported-by: Johannes Zink <j.zink@xxxxxxxxxxxxxx> Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx> --- drivers/regulator/core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 1fb344656f38..472b26f3a0ac 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -574,9 +574,14 @@ EXPORT_SYMBOL_GPL(regulator_bulk_free); int regulator_get_voltage(struct regulator *regulator) { - struct regulator_dev *rdev = regulator->ri->rdev; + struct regulator_dev *rdev; int sel, ret; + if (!regulator) + return -EINVAL; + + rdev = regulator->ri->rdev; + if (rdev->desc->ops->get_voltage_sel) { sel = rdev->desc->ops->get_voltage_sel(rdev); if (sel < 0) -- 2.30.2