mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] regulator: dbx500: Prevent double free in ux500_regulator_debug_init()
@ 2026-12-03 10:05 Thomas Fourier
  0 siblings, 0 replies; only message in thread
From: Thomas Fourier @ 2026-12-03 10:05 UTC (permalink / raw)
  Cc: Thomas Fourier, Liam Girdwood, Mark Brown, Lee Jones,
	open list:VOLTAGE AND CURRENT REGULATOR FRAMEWORK

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-03 10:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03 10:05 [PATCH] regulator: dbx500: Prevent double free in ux500_regulator_debug_init() Thomas Fourier

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®