From: Thomas Fourier <fourier.thomas@gmail.com>
Cc: Thomas Fourier <fourier.thomas@gmail.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Lee Jones <lee@kernel.org>,
linux-kernel@vger.kernel.org (open list:VOLTAGE AND CURRENT
REGULATOR FRAMEWORK)
Subject: [PATCH] regulator: dbx500: Prevent double free in ux500_regulator_debug_init()
Date: Thu, 3 Dec 2026 11:05:52 +0100 [thread overview]
Message-ID: <20261203100555.384232-1-fourier.thomas@gmail.com> (raw)
When an allocation fails in ux500_regulator_debug_init(), the error
path frees rdebug.state_before_suspend and removes rdebug.dir but
leaves both pointers set. db8500_regulator_probe() ignores the return
value of ux500_regulator_debug_init(), so the driver still binds. On
remove, ux500_regulator_debug_exit() calls debugfs_remove_recursive()
on the stale dentry and frees state_before_suspend again.
Set the pointers to NULL on the error path, so the exit function
skips them. Test if those pointers are null
inux500_regulator_status_show() before dereference.
Fixes: 8986cf8852f1 ("regulator: db8500-prcmu: Separate regulator registration from probe")
Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
---
drivers/regulator/dbx500-prcmu.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/drivers/regulator/dbx500-prcmu.c b/drivers/regulator/dbx500-prcmu.c
index a45c1e1ac7ef..c97eaf0efe46 100644
--- a/drivers/regulator/dbx500-prcmu.c
+++ b/drivers/regulator/dbx500-prcmu.c
@@ -97,11 +97,12 @@ static int ux500_regulator_status_show(struct seq_file *s, void *p)
info = &rdebug.regulator_array[i];
/* print status */
- seq_printf(s, "%20s : %8s : %8s : %8s\n",
- info->desc.name,
- info->is_enabled ? "enabled" : "disabled",
- rdebug.state_before_suspend[i] ? "enabled" : "disabled",
- rdebug.state_after_suspend[i] ? "enabled" : "disabled");
+ if (rdebug.state_before_suspend && rdebug.state_after_suspend)
+ seq_printf(s, "%20s : %8s : %8s : %8s\n",
+ info->desc.name,
+ info->is_enabled ? "enabled" : "disabled",
+ rdebug.state_before_suspend[i] ? "enabled" : "disabled",
+ rdebug.state_after_suspend[i] ? "enabled" : "disabled");
}
return 0;
@@ -139,8 +140,10 @@ ux500_regulator_debug_init(struct platform_device *pdev,
exit_free:
kfree(rdebug.state_before_suspend);
+ rdebug.state_before_suspend = NULL;
exit_destroy_power_state:
debugfs_remove_recursive(rdebug.dir);
+ rdebug.dir = NULL;
return -ENOMEM;
}
--
2.53.0
reply other threads:[~2026-12-03 10:29 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261203100555.384232-1-fourier.thomas@gmail.com \
--to=fourier.thomas@gmail.com \
--cc=broonie@kernel.org \
--cc=lee@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
all inboxes | Powered by JetHome®