Skip to contentSkip to conversation

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

PATCH Applied Alexey Charkov 4 participants 4 messages Sep 30 – Oct 1

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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

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.

Fixes 75996c92f4de ("PCI/pwrctrl: Add pwrctrl driver for PCI slots")

---
Split out from [1] for easier application per Mark's feedback

[1] https://lore.kernel.org/all/[email protected]/

---
 drivers/pci/pwrctrl/generic.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/pwrctrl/generic.c +1 -0
index d56171e0ee24..4b6cbbb52248 100644
@@ -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,

Signature · 1 line
Alexey Charkov <[email protected]>
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines

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.

Fixes 75996c92f4de ("PCI/pwrctrl: Add pwrctrl driver for PCI slots")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Alexey Charkov
Quoted 10 lines · Alexey Charkov

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.

Fixes 75996c92f4de ("PCI/pwrctrl: Add pwrctrl driver for PCI slots")

---

#3 lore raw
In reply to Alexey Charkov
Quoted 9 lines · Alexey Charkov

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.

Fixes 75996c92f4de ("PCI/pwrctrl: Add pwrctrl driver for PCI slots")

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

Quoted 29 lines

---
Split out from [1] for easier application per Mark's feedback

[1] https://lore.kernel.org/all/[email protected]/

---
 drivers/pci/pwrctrl/generic.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/pwrctrl/generic.c +1 -1
index d56171e0ee24..4b6cbbb52248 100644
@@ -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,

Signature · 1 line
Alexey Charkov <[email protected]>