Re: [PATCH] regulator: devres: release enable GPIO on devres_alloc() failure
From: Linus Walleij
Date: Tue Dec 01 2026 - 16:16:43 EST
On Tue, Dec 1, 2026 at 6:52 AM Dmitry Torokhov
<dmitry.torokhov@xxxxxxxxx> wrote:
> regulator_register() takes ownership of the enable GPIO descriptor
> passed in the configuration and releases it on every failure path,
> including out-of-memory errors. Because callers cannot distinguish an
> -ENOMEM from devm_regulator_register()'s devres allocation from one
> returned inside regulator_register(), they cannot safely free the GPIO
> descriptor on error without risking a double put.
>
> Release the enable GPIO descriptor when devres allocation fails in
> devm_regulator_register() so the ownership contract matches
> regulator_register() across all error paths.
>
> Fixes: 0edb040d416a ("regulator: core: Track dangling GPIO descriptors")
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
Looks right to me!
Reviewed-by: Linus Walleij <linusw@xxxxxxxxxx>
Yours,
Linus Walleij