* [PATCH net v2] net:thunder:Fix resource leaks in device_for_each_child_node() loops
@ 2023-07-06 12:30 ` Wang Ming
0 siblings, 0 replies; 4+ messages in thread
From: Wang Ming @ 2023-07-06 12:30 UTC (permalink / raw)
To: Sunil Goutham, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-arm-kernel, netdev, linux-kernel
Cc: opensource.kernel, simon.horman, Wang Ming
The device_for_each_child_node() loop in
bgx_init_of_phy() function should have
fwnode_handle_put() before break
which could avoid resource leaks.
This patch could fix this bug.
Signed-off-by: Wang Ming <machel@vivo.com>
---
drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
index a317feb8decb..f8a8b2ab72aa 100644
--- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
+++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
@@ -1469,6 +1469,7 @@ static int bgx_init_of_phy(struct bgx *bgx)
struct fwnode_handle *fwn;
struct device_node *node = NULL;
u8 lmac = 0;
+ int err = 0;
device_for_each_child_node(&bgx->pdev->dev, fwn) {
struct phy_device *pd;
@@ -1479,7 +1480,7 @@ static int bgx_init_of_phy(struct bgx *bgx)
*/
node = to_of_node(fwn);
if (!node)
- break;
+ goto out_handle_put;
of_get_mac_address(node, bgx->lmac[lmac].mac);
@@ -1501,10 +1502,8 @@ static int bgx_init_of_phy(struct bgx *bgx)
}
lmac++;
- if (lmac == bgx->max_lmac) {
- of_node_put(node);
- break;
- }
+ if (lmac == bgx->max_lmac)
+ goto out_node_put;
}
return 0;
@@ -1519,8 +1518,12 @@ static int bgx_init_of_phy(struct bgx *bgx)
}
lmac--;
}
+ err = -EPROBE_DEFER;
+out_node_put:
of_node_put(node);
- return -EPROBE_DEFER;
+out_handle_put:
+ fwnode_handle_put(fwn);
+ return err;
}
#else
--
2.25.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net v2] net:thunder:Fix resource leaks in device_for_each_child_node() loops
@ 2023-07-06 12:30 ` Wang Ming
0 siblings, 0 replies; 4+ messages in thread
From: Wang Ming @ 2023-07-06 12:30 UTC (permalink / raw)
To: Sunil Goutham, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-arm-kernel, netdev, linux-kernel
Cc: opensource.kernel, simon.horman, Wang Ming
The device_for_each_child_node() loop in
bgx_init_of_phy() function should have
fwnode_handle_put() before break
which could avoid resource leaks.
This patch could fix this bug.
Signed-off-by: Wang Ming <machel@vivo.com>
---
drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
index a317feb8decb..f8a8b2ab72aa 100644
--- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
+++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
@@ -1469,6 +1469,7 @@ static int bgx_init_of_phy(struct bgx *bgx)
struct fwnode_handle *fwn;
struct device_node *node = NULL;
u8 lmac = 0;
+ int err = 0;
device_for_each_child_node(&bgx->pdev->dev, fwn) {
struct phy_device *pd;
@@ -1479,7 +1480,7 @@ static int bgx_init_of_phy(struct bgx *bgx)
*/
node = to_of_node(fwn);
if (!node)
- break;
+ goto out_handle_put;
of_get_mac_address(node, bgx->lmac[lmac].mac);
@@ -1501,10 +1502,8 @@ static int bgx_init_of_phy(struct bgx *bgx)
}
lmac++;
- if (lmac == bgx->max_lmac) {
- of_node_put(node);
- break;
- }
+ if (lmac == bgx->max_lmac)
+ goto out_node_put;
}
return 0;
@@ -1519,8 +1518,12 @@ static int bgx_init_of_phy(struct bgx *bgx)
}
lmac--;
}
+ err = -EPROBE_DEFER;
+out_node_put:
of_node_put(node);
- return -EPROBE_DEFER;
+out_handle_put:
+ fwnode_handle_put(fwn);
+ return err;
}
#else
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net v2] net:thunder:Fix resource leaks in device_for_each_child_node() loops
2023-07-06 12:30 ` Wang Ming
@ 2023-07-06 15:48 ` Jakub Kicinski
-1 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2023-07-06 15:48 UTC (permalink / raw)
To: Wang Ming
Cc: Sunil Goutham, David S. Miller, Eric Dumazet, Paolo Abeni,
linux-arm-kernel, netdev, linux-kernel, opensource.kernel,
simon.horman
On Thu, 6 Jul 2023 20:30:11 +0800 Wang Ming wrote:
> The device_for_each_child_node() loop in
> bgx_init_of_phy() function should have
> fwnode_handle_put() before break
> which could avoid resource leaks.
> This patch could fix this bug.
Don't ignore previous feedback
--
pw-bot: cr
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net v2] net:thunder:Fix resource leaks in device_for_each_child_node() loops
@ 2023-07-06 15:48 ` Jakub Kicinski
0 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2023-07-06 15:48 UTC (permalink / raw)
To: Wang Ming
Cc: Sunil Goutham, David S. Miller, Eric Dumazet, Paolo Abeni,
linux-arm-kernel, netdev, linux-kernel, opensource.kernel,
simon.horman
On Thu, 6 Jul 2023 20:30:11 +0800 Wang Ming wrote:
> The device_for_each_child_node() loop in
> bgx_init_of_phy() function should have
> fwnode_handle_put() before break
> which could avoid resource leaks.
> This patch could fix this bug.
Don't ignore previous feedback
--
pw-bot: cr
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-07-06 15:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-06 12:30 [PATCH net v2] net:thunder:Fix resource leaks in device_for_each_child_node() loops Wang Ming
2023-07-06 12:30 ` Wang Ming
2023-07-06 15:48 ` Jakub Kicinski
2023-07-06 15:48 ` Jakub Kicinski
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.