[PATCH] media: intel/ipu6: Fix pdata double free in init error paths
From: Guangshuo Li
Date: Thu Apr 30 2026 - 01:55:03 EST
ipu6_bus_initialize_device() stores the caller allocated pdata pointer in
adev->pdata and installs ipu6_bus_release() as the device release callback.
After auxiliary_device_init() succeeds, pdata is released by
ipu6_bus_release().
The isys and psys init error paths still call kfree(pdata) after
put_device() or after ipu6_bus_add_device() fails. In both cases the
auxiliary device release callback has already been invoked, so pdata has
already been freed through adev->pdata.
Remove the duplicate kfree(pdata) calls. Also cache the MMU init error
before calling put_device(), since put_device() may release the auxiliary
device container.
This issue was found by a static analysis tool I am developing.
Fixes: 25fedc021985a ("media: intel/ipu6: add Intel IPU6 PCI device driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
---
drivers/media/pci/intel/ipu6/ipu6.c | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/drivers/media/pci/intel/ipu6/ipu6.c b/drivers/media/pci/intel/ipu6/ipu6.c
index 34f67f4f1bb5..96ee33af8f6a 100644
--- a/drivers/media/pci/intel/ipu6/ipu6.c
+++ b/drivers/media/pci/intel/ipu6/ipu6.c
@@ -399,19 +399,18 @@ ipu6_isys_init(struct pci_dev *pdev, struct device *parent,
isys_adev->mmu = ipu6_mmu_init(dev, base, ISYS_MMID,
&ipdata->hw_variant);
if (IS_ERR(isys_adev->mmu)) {
+ ret = PTR_ERR(isys_adev->mmu);
+ dev_err_probe(dev, ret,
+ "ipu6_mmu_init(isys_adev->mmu) failed\n");
put_device(&isys_adev->auxdev.dev);
- kfree(pdata);
- return dev_err_cast_probe(dev, isys_adev->mmu,
- "ipu6_mmu_init(isys_adev->mmu) failed\n");
+ return ERR_PTR(ret);
}
isys_adev->mmu->dev = &isys_adev->auxdev.dev;
ret = ipu6_bus_add_device(isys_adev);
- if (ret) {
- kfree(pdata);
+ if (ret)
return ERR_PTR(ret);
- }
return isys_adev;
}
@@ -443,19 +442,18 @@ ipu6_psys_init(struct pci_dev *pdev, struct device *parent,
psys_adev->mmu = ipu6_mmu_init(&pdev->dev, base, PSYS_MMID,
&ipdata->hw_variant);
if (IS_ERR(psys_adev->mmu)) {
+ ret = PTR_ERR(psys_adev->mmu);
+ dev_err_probe(&pdev->dev, ret,
+ "ipu6_mmu_init(psys_adev->mmu) failed\n");
put_device(&psys_adev->auxdev.dev);
- kfree(pdata);
- return dev_err_cast_probe(&pdev->dev, psys_adev->mmu,
- "ipu6_mmu_init(psys_adev->mmu) failed\n");
+ return ERR_PTR(ret);
}
psys_adev->mmu->dev = &psys_adev->auxdev.dev;
ret = ipu6_bus_add_device(psys_adev);
- if (ret) {
- kfree(pdata);
+ if (ret)
return ERR_PTR(ret);
- }
return psys_adev;
}
--
2.43.0