]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
regulator: tps65185: check devm_kzalloc() result in probe
authorYufan Chen <ericterminal@gmail.com>
Sun, 22 Feb 2026 10:40:35 +0000 (18:40 +0800)
committerMark Brown <broonie@kernel.org>
Mon, 23 Feb 2026 14:52:16 +0000 (14:52 +0000)
tps65185_probe() dereferences the allocation result immediately by using data->regmap. If devm_kzalloc() returns NULL under memory pressure, this leads to a NULL pointer dereference.

Add the missing allocation check and return -ENOMEM on failure.

Signed-off-by: Yufan Chen <ericterminal@gmail.com>
Link: https://patch.msgid.link/20260222104035.90790-1-ericterminal@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/tps65185.c

index 3286c9ab33d026a6cabae6079ef258a1520566a8..786622d8d5980c9904f59b18bdc75c687f04dd2d 100644 (file)
@@ -332,6 +332,9 @@ static int tps65185_probe(struct i2c_client *client)
        int i;
 
        data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
+       if (!data)
+               return -ENOMEM;
+
        data->regmap = devm_regmap_init_i2c(client, &regmap_config);
        if (IS_ERR(data->regmap))
                return dev_err_probe(&client->dev, PTR_ERR(data->regmap),