Skip to contentSkip to conversation

PCI: rcar-gen4: Fix device_node leak in rcar_gen4_pcie_host_msi_addr()

PATCH Applied Fuad Tabba 5 participants 6 messages Sep 23 – Oct 27

Subsystems (4)
lore
Share & tools
lore

Fuad Tabba

author
#0 lore raw

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
index fbe465a29068f..bb2fcfd6861ac 100644
@@ -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
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines

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.

Quoted 6 lines

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
#2 lore raw
In reply to Fuad Tabba
Quoted 6 lines · Fuad Tabba

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.

Quoted 6 lines

I liked V1 a bit better, but either way works.

Reviewed-by on v2 1/1
#3 lore raw
In reply to Fuad Tabba
Quoted 6 lines · On Wed, 23 Sep 2026 19:07:49 +0100 Fuad Tabba <[email protected]> wrote:

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.

Quoted 6 lines
Quoted 36 lines

---

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
index fbe465a29068f..bb2fcfd6861ac 100644
@@ -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

maintainer Applied
#5 lore raw
In reply to Fuad Tabba
Quoted 1 line · Fuad Tabba

PCI: rcar-gen4: Fix device_node leak in rcar_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
மணிவண்ணன் சதாசிவம்