PCI: rcar-gen4: Fix device_node leak in rcar_gen4_pcie_host_msi_addr()
Subsystems (4)
PATCH 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.
--- 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,7 @@ 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_node *msi_node __free(device_node) = NULL;struct device *dev = dw->dev;struct resource res;u64 addr;
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 10 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.Fixes 8d6af27c0a73 ("PCI: rcar-gen4: Configure AXIINTC if iMSI-RX is not used")Reported-by Sashiko <[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 19 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.Fixes 8d6af27c0a73 ("PCI: rcar-gen4: Configure AXIINTC if iMSI-RX is not used")Reported-by Sashiko <[email protected]>Signed-off-by Fuad Tabba <[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 +0
-0
drivers/pci/controller/dwc/pcie-rcar-gen4.c static struct rcar_gen4_pcie *rcar_gen4_pcie_alloc(struct platform_device *pdev) · line 326
Quoted 5 lines
drivers/pci/controller/dwc/pcie-rcar-gen4.c +1
-1@@ -323,7 +323,7 @@ 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_node *msi_node __free(device_node) = NULL;
I think you have to call of_node_put() on msi_node(), so what about this instead ?
"
drivers/pci/controller/dwc/pcie-rcar-gen4.c +16 -7
@@ -382,20 +382,29 @@ static int rcar_gen4_pcie_host_msi_addr(struct dw_pcie_rp *pp, u32 *msi_addr)return -ENODEV ;/* Check if "msi-parent" or the "msi-map" points to ARM GICv3 ITS. */ -if (!of_device_is_compatible (msi_node,"arm,gic-v3-its" )) -return dev_err_probe (dev, -ENODEV ,"Compatible MSI controller not found\n" ); +if (!of_device_is_compatible (msi_node,"arm,gic-v3-its" )) { + ret =dev_err_probe (dev, -ENODEV ,"Compatible MSI controller not found\n" ); + goto exit; + }/* Derive GITS_TRANSLATER address from GICv3 */ ret =of_address_to_resource (msi_node,0 , &res); -if (ret <0 ) -return dev_err_probe (dev, ret,"MSI controller resources not obtained\n" ); +if (ret <0 ) { + ret =dev_err_probe (dev, ret,"MSI controller resources not obtained\n" ); + goto exit; + } addr = res.start +GITS_TRANSLATER ; -if (addr >=SZ_4G ) -return dev_err_probe (dev, -EINVAL ,"MSI controller address above 32bit range\n" ); +if (addr >=SZ_4G ) { + ret =dev_err_probe (dev, -EINVAL ,"MSI controller address above 32bit range\n" ); + goto exit; + } *msi_addr = addr; -return 0 ; + +exit: +of_node_put (msi_node); +return ret; }static int rcar_gen4_pcie_host_msi_init (struct dw_pcie_rp *pp)
"
Also, I think drivers/pci/controller/pcie-iproc.c iproc_pcie_msi_enable() needs similar fix ?
Hi Marek,
On Mon, 21 Sep 2026 22:47:30 +0200, Marek Vasut <[email protected]> wrote:
[...]
Quoted 2 lines
I think you have to call
of_node_put()onmsi_node(), so what about this instead ?
The __free(device_node) is that call: it puts msi_node on every return from the function, the success path included, so no goto is needed. It's the same scoped cleanup pci-imx6.c and pcie-rzg3s-host.c use for their device_node lookups.
Quoted 1 line
(quoted diff) +0
-0
[...]
Quoted 4 lines
"
Also, I think
drivers/pci/controller/pcie-iproc.ciproc_pcie_msi_enable()needs similar fix ?
I don't think so: iproc_pcie_msi_enable() already puts the node at out_put_node, on the steer failure and the success paths alike.
Cheers,
/fuad
On 9/22/26 8:38 AM, Fuad Tabba wrote:
Hello Fuad,
Quoted 8 lines · Marek Vasut
[...]
Quoted 2 lines
I think you have to call
of_node_put()onmsi_node(), so what about this instead ?The
__free(device_node)is that call: it putsmsi_nodeon every return from the function, the success path included, so no goto is needed. It's the same scoped cleanuppci-imx6.candpcie-rzg3s-host.cuse for theirdevice_nodelookups.
Oh, this is very nice, TIL, thank you.
Quoted 10 lines
Quoted 1 line
(quoted diff) +0
-0[...]
Quoted 4 lines
"
Also, I think
drivers/pci/controller/pcie-iproc.ciproc_pcie_msi_enable()needs similar fix ?I don't think so:
iproc_pcie_msi_enable()already puts the node atout_put_node, on the steer failure and the success paths alike.
Could you maybe send similar simplification patch ?
Thank you !
Signature · 2 lines
Best regards, Marek Vasut
Hi Marek,
On Tue, 22 Sept 2026 at 19:07, Marek Vasut <[email protected]> wrote:
[...]
Quoted 5 lines
Oh, this is very nice, TIL, thank you.
Reviewed-by Marek Vasut <[email protected]>R-Car V4H Sparrow Hawk
Thanks.
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
(quoted diff) +0
-0[...]
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
"
Also, I think
drivers/pci/controller/pcie-iproc.ciproc_pcie_msi_enable()needs similar fix ?I don't think so:
iproc_pcie_msi_enable()already puts the node atout_put_node, on the steer failure and the success paths alike.Could you maybe send similar simplification patch ?
Sure: https://lore.kernel.org/all/[email protected]/
Cheers,
/fuad
Quoted 6 lines
Thank you !
--
Best regards,
Marek Vasut