regulator: max8660: Fix NULL pointer dereference in probe
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
@@ -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;
Mark Brown
maintainerQuoted 4 lines · Yang Zi
max8660_probe()dereferencespdata->num_subdevswithout 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.