diff mbox series

PCI/pwrctrl: generic: Fix leaking array from of_regulator_bulk_get_all()

Message ID 20260930-pci-pwrctrl-kfree-v1-1-f09bbffd8da3@flipper.net
State New
Headers show
Series PCI/pwrctrl: generic: Fix leaking array from of_regulator_bulk_get_all() | expand

Commit Message

Alexey Charkov Sept. 30, 2026, 4:07 p.m. UTC
of_regulator_bulk_get_all() allocates the consumers array and hands it to
the caller, who is expected to free it at an appropriate time.
PCI pwrctrl never did, leading to a memory leak.

Add an explicit kfree() for the consumers array.

Cc: stable@vger.kernel.org
Fixes: 75996c92f4de ("PCI/pwrctrl: Add pwrctrl driver for PCI slots")
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
Split out from [1] for easier application per Mark's feedback

[1] https://lore.kernel.org/all/20260929-regulator-get-all-v1-0-e887c66a47f1@flipper.net/
---
 drivers/pci/pwrctrl/generic.c | 1 +
 1 file changed, 1 insertion(+)


---
base-commit: 6c2cb8b8b843d216ab549b678a0d8831c43153e0
change-id: 20260930-pci-pwrctrl-kfree-b58621738902

Best regards,
--  
Alexey Charkov <alchark@flipper.net>

Comments

sashiko-bot@kernel.org Sept. 30, 2026, 4:17 p.m. UTC | #1
> of_regulator_bulk_get_all() allocates the consumers array and hands it to
> the caller, who is expected to free it at an appropriate time.
> PCI pwrctrl never did, leading to a memory leak.
> 
> Add an explicit kfree() for the consumers array.
> 
> Cc: stable@vger.kernel.org
> Fixes: 75996c92f4de ("PCI/pwrctrl: Add pwrctrl driver for PCI slots")
> Signed-off-by: Alexey Charkov <alchark@flipper.net>

Sashiko has reviewed this patch and found no issues. It looks great!
Bartosz Golaszewski Oct. 1, 2026, 2:41 p.m. UTC | #2
On Wed, 30 Sep 2026 18:07:45 +0200, Alexey Charkov <alchark@flipper.net> said:
> of_regulator_bulk_get_all() allocates the consumers array and hands it to
> the caller, who is expected to free it at an appropriate time.
> PCI pwrctrl never did, leading to a memory leak.
>
> Add an explicit kfree() for the consumers array.
>
> Cc: stable@vger.kernel.org
> Fixes: 75996c92f4de ("PCI/pwrctrl: Add pwrctrl driver for PCI slots")
> Signed-off-by: Alexey Charkov <alchark@flipper.net>
> ---

Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Bjorn Helgaas Oct. 1, 2026, 4:50 p.m. UTC | #3
On Wed, Sep 30, 2026 at 08:07:45PM +0400, Alexey Charkov wrote:
> of_regulator_bulk_get_all() allocates the consumers array and hands it to
> the caller, who is expected to free it at an appropriate time.
> PCI pwrctrl never did, leading to a memory leak.
> 
> Add an explicit kfree() for the consumers array.
> 
> Cc: stable@vger.kernel.org
> Fixes: 75996c92f4de ("PCI/pwrctrl: Add pwrctrl driver for PCI slots")
> Signed-off-by: Alexey Charkov <alchark@flipper.net>

Applied to pci/pwrctrl for v7.4, thanks!

> ---
> Split out from [1] for easier application per Mark's feedback
> 
> [1] https://lore.kernel.org/all/20260929-regulator-get-all-v1-0-e887c66a47f1@flipper.net/
> ---
>  drivers/pci/pwrctrl/generic.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/pci/pwrctrl/generic.c b/drivers/pci/pwrctrl/generic.c
> index d56171e0ee24..4b6cbbb52248 100644
> --- a/drivers/pci/pwrctrl/generic.c
> +++ b/drivers/pci/pwrctrl/generic.c
> @@ -63,6 +63,7 @@ static void devm_slot_pwrctrl_release(void *data)
>  	struct slot_pwrctrl *slot = data;
>  
>  	regulator_bulk_free(slot->num_supplies, slot->supplies);
> +	kfree(slot->supplies);
>  }
>  
>  static int slot_pwrctrl_probe(struct platform_device *pdev)
> 
> ---
> base-commit: 6c2cb8b8b843d216ab549b678a0d8831c43153e0
> change-id: 20260930-pci-pwrctrl-kfree-b58621738902
> 
> Best regards,
> --  
> Alexey Charkov <alchark@flipper.net>
>
diff mbox series

Patch

diff --git a/drivers/pci/pwrctrl/generic.c b/drivers/pci/pwrctrl/generic.c
index d56171e0ee24..4b6cbbb52248 100644
--- a/drivers/pci/pwrctrl/generic.c
+++ b/drivers/pci/pwrctrl/generic.c
@@ -63,6 +63,7 @@  static void devm_slot_pwrctrl_release(void *data)
 	struct slot_pwrctrl *slot = data;
 
 	regulator_bulk_free(slot->num_supplies, slot->supplies);
+	kfree(slot->supplies);
 }
 
 static int slot_pwrctrl_probe(struct platform_device *pdev)