[PATCH] regulator: max1586: Fix NULL pointer dereference in probe

From: Yang Zi

Date: Tue Aug 25 2026 - 05:01:02 EST


max1586_pmic_probe() dereferences pdata->v3_gain 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 -EINVAL when
pdata is NULL.

Signed-off-by: Yang Zi <2959243019@xxxxxx>
---
 drivers/regulator/max1586.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c
index e5cbc09c2d39..de7840a58638 100644
--- a/drivers/regulator/max1586.c
+++ b/drivers/regulator/max1586.c
@@ -222,6 +222,9 @@ static int max1586_pmic_probe(struct i2c_client *client)
         pdata = &pdata_of;
     }
 
+    if (!pdata)
+        return -EINVAL;
+
     max1586 = devm_kzalloc(&client->dev, sizeof(struct max1586_data),
             GFP_KERNEL);
     if (!max1586)