Skip to content

Commit 3c25587

Browse files
Koichiro Dengregkh
authored andcommitted
PCI: endpoint: pci-ep-msi: Fix error unwind and prevent double alloc
[ Upstream commit 1cba96c ] pci_epf_alloc_doorbell() stores the allocated doorbell message array in epf->db_msg/epf->num_db before requesting MSI vectors. If MSI allocation fails, the array is freed but the EPF state may still point to freed memory. Clear epf->db_msg and epf->num_db on the MSI allocation failure path so that later cleanup cannot double-free the array and callers can retry allocation. Also return -EBUSY when doorbells have already been allocated to prevent leaking or overwriting an existing allocation. Fixes: 1c3b002 ("PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller") Signed-off-by: Koichiro Den <den@valinux.co.jp> Signed-off-by: Manivannan Sadhasivam <mani@kernel.org> Reviewed-by: Frank Li <Frank.Li@nxp.com> Reviewed-by: Niklas Cassel <cassel@kernel.org> Link: https://patch.msgid.link/20260217063856.3759713-4-den@valinux.co.jp Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent f33315d commit 3c25587

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

drivers/pci/endpoint/pci-ep-msi.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 num_db)
5050
return -EINVAL;
5151
}
5252

53+
if (epf->db_msg)
54+
return -EBUSY;
55+
5356
domain = of_msi_map_get_device_domain(epc->dev.parent, 0,
5457
DOMAIN_BUS_PLATFORM_MSI);
5558
if (!domain) {
@@ -79,6 +82,8 @@ int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 num_db)
7982
if (ret) {
8083
dev_err(dev, "Failed to allocate MSI\n");
8184
kfree(msg);
85+
epf->db_msg = NULL;
86+
epf->num_db = 0;
8287
return ret;
8388
}
8489

0 commit comments

Comments
 (0)