power: sequencing: fix serdev controller reference leak
Subsystems (4)
PATCH 1/1 power: sequencing: fix serdev controller reference leak
In pwrseq_pcie_m2_create_serdev_one(), if serdev_ctrl->serdev is NULL but pdev is already tracked in ctx->pci_devices, we return early from the loop and skip the serdev_controller_put(), leaking the reference.
Initialize ret to 0 and jump directly to the label that ensures the reference is released.
--- drivers/power/sequencing/pwrseq-pcie-m2.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/power/sequencing/pwrseq-pcie-m2.c +4 -6
@@ -296,7 +296,7 @@ static int pwrseq_pcie_m2_create_serdev_one(struct pwrseq_pcie_m2_ctx *ctx,struct serdev_controller *serdev_ctrl;struct device *dev = ctx->dev;struct pwrseq_pci_dev *pci_dev; -int ret; +int ret =0 ; struct device_node *serdev_parent __free(device_node) =of_graph_get_remote_node (dev_of_node (ctx->dev),3 ,0 );
@@ -308,16 +308,14 @@ static int pwrseq_pcie_m2_create_serdev_one(struct pwrseq_pcie_m2_ctx *ctx,return 0 ;/* Bail out if the device was already attached to this controller */ -if (serdev_ctrl->serdev) { -serdev_controller_put (serdev_ctrl); -return 0 ; - } +if (serdev_ctrl->serdev) + goto err_put_ctrl;/* Bail out if the serdev device was already created for the PCI dev */ scoped_guard(mutex, &ctx->list_lock) {list_for_each_entry (pci_dev, &ctx->pci_devices, list) {if (pci_dev->pdev == pdev) -return 0 ; + goto err_put_ctrl; } }
---
base-commit: ddfe51b0a0f5dc9e415cc2c8ad8db17532dd426b
change-id: 20261105-pwrseq-pcie-m2-serdev-ref-leak-f521e086d5f8
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 11 lines
In
pwrseq_pcie_m2_create_serdev_one(), ifserdev_ctrl->serdevis NULL but pdev is already tracked inctx->pci_devices, we return early from the loop and skip theserdev_controller_put(), leaking the reference.Initialize ret to 0 and jump directly to the label that ensures the reference is released.
Fixes c4be520907a4 ("power: sequencing: pcie-m2: Create serdev for PCI devices present before probe")Signed-off-by Bartosz Golaszewski <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20261105-pwrseq-pcie-m2-serdev-ref-leak-v1-1-e2e022ca17ec@oss.qualcomm.com?part=1
Bartosz Golaszewski
AppliedQuoted 8 lines · Bartosz Golaszewski
In
pwrseq_pcie_m2_create_serdev_one(), ifserdev_ctrl->serdevis NULL but pdev is already tracked inctx->pci_devices, we return early from the loop and skip theserdev_controller_put(), leaking the reference.Initialize ret to 0 and jump directly to the label that ensures the reference is released.
[...]
Applied, thanks!
[1/1] power: sequencing: fix serdev controller reference leak
https://git.kernel.org/brgl/c/073f01043e79fd76f4fa648e58061c80329a6eef
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>