[PATCH master 1/2] regulator: handle regulator_get_voltage(NULL) gracefully
Sascha Hauer
sha at pengutronix.de
Mon Aug 8 07:21:48 PDT 2022
On Mon, Jul 18, 2022 at 01:48:23PM +0200, Ahmad Fatoum wrote:
> 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 at pengutronix.de>
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
> drivers/regulator/core.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
Applied, thanks
Sascha
>
> 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
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list