summaryrefslogtreecommitdiffstats
path: root/drivers/regulator/core.c
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2022-07-18 13:48:23 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2022-08-08 16:21:27 +0200
commit2fdb13043f0f75075332a0bb5083dd278430c064 (patch)
tree290269218c2f32884ba8bb45a46d0218b08e0885 /drivers/regulator/core.c
parent583855354bfc13367aca013159cdb5b5addc3ca2 (diff)
downloadbarebox-2fdb13043f0f75075332a0bb5083dd278430c064.tar.gz
barebox-2fdb13043f0f75075332a0bb5083dd278430c064.tar.xz
regulator: handle regulator_get_voltage(NULL) gracefully
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@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220718114824.2632364-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/regulator/core.c')
-rw-r--r--drivers/regulator/core.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index af8a0cb4fc..29a335f502 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -569,9 +569,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)