From: Yufan Chen <ericterminal@gmail.com>
To: Liam Girdwood <lgirdwood@gmail.com>, Mark Brown <broonie@kernel.org>
Cc: linux-kernel@vger.kernel.org, Yufan Chen <ericterminal@gmail.com>
Subject: [PATCH] regulator: tps65185: check devm_kzalloc() result in probe
Date: Sun, 22 Feb 2026 18:40:35 +0800 [thread overview]
Message-ID: <20260222104035.90790-1-ericterminal@gmail.com> (raw)
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>
---
drivers/regulator/tps65185.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/regulator/tps65185.c b/drivers/regulator/tps65185.c
index 3286c9ab3..786622d8d 100644
--- a/drivers/regulator/tps65185.c
+++ b/drivers/regulator/tps65185.c
@@ -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, ®map_config);
if (IS_ERR(data->regmap))
return dev_err_probe(&client->dev, PTR_ERR(data->regmap),
--
2.47.3
next reply other threads:[~2026-02-22 10:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-22 10:40 Yufan Chen [this message]
2026-02-22 10:51 ` [PATCH] regulator: tps65185: check devm_kzalloc() result in probe Eric_Terminal
2026-02-23 19:09 ` Mark Brown
-- strict thread matches above, loose matches on Subject: below --
2026-02-21 7:17 Eric-Terminal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260222104035.90790-1-ericterminal@gmail.com \
--to=ericterminal@gmail.com \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox