[PATCH] regulator: dbx500: Prevent double free in ux500_regulator_debug_init()

From: Thomas Fourier

Date: Thu Dec 03 2026 - 05:29:49 EST


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@xxxxxxxxx>
---
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