]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
regulator: fixed: fix GPIO descriptor leak on register failure
authorHaotian Zhang <vulab@iscas.ac.cn>
Tue, 28 Oct 2025 17:28:28 +0000 (01:28 +0800)
committerMark Brown <broonie@kernel.org>
Wed, 5 Nov 2025 11:56:16 +0000 (11:56 +0000)
In the commit referenced by the Fixes tag,
devm_gpiod_get_optional() was replaced by manual
GPIO management, relying on the regulator core to release the
GPIO descriptor. However, this approach does not account for the
error path: when regulator registration fails, the core never
takes over the GPIO, resulting in a resource leak.

Add gpiod_put() before returning on regulator registration failure.

Fixes: 5e6f3ae5c13b ("regulator: fixed: Let core handle GPIO descriptor")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
Link: https://patch.msgid.link/20251028172828.625-1-vulab@iscas.ac.cn
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/fixed.c

index 1cb647ed70c62d5e669b422d0784cb00b243a663..a2d16e9abfb58dc3ebd1c1c612fe699ae3487d95 100644 (file)
@@ -334,6 +334,7 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
                ret = dev_err_probe(&pdev->dev, PTR_ERR(drvdata->dev),
                                    "Failed to register regulator: %ld\n",
                                    PTR_ERR(drvdata->dev));
+               gpiod_put(cfg.ena_gpiod);
                return ret;
        }