]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
regulator: core: fix NULL dereference on unbind due to stale coupling data
authorAlessandro Carminati <acarmina@redhat.com>
Thu, 26 Jun 2025 08:38:09 +0000 (08:38 +0000)
committerMark Brown <broonie@kernel.org>
Sun, 29 Jun 2025 21:10:41 +0000 (22:10 +0100)
Failing to reset coupling_desc.n_coupled after freeing coupled_rdevs can
lead to NULL pointer dereference when regulators are accessed post-unbind.

This can happen during runtime PM or other regulator operations that rely
on coupling metadata.

For example, on ridesx4, unbinding the 'reg-dummy' platform device triggers
a panic in regulator_lock_recursive() due to stale coupling state.

Ensure n_coupled is set to 0 to prevent access to invalid pointers.

Signed-off-by: Alessandro Carminati <acarmina@redhat.com>
Link: https://patch.msgid.link/20250626083809.314842-1-acarmina@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/core.c

index 7a248dc8d2e2ffd21e7daf729de9b33a5efc1937..cbd6d53ebfb5ef21b5dfc8b0f1f1f033772a886c 100644 (file)
@@ -5639,6 +5639,7 @@ static void regulator_remove_coupling(struct regulator_dev *rdev)
                                 ERR_PTR(err));
        }
 
+       rdev->coupling_desc.n_coupled = 0;
        kfree(rdev->coupling_desc.coupled_rdevs);
        rdev->coupling_desc.coupled_rdevs = NULL;
 }