Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH 0/3] PCI: keystone: Fix device node leaks in syscon phandle parsing
@ 2026-11-10 10:09 zhaofeng2
  2026-11-10 10:09 ` [PATCH 1/3] PCI: keystone: Fix device node leak in ks_pcie_init_id() zhaofeng2
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: zhaofeng2 @ 2026-11-10 10:09 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Zhao Feng, linux-pci, Nishanth Menon, Santosh Shilimkar,
	Vignesh Raghavendra, linux-arm-kernel, linux-kernel

From: Zhao Feng <zhaofeng2@cmss.chinamobile.com>

ks_pcie_init_id(), ks_pcie_set_mode() and ks_pcie_am654_set_mode()
resolve the "ti,syscon-pcie-id" / "ti,syscon-pcie-mode" phandles with
of_parse_phandle_with_fixed_args(), which takes a reference on the
syscon device node, but none of them drops that reference after the
register offset has been read from args.args[0], so the syscon node
is leaked on every probe.

All three call sites were introduced by the same commit, which
switched the driver from syscon_regmap_lookup_by_phandle() to
of_parse_phandle_with_fixed_args() in order to obtain the register
offset from the phandle argument.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] PCI: keystone: Fix device node leak in ks_pcie_init_id()
  2026-11-10 10:09 [PATCH 0/3] PCI: keystone: Fix device node leaks in syscon phandle parsing zhaofeng2
@ 2026-11-10 10:09 ` zhaofeng2
  2026-11-10 10:19   ` sashiko-bot
  2026-11-10 10:09 ` [PATCH 2/3] PCI: keystone: Fix device node leak in ks_pcie_set_mode() zhaofeng2
  2026-11-10 10:09 ` [PATCH 3/3] PCI: keystone: Fix device node leak in ks_pcie_am654_set_mode() zhaofeng2
  2 siblings, 1 reply; 7+ messages in thread
From: zhaofeng2 @ 2026-11-10 10:09 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Zhao Feng, linux-pci, Nishanth Menon, Santosh Shilimkar,
	Vignesh Raghavendra, linux-arm-kernel, linux-kernel

From: Zhao Feng <zhaofeng2@cmss.chinamobile.com>

ks_pcie_init_id() resolves the "ti,syscon-pcie-id" phandle with
of_parse_phandle_with_fixed_args() to obtain the device-id register
offset, which takes a reference on the syscon device node, but the
reference is never dropped after the offset has been read from
args.args[0], so the syscon node is leaked on every probe.

Drop the reference with of_node_put() once the offset argument has
been consumed.

Fixes: 7dcf07ac8867 ("PCI: keystone: Use phandle argument from "ti,syscon-pcie-id"/"ti,syscon-pcie-mode"")
Signed-off-by: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
---
 drivers/pci/controller/dwc/pci-keystone.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/pci/controller/dwc/pci-keystone.c b/drivers/pci/controller/dwc/pci-keystone.c
--- a/drivers/pci/controller/dwc/pci-keystone.c
+++ b/drivers/pci/controller/dwc/pci-keystone.c
@@ -795,8 +795,10 @@
 
 	/* Do not error out to maintain old DT compatibility */
 	ret = of_parse_phandle_with_fixed_args(np, "ti,syscon-pcie-id", 1, 0, &args);
-	if (!ret)
+	if (!ret) {
 		offset = args.args[0];
+		of_node_put(args.np);
+	}
 
 	ret = regmap_read(devctrl_regs, offset, &id);
 	if (ret)



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/3] PCI: keystone: Fix device node leak in ks_pcie_set_mode()
  2026-11-10 10:09 [PATCH 0/3] PCI: keystone: Fix device node leaks in syscon phandle parsing zhaofeng2
  2026-11-10 10:09 ` [PATCH 1/3] PCI: keystone: Fix device node leak in ks_pcie_init_id() zhaofeng2
@ 2026-11-10 10:09 ` zhaofeng2
  2026-11-10 10:18   ` sashiko-bot
  2026-11-10 10:09 ` [PATCH 3/3] PCI: keystone: Fix device node leak in ks_pcie_am654_set_mode() zhaofeng2
  2 siblings, 1 reply; 7+ messages in thread
From: zhaofeng2 @ 2026-11-10 10:09 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Zhao Feng, linux-pci, Nishanth Menon, Santosh Shilimkar,
	Vignesh Raghavendra, linux-arm-kernel, linux-kernel

From: Zhao Feng <zhaofeng2@cmss.chinamobile.com>

ks_pcie_set_mode() resolves the "ti,syscon-pcie-mode" phandle with
of_parse_phandle_with_fixed_args() to obtain the mode register
offset, which takes a reference on the syscon device node, but the
reference is never dropped after the offset has been read from
args.args[0], so the syscon node is leaked on every probe.

Drop the reference with of_node_put() once the offset argument has
been consumed.

Fixes: 7dcf07ac8867 ("PCI: keystone: Use phandle argument from "ti,syscon-pcie-id"/"ti,syscon-pcie-mode"")
Signed-off-by: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
---
 drivers/pci/controller/dwc/pci-keystone.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/pci/controller/dwc/pci-keystone.c b/drivers/pci/controller/dwc/pci-keystone.c
--- a/drivers/pci/controller/dwc/pci-keystone.c
+++ b/drivers/pci/controller/dwc/pci-keystone.c
@@ -1027,8 +1027,10 @@
 
 	/* Do not error out to maintain old DT compatibility */
 	ret = of_parse_phandle_with_fixed_args(np, "ti,syscon-pcie-mode", 1, 0, &args);
-	if (!ret)
+	if (!ret) {
 		offset = args.args[0];
+		of_node_put(args.np);
+	}
 
 	mask = KS_PCIE_DEV_TYPE_MASK | KS_PCIE_SYSCLOCKOUTEN;
 	val = KS_PCIE_DEV_TYPE(RC) | KS_PCIE_SYSCLOCKOUTEN;



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/3] PCI: keystone: Fix device node leak in ks_pcie_am654_set_mode()
  2026-11-10 10:09 [PATCH 0/3] PCI: keystone: Fix device node leaks in syscon phandle parsing zhaofeng2
  2026-11-10 10:09 ` [PATCH 1/3] PCI: keystone: Fix device node leak in ks_pcie_init_id() zhaofeng2
  2026-11-10 10:09 ` [PATCH 2/3] PCI: keystone: Fix device node leak in ks_pcie_set_mode() zhaofeng2
@ 2026-11-10 10:09 ` zhaofeng2
  2026-11-10 10:14   ` sashiko-bot
  2 siblings, 1 reply; 7+ messages in thread
From: zhaofeng2 @ 2026-11-10 10:09 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Zhao Feng, linux-pci, Nishanth Menon, Santosh Shilimkar,
	Vignesh Raghavendra, linux-arm-kernel, linux-kernel

From: Zhao Feng <zhaofeng2@cmss.chinamobile.com>

ks_pcie_am654_set_mode() resolves the "ti,syscon-pcie-mode" phandle
with of_parse_phandle_with_fixed_args() to obtain the mode register
offset, which takes a reference on the syscon device node, but the
reference is never dropped after the offset has been read from
args.args[0], so the syscon node is leaked on every probe.

Drop the reference with of_node_put() once the offset argument has
been consumed.

Fixes: 7dcf07ac8867 ("PCI: keystone: Use phandle argument from "ti,syscon-pcie-id"/"ti,syscon-pcie-mode"")
Signed-off-by: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
---
 drivers/pci/controller/dwc/pci-keystone.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/pci/controller/dwc/pci-keystone.c b/drivers/pci/controller/dwc/pci-keystone.c
--- a/drivers/pci/controller/dwc/pci-keystone.c
+++ b/drivers/pci/controller/dwc/pci-keystone.c
@@ -1059,8 +1059,10 @@
 
 	/* Do not error out to maintain old DT compatibility */
 	ret = of_parse_phandle_with_fixed_args(np, "ti,syscon-pcie-mode", 1, 0, &args);
-	if (!ret)
+	if (!ret) {
 		offset = args.args[0];
+		of_node_put(args.np);
+	}
 
 	mask = AM654_PCIE_DEV_TYPE_MASK;
 



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] PCI: keystone: Fix device node leak in ks_pcie_am654_set_mode()
  2026-11-10 10:09 ` [PATCH 3/3] PCI: keystone: Fix device node leak in ks_pcie_am654_set_mode() zhaofeng2
@ 2026-11-10 10:14   ` sashiko-bot
  0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-10 10:14 UTC (permalink / raw)
  To: zhaofeng2; +Cc: linux-pci

> From: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
> 
> ks_pcie_am654_set_mode() resolves the "ti,syscon-pcie-mode" phandle
> with of_parse_phandle_with_fixed_args() to obtain the mode register
> offset, which takes a reference on the syscon device node, but the
> reference is never dropped after the offset has been read from
> args.args[0], so the syscon node is leaked on every probe.
> 
> Drop the reference with of_node_put() once the offset argument has
> been consumed.
> 
> Fixes: 7dcf07ac8867 ("PCI: keystone: Use phandle argument from "ti,syscon-pcie-id"/"ti,syscon-pcie-mode"")
> Signed-off-by: Zhao Feng <zhaofeng2@cmss.chinamobile.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261110100955.1046-1-zhaofeng2@cmss.chinamobile.com?part=3


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] PCI: keystone: Fix device node leak in ks_pcie_set_mode()
  2026-11-10 10:09 ` [PATCH 2/3] PCI: keystone: Fix device node leak in ks_pcie_set_mode() zhaofeng2
@ 2026-11-10 10:18   ` sashiko-bot
  0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-10 10:18 UTC (permalink / raw)
  To: zhaofeng2; +Cc: linux-pci

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Medium] PCI: keystone: OF node leak in ks_pcie_init_id() [1]
--

commit adfea56e642f99fd836f33feabf3e85f9ea278a1
Author: Zhao Feng <zhaofeng2@cmss.chinamobile.com>

PCI: keystone: Fix device node leak in ks_pcie_set_mode()

This commit adds an of_node_put() call in ks_pcie_set_mode() to drop the
syscon device node reference acquired by
of_parse_phandle_with_fixed_args().

> diff --git a/drivers/pci/controller/dwc/pci-keystone.c b/drivers/pci/controller/dwc/pci-keystone.c
> index 832589152570a..12c6f7d9a64bf 100644
> --- a/drivers/pci/controller/dwc/pci-keystone.c
> +++ b/drivers/pci/controller/dwc/pci-keystone.c
> @@ -1029,8 +1029,10 @@ static int ks_pcie_set_mode(struct device *dev)
>  
>  	/* Do not error out to maintain old DT compatibility */
>  	ret = of_parse_phandle_with_fixed_args(np, "ti,syscon-pcie-mode", 1, 0, &args);
> -	if (!ret)
> +	if (!ret) {
>  		offset = args.args[0];
> +		of_node_put(args.np);
> +	}

[Severity: Medium]
This problem wasn't introduced by this patch, but does the same
args.np device node reference leak [1] remain in ks_pcie_init_id()
and ks_pcie_am654_set_mode()?  Both functions also call
of_parse_phandle_with_fixed_args() to read args.args[0] without calling
of_node_put(args.np), leaking the syscon node reference on probe.

[1] https://sashiko.dev/#/bug/linux-2281dc7f-5c66-431f-8423-64e501436da0

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261110100955.1046-1-zhaofeng2@cmss.chinamobile.com?part=2

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] PCI: keystone: Fix device node leak in ks_pcie_init_id()
  2026-11-10 10:09 ` [PATCH 1/3] PCI: keystone: Fix device node leak in ks_pcie_init_id() zhaofeng2
@ 2026-11-10 10:19   ` sashiko-bot
  0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-10 10:19 UTC (permalink / raw)
  To: zhaofeng2; +Cc: linux-pci

> From: Zhao Feng <zhaofeng2@cmss.chinamobile.com>
> 
> ks_pcie_init_id() resolves the "ti,syscon-pcie-id" phandle with
> of_parse_phandle_with_fixed_args() to obtain the device-id register
> offset, which takes a reference on the syscon device node, but the
> reference is never dropped after the offset has been read from
> args.args[0], so the syscon node is leaked on every probe.
> 
> Drop the reference with of_node_put() once the offset argument has
> been consumed.
> 
> Fixes: 7dcf07ac8867 ("PCI: keystone: Use phandle argument from "ti,syscon-pcie-id"/"ti,syscon-pcie-mode"")
> Signed-off-by: Zhao Feng <zhaofeng2@cmss.chinamobile.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261110100955.1046-1-zhaofeng2@cmss.chinamobile.com?part=1


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-10 10:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-10 10:09 [PATCH 0/3] PCI: keystone: Fix device node leaks in syscon phandle parsing zhaofeng2
2026-11-10 10:09 ` [PATCH 1/3] PCI: keystone: Fix device node leak in ks_pcie_init_id() zhaofeng2
2026-11-10 10:19   ` sashiko-bot
2026-11-10 10:09 ` [PATCH 2/3] PCI: keystone: Fix device node leak in ks_pcie_set_mode() zhaofeng2
2026-11-10 10:18   ` sashiko-bot
2026-11-10 10:09 ` [PATCH 3/3] PCI: keystone: Fix device node leak in ks_pcie_am654_set_mode() zhaofeng2
2026-11-10 10:14   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox