* [PATCH v2 net 1/4] net: ti: icssg-prueth: Fix device_node refcount leak in prueth_probe()
2026-11-10 6:41 [PATCH v2 net 0/4] net: ti: icssg: Fix device_node handling in prueth_probe() Xiangwu Lai
@ 2026-11-10 6:41 ` Xiangwu Lai
2026-11-10 6:41 ` [PATCH v2 net 2/4] net: ti: icssg-prueth-sr1: " Xiangwu Lai
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Xiangwu Lai @ 2026-11-10 6:41 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, danishanwar,
rogerq, jan.kiszka, diogo.ivo, haokexin, horms, linux-arm-kernel,
linux-kernel, Xiangwu Lai
prueth_probe() takes references on the eth0_node/eth1_node device nodes
with of_node_get() and stores them in prueth->eth_node[]. If either of
the "ti,mii-g-rt" or "ti,mii-rt" syscon regmap lookups fails, probe()
returns -ENODEV without dropping those references, leaking the device
nodes.
Jump to the existing put_cores label so the error path releases the
eth0_node/eth1_node references like all the other failure paths in the
function do.
Fixes: 128d5874c082 ("net: ti: icssg-prueth: Add ICSSG ethernet driver")
Signed-off-by: Xiangwu Lai <laixiangwu@cmss.chinamobile.com>
---
Changes in v2:
- Collect the two independent fixes into one series (suggested by
Simon Horman).
- No code change since v1.
Link: https://lore.kernel.org/netdev/20261030085651.1944-1-laixiangwu@cmss.chinamobile.com/
drivers/net/ethernet/ti/icssg/icssg_prueth.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
index 591be5c80..9b971d1df 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
@@ -2258,13 +2258,15 @@ static int prueth_probe(struct platform_device *pdev)
prueth->miig_rt = syscon_regmap_lookup_by_phandle(np, "ti,mii-g-rt");
if (IS_ERR(prueth->miig_rt)) {
dev_err(dev, "couldn't get ti,mii-g-rt syscon regmap\n");
- return -ENODEV;
+ ret = -ENODEV;
+ goto put_cores;
}
prueth->mii_rt = syscon_regmap_lookup_by_phandle(np, "ti,mii-rt");
if (IS_ERR(prueth->mii_rt)) {
dev_err(dev, "couldn't get ti,mii-rt syscon regmap\n");
- return -ENODEV;
+ ret = -ENODEV;
+ goto put_cores;
}
prueth->pa_stats = syscon_regmap_lookup_by_phandle(np, "ti,pa-stats");
--
2.50.1.windows.1
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v2 net 2/4] net: ti: icssg-prueth-sr1: Fix device_node refcount leak in prueth_probe()
2026-11-10 6:41 [PATCH v2 net 0/4] net: ti: icssg: Fix device_node handling in prueth_probe() Xiangwu Lai
2026-11-10 6:41 ` [PATCH v2 net 1/4] net: ti: icssg-prueth: Fix device_node refcount leak " Xiangwu Lai
@ 2026-11-10 6:41 ` Xiangwu Lai
2026-11-10 6:41 ` [PATCH v2 net 3/4] net: ti: icssg-prueth: Fix port scan issues " Xiangwu Lai
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Xiangwu Lai @ 2026-11-10 6:41 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, danishanwar,
rogerq, jan.kiszka, diogo.ivo, haokexin, horms, linux-arm-kernel,
linux-kernel, Xiangwu Lai
prueth_probe() takes references on the eth0_node/eth1_node device nodes
with of_node_get() and stores them in prueth->eth_node[]. If either of
the "ti,mii-g-rt" or "ti,mii-rt" syscon regmap lookups fails, probe()
returns -ENODEV without dropping those references, leaking the device
nodes.
Jump to the existing put_cores label so the error path releases the
eth0_node/eth1_node references like all the other failure paths in the
function do.
Fixes: e654b85a693e ("net: ti: icssg-prueth: Add ICSSG Ethernet driver for AM65x SR1.0 platforms")
Signed-off-by: Xiangwu Lai <laixiangwu@cmss.chinamobile.com>
---
Changes in v2:
- Collect the two independent fixes into one series (suggested by
Simon Horman).
- No code change since v1.
Link: https://lore.kernel.org/netdev/20261030085851.2019-1-laixiangwu@cmss.chinamobile.com/
drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c b/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c
index b8115ca47..ef1dc32ff 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c
@@ -963,13 +963,15 @@ static int prueth_probe(struct platform_device *pdev)
prueth->miig_rt = syscon_regmap_lookup_by_phandle(np, "ti,mii-g-rt");
if (IS_ERR(prueth->miig_rt)) {
dev_err(dev, "couldn't get ti,mii-g-rt syscon regmap\n");
- return -ENODEV;
+ ret = -ENODEV;
+ goto put_cores;
}
prueth->mii_rt = syscon_regmap_lookup_by_phandle(np, "ti,mii-rt");
if (IS_ERR(prueth->mii_rt)) {
dev_err(dev, "couldn't get ti,mii-rt syscon regmap\n");
- return -ENODEV;
+ ret = -ENODEV;
+ goto put_cores;
}
if (eth0_node) {
--
2.50.1.windows.1
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v2 net 3/4] net: ti: icssg-prueth: Fix port scan issues in prueth_probe()
2026-11-10 6:41 [PATCH v2 net 0/4] net: ti: icssg: Fix device_node handling in prueth_probe() Xiangwu Lai
2026-11-10 6:41 ` [PATCH v2 net 1/4] net: ti: icssg-prueth: Fix device_node refcount leak " Xiangwu Lai
2026-11-10 6:41 ` [PATCH v2 net 2/4] net: ti: icssg-prueth-sr1: " Xiangwu Lai
@ 2026-11-10 6:41 ` Xiangwu Lai
2026-11-10 6:41 ` [PATCH v2 net 4/4] net: ti: icssg-prueth-sr1: " Xiangwu Lai
2026-11-10 6:46 ` [PATCH v2 net 0/4] net: ti: icssg: Fix device_node handling " netdev-bot+sinfo
4 siblings, 0 replies; 7+ messages in thread
From: Xiangwu Lai @ 2026-11-10 6:41 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, danishanwar,
rogerq, jan.kiszka, diogo.ivo, haokexin, horms, linux-arm-kernel,
linux-kernel, Xiangwu Lai
The port scan loop in prueth_probe() has several issues:
- When reading the reg property of a port fails, the error is only
logged and the uninitialized value of reg is then used to decide
which slot the port node is stored in.
- of_node_get() is called on every port child before the reg value is
validated. If reg is neither 0 nor 1, the reference is never
released. If two ports use the same reg value, the second
assignment overwrites the first pointer and its reference is lost.
- The "port0 and port1 can't have same reg" check after the loop is
dead code: both variables are initialized to NULL, each iteration
assigns at most one of them, for_each_child_of_node() visits each
child exactly once, and the both-NULL case is handled by the
preceding check.
Fix the first issue by skipping a port when its reg property cannot
be read, and the second by taking the reference only when a port is
actually accepted. Reject duplicate reg values, which is what the
existing check intended but never caught, and remove the unreachable
check.
Fixes: 128d5874c082 ("net: ti: icssg-prueth: Add ICSSG ethernet driver")
Signed-off-by: Xiangwu Lai <laixiangwu@cmss.chinamobile.com>
---
drivers/net/ethernet/ti/icssg/icssg_prueth.c | 26 +++++++++++---------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
index 9b971d1df..c19a51174 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
@@ -2217,24 +2217,34 @@ static int prueth_probe(struct platform_device *pdev)
if (ret < 0) {
dev_err(dev, "%pOF error reading port_id %d\n",
eth_node, ret);
+ continue;
}
- of_node_get(eth_node);
+ if (reg != 0 && reg != 1) {
+ dev_err(dev, "port reg should be 0 or 1\n");
+ continue;
+ }
+
+ if ((reg == 0 && eth0_node) || (reg == 1 && eth1_node)) {
+ dev_err(dev, "port reg %d already in use\n", reg);
+ ret = -ENODEV;
+ of_node_put(eth_node);
+ of_node_put(eth_ports_node);
+ goto put_cores;
+ }
if (reg == 0) {
- eth0_node = eth_node;
+ eth0_node = of_node_get(eth_node);
if (!of_device_is_available(eth0_node)) {
of_node_put(eth0_node);
eth0_node = NULL;
}
} else if (reg == 1) {
- eth1_node = eth_node;
+ eth1_node = of_node_get(eth_node);
if (!of_device_is_available(eth1_node)) {
of_node_put(eth1_node);
eth1_node = NULL;
}
- } else {
- dev_err(dev, "port reg should be 0 or 1\n");
}
}
@@ -2246,12 +2256,6 @@ static int prueth_probe(struct platform_device *pdev)
return -ENODEV;
}
- if (eth0_node == eth1_node) {
- dev_err(dev, "port0 and port1 can't have same reg\n");
- of_node_put(eth0_node);
- return -ENODEV;
- }
-
prueth->eth_node[PRUETH_MAC0] = eth0_node;
prueth->eth_node[PRUETH_MAC1] = eth1_node;
--
2.50.1.windows.1
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v2 net 4/4] net: ti: icssg-prueth-sr1: Fix port scan issues in prueth_probe()
2026-11-10 6:41 [PATCH v2 net 0/4] net: ti: icssg: Fix device_node handling in prueth_probe() Xiangwu Lai
` (2 preceding siblings ...)
2026-11-10 6:41 ` [PATCH v2 net 3/4] net: ti: icssg-prueth: Fix port scan issues " Xiangwu Lai
@ 2026-11-10 6:41 ` Xiangwu Lai
2026-11-10 6:46 ` [PATCH v2 net 0/4] net: ti: icssg: Fix device_node handling " netdev-bot+sinfo
4 siblings, 0 replies; 7+ messages in thread
From: Xiangwu Lai @ 2026-11-10 6:41 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, danishanwar,
rogerq, jan.kiszka, diogo.ivo, haokexin, horms, linux-arm-kernel,
linux-kernel, Xiangwu Lai
The port scan loop in prueth_probe() has several issues:
- When reading the reg property of a port fails, the error is only
logged and the uninitialized value of reg is then used to decide
which slot the port node is stored in.
- of_node_get() is called on every port child before the reg value is
validated. If reg is neither 0 nor 1, the reference is never
released. If two ports use the same reg value, the second
assignment overwrites the first pointer and its reference is lost.
- The "port0 and port1 can't have same reg" check after the loop is
dead code: both variables are initialized to NULL, each iteration
assigns at most one of them, for_each_child_of_node() visits each
child exactly once, and the both-NULL case is handled by the
preceding check.
Fix the first issue by skipping a port when its reg property cannot
be read, and the second by taking the reference only when a port is
actually accepted. Reject duplicate reg values, which is what the
existing check intended but never caught, and remove the unreachable
check.
Fixes: e654b85a693e ("net: ti: icssg-prueth: Add ICSSG Ethernet driver for AM65x SR1.0 platforms")
Signed-off-by: Xiangwu Lai <laixiangwu@cmss.chinamobile.com>
---
.../net/ethernet/ti/icssg/icssg_prueth_sr1.c | 26 +++++++++++--------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c b/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c
index ef1dc32ff..1a9dd70b2 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c
@@ -922,24 +922,34 @@ static int prueth_probe(struct platform_device *pdev)
if (ret < 0) {
dev_err(dev, "%pOF error reading port_id %d\n",
eth_node, ret);
+ continue;
}
- of_node_get(eth_node);
+ if (reg != 0 && reg != 1) {
+ dev_err(dev, "port reg should be 0 or 1\n");
+ continue;
+ }
+
+ if ((reg == 0 && eth0_node) || (reg == 1 && eth1_node)) {
+ dev_err(dev, "port reg %d already in use\n", reg);
+ ret = -ENODEV;
+ of_node_put(eth_node);
+ of_node_put(eth_ports_node);
+ goto put_cores;
+ }
if (reg == 0) {
- eth0_node = eth_node;
+ eth0_node = of_node_get(eth_node);
if (!of_device_is_available(eth0_node)) {
of_node_put(eth0_node);
eth0_node = NULL;
}
} else if (reg == 1) {
- eth1_node = eth_node;
+ eth1_node = of_node_get(eth_node);
if (!of_device_is_available(eth1_node)) {
of_node_put(eth1_node);
eth1_node = NULL;
}
- } else {
- dev_err(dev, "port reg should be 0 or 1\n");
}
}
@@ -951,12 +961,6 @@ static int prueth_probe(struct platform_device *pdev)
return -ENODEV;
}
- if (eth0_node == eth1_node) {
- dev_err(dev, "port0 and port1 can't have same reg\n");
- of_node_put(eth0_node);
- return -ENODEV;
- }
-
prueth->eth_node[PRUETH_MAC0] = eth0_node;
prueth->eth_node[PRUETH_MAC1] = eth1_node;
--
2.50.1.windows.1
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v2 net 0/4] net: ti: icssg: Fix device_node handling in prueth_probe()
2026-11-10 6:41 [PATCH v2 net 0/4] net: ti: icssg: Fix device_node handling in prueth_probe() Xiangwu Lai
` (3 preceding siblings ...)
2026-11-10 6:41 ` [PATCH v2 net 4/4] net: ti: icssg-prueth-sr1: " Xiangwu Lai
@ 2026-11-10 6:46 ` netdev-bot+sinfo
2026-11-10 7:31 ` Xiangwu Lai
4 siblings, 1 reply; 7+ messages in thread
From: netdev-bot+sinfo @ 2026-11-10 6:46 UTC (permalink / raw)
To: Xiangwu Lai
Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni,
danishanwar, rogerq, jan.kiszka, diogo.ivo, haokexin, horms,
linux-arm-kernel, linux-kernel
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical
(e.g. found by code inspection). If it was triggered please include
the symptoms, like the stack trace or error messages.
- What hardware the change was tested on. For driver fixes please
mention the device (and if relevant firmware version) used for
testing, or say that the change was not tested on real hardware.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account. If the series needs another revision for
other reasons, please include the information in the commit messages
then.
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v2 net 0/4] net: ti: icssg: Fix device_node handling in prueth_probe()
2026-11-10 6:46 ` [PATCH v2 net 0/4] net: ti: icssg: Fix device_node handling " netdev-bot+sinfo
@ 2026-11-10 7:31 ` Xiangwu Lai
0 siblings, 0 replies; 7+ messages in thread
From: Xiangwu Lai @ 2026-11-10 7:31 UTC (permalink / raw)
To: netdev-bot+sinfo
Cc: Xiangwu Lai, netdev, andrew+netdev, davem, edumazet, kuba,
pabeni, danishanwar, rogerq, jan.kiszka, diogo.ivo, haokexin,
horms, linux-arm-kernel, linux-kernel
Hi,
Please find below the additional information requested for this
series. The same information was provided for the v1 postings of
patches 1 and 2 here:
https://lore.kernel.org/netdev/20261109093000.54321-laixiangwu@cmss.chinamobile.com/
https://lore.kernel.org/netdev/20261109093500.54322-laixiangwu@cmss.chinamobile.com/
How the issues were discovered: manual code inspection of the error
paths in prueth_probe() while auditing both ICSSG drivers for
probe-time resource leaks. The port scan issues addressed by
patches 3 and 4 were found in the same audit; the use of the
uninitialized reg value was also raised during the review of v1.
Whether the issues were actually triggered: no, they are purely
theoretical, all of them require a malformed device tree:
- Patches 1 and 2: the leak triggers only when the "ti,mii-g-rt" or
"ti,mii-rt" syscon regmap lookup fails, which does not happen on
a valid DT. probe() then fails with -ENODEV and the references
taken on eth0_node/eth1_node are leaked silently; there is no
stack trace or error message pointing at the leak itself.
- Patches 3 and 4: the uninitialized reg value is only used when a
port node has no reg property, and a reference is only leaked for
port nodes with a reg value outside 0/1 or with a duplicate reg
value. On a valid DT (one port with reg 0 and one with reg 1) the
loop behaves as before, with identical reference accounting for
the accepted ports.
Hardware the change was tested on: none, the series was not tested
on real hardware. Patches 1 and 2 only re-route two error branches
to the existing put_cores label, which is already exercised by the
other failure paths in the same function (e.g. prueth_get_cores()
failures). Patches 3 and 4 move of_node_get() from an unconditional
call on every port child to the assignment points, so for ports
that are accepted the reference accounting is unchanged, and the
new error path only releases references it has just taken.
Best regards,
Xiangwu Lai
^ permalink raw reply [flat|nested] 7+ messages in thread