PCI: rcar-gen4: Fix device_node leak in rcar_gen4_pcie_host_msi_addr()
Subsystems (4)
PATCH v2 1/1 PCI: rcar-gen4: Fix device_node leak in rcar_gen4_pcie_host_msi_addr()
rcar_gen4_pcie_host_msi_addr() calls of_msi_xlate() with *msi_np NULL, so it receives the MSI controller node with a reference held, and every return past the NULL check leaks that reference, the success path included. Declare msi_node with __free(device_node) so it's put on every return.
---
Notes:
Changes since v1:
- Declare msi_node immediately before of_msi_xlate() rather than at the top of the function, as Jonathan asked on the iproc conversion [1].
- Kept Marek's Tested-by and Reviewed-by, since the generated code differs only in the stack offsets of msi_node and res.
[1] https://lore.kernel.org/all/[email protected]/
drivers/pci/controller/dwc/pcie-rcar-gen4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-rcar-gen4.c +1 -1
@@ -323,7 +323,6 @@ static struct rcar_gen4_pcie *rcar_gen4_pcie_alloc(struct platform_device *pdev)static int rcar_gen4_pcie_host_msi_addr (struct dw_pcie_rp *pp,u32 *msi_addr) {struct dw_pcie *dw =to_dw_pcie_from_pp (pp); -struct device_node *msi_node =NULL ;struct device *dev = dw->dev;struct resource res;u64 addr;
@@ -333,6 +332,7 @@ static int rcar_gen4_pcie_host_msi_addr(struct dw_pcie_rp *pp, u32 *msi_addr)* Either the "msi-parent" or the "msi-map" phandle needs to exist * to obtain the MSI node. */ + struct device_node *msi_node __free(device_node) = NULL;of_msi_xlate (dev, &msi_node,0 );if (!msi_node)return -ENODEV ;
base-commit: fd73f4a6659897191fa0d40695fe370925dd3780
Signature · 1 line
2.39.5
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
rcar_gen4_pcie_host_msi_addr()callsof_msi_xlate()with*msi_npNULL, so it receives the MSI controller node with a reference held, and every return past the NULL check leaks that reference, the success path included. Declaremsi_nodewith__free(device_node)so it's put on every return.
Quoted 6 lines
Fixes 8d6af27c0a73 ("PCI: rcar-gen4: Configure AXIINTC if iMSI-RX is not used")Reported-by Sashiko <[email protected]>Reviewed-by Marek Vasut <[email protected]>Signed-off-by Fuad Tabba <[email protected]>
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
Quoted 6 lines · Fuad Tabba
rcar_gen4_pcie_host_msi_addr()callsof_msi_xlate()with*msi_npNULL, so it receives the MSI controller node with a reference held, and every return past the NULL check leaks that reference, the success path included. Declaremsi_nodewith__free(device_node)so it's put on every return.
Quoted 6 lines
Fixes 8d6af27c0a73 ("PCI: rcar-gen4: Configure AXIINTC if iMSI-RX is not used")Reported-by Sashiko <[email protected]>Reviewed-by Marek Vasut <[email protected]>Signed-off-by Fuad Tabba <[email protected]>
I liked V1 a bit better, but either way works.
Quoted 6 lines · On Wed, 23 Sep 2026 19:07:49 +0100 Fuad Tabba <[email protected]> wrote:
rcar_gen4_pcie_host_msi_addr()callsof_msi_xlate()with*msi_npNULL, so it receives the MSI controller node with a reference held, and every return past the NULL check leaks that reference, the success path included. Declaremsi_nodewith__free(device_node)so it's put on every return.
Quoted 6 lines
Fixes 8d6af27c0a73 ("PCI: rcar-gen4: Configure AXIINTC if iMSI-RX is not used")Reported-by Sashiko <[email protected]>Reviewed-by Marek Vasut <[email protected]>Signed-off-by Fuad Tabba <[email protected]>
Quoted 36 lines
---
Notes:
Changes since v1:
- Declaremsi_nodeimmediately beforeof_msi_xlate()rather than at the top of the function, as Jonathan asked on the iproc conversion [1].
- Kept Marek's Tested-by and Reviewed-by, since the generated code differs only in the stack offsets ofmsi_nodeand res.[1] https://lore.kernel.org/all/[email protected]/
drivers/pci/controller/dwc/pcie-rcar-gen4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/controller/dwc/pcie-rcar-gen4.c +1
-1@@ -323,7 +323,6 @@ static struct rcar_gen4_pcie *rcar_gen4_pcie_alloc(struct platform_device *pdev)static int rcar_gen4_pcie_host_msi_addr (struct dw_pcie_rp *pp,u32 *msi_addr) {struct dw_pcie *dw =to_dw_pcie_from_pp (pp); -struct device_node *msi_node =NULL ;struct device *dev = dw->dev;struct resource res;u64 addr;@@ -333,6 +332,7 @@ static int rcar_gen4_pcie_host_msi_addr(struct dw_pcie_rp *pp, u32 *msi_addr)* Either the "msi-parent" or the "msi-map" phandle needs to exist * to obtain the MSI node. */ + struct device_node *msi_node __free(device_node) = NULL;of_msi_xlate (dev, &msi_node,0 );if (!msi_node)return -ENODEV ;base-commit:
fd73f4a6659897191fa0d40695fe370925dd3780
Hi,
Gentle ping on this fix.
Cheers,
/fuad
Quoted 1 line · Fuad Tabba
PCI: rcar-gen4: Fix
device_nodeleak inrcar_gen4_pcie_host_msi_addr()
Applied, thanks!
[1/1] PCI: rcar-gen4: Fix device_node leak in rcar_gen4_pcie_host_msi_addr()
commit: 34fb13a4a9620658e43be79f818ac5c456402c54
Best regards,
Signature · 1 line
மணிவண்ணன் சதாசிவம்