Skip to contentSkip to conversation

regulator: max8660: Fix NULL pointer dereference in probe

PATCH In review Yang Zi 2 participants 2 messages Aug 25 – Aug 26 Voltage and current regulator framework

lore
Share & tools
lore

Yang Zi

author
#0 lore raw

PATCH 1/1 regulator: max8660: Fix NULL pointer dereference in probe

max8660_probe() dereferences pdata->num_subdevs without first checking that platform data is available. When the device is instantiated without a device tree node and without platform data, pdata remains NULL and probe crashes with a NULL pointer dereference.

Add a check after the platform data is resolved and return -ENODEV when pdata is NULL.

---
 drivers/regulator/max8660.c | 3 +++

 1 file changed, 3 insertions(+)
drivers/regulator/max8660.c +0 -0
index ede17099b727..ae606067df2d 100644
@@ -396,6 +396,9 @@ static int max8660_probe(struct i2c_client *client)

         memset(of_node, 0, sizeof(of_node)); }

+    if (!pdata)
+        return -ENODEV;
+
     if (pdata->num_subdevs > MAX8660_V_END) { dev_err(dev, "Too many regulators found!\n"); return -EINVAL;

maintainer
#1 lore raw
Quoted 4 lines · Yang Zi

max8660_probe() dereferences pdata->num_subdevs without first checking that platform data is available. When the device is instantiated without a device tree node and without platform data, pdata remains NULL and probe crashes with a NULL pointer dereference.

This doesn't apply against current code, please check and resend.