* [PATCH net] net: phylink: put link_gpio if phylink_create fails
@ 2026-07-26 15:08 Christian Marangi
2026-07-26 16:50 ` Andrew Lunn
2026-07-29 2:00 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Christian Marangi @ 2026-07-26 15:08 UTC (permalink / raw)
To: Russell King, Andrew Lunn, Heiner Kallweit, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel
Cc: Christian Marangi
In phylink_create() if phylink_register_sfp() returns an error, link_gpio
obtained by phylink_parse_fixedlink() is never released. While this is a
very unlikely scenario, it's worth to fix/handle this.
This was present from the very first implementation of phylink but got
relevant only with the introduction of ce0aa27ff3f6 ("sfp: add sfp-bus to
bridge between network devices and sfp cages") where additional function
were added after phylink_parse_fixedlink() making the release of link_gpio
needed if such additional function errored out.
While at it, restructure the exit condition of phylink_create() with the
goto pattern to reduce code duplication on handling error conditions.
Fixes: ce0aa27ff3f6 ("sfp: add sfp-bus to bridge between network devices and sfp cages")
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
drivers/net/phy/phylink.c | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 59dfe35afa54..f40acc0d4133 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -1874,8 +1874,8 @@ struct phylink *phylink_create(struct phylink_config *config,
} else if (config->type == PHYLINK_DEV) {
pl->dev = config->dev;
} else {
- kfree(pl);
- return ERR_PTR(-EINVAL);
+ ret = -EINVAL;
+ goto free_pl;
}
pl->mac_supports_eee_ops = phylink_mac_implements_lpi(mac_ops);
@@ -1908,28 +1908,29 @@ struct phylink *phylink_create(struct phylink_config *config,
phylink_validate(pl, pl->supported, &pl->link_config);
ret = phylink_parse_mode(pl, fwnode);
- if (ret < 0) {
- kfree(pl);
- return ERR_PTR(ret);
- }
+ if (ret < 0)
+ goto free_pl;
if (pl->cfg_link_an_mode == MLO_AN_FIXED) {
ret = phylink_parse_fixedlink(pl, fwnode);
- if (ret < 0) {
- kfree(pl);
- return ERR_PTR(ret);
- }
+ if (ret < 0)
+ goto release_link_gpio;
}
pl->req_link_an_mode = pl->cfg_link_an_mode;
ret = phylink_register_sfp(pl, fwnode);
- if (ret < 0) {
- kfree(pl);
- return ERR_PTR(ret);
- }
+ if (ret < 0)
+ goto release_link_gpio;
return pl;
+
+release_link_gpio:
+ if (pl->link_gpio)
+ gpiod_put(pl->link_gpio);
+free_pl:
+ kfree(pl);
+ return ERR_PTR(ret);
}
EXPORT_SYMBOL_GPL(phylink_create);
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net] net: phylink: put link_gpio if phylink_create fails
2026-07-26 15:08 [PATCH net] net: phylink: put link_gpio if phylink_create fails Christian Marangi
@ 2026-07-26 16:50 ` Andrew Lunn
2026-07-29 2:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2026-07-26 16:50 UTC (permalink / raw)
To: Christian Marangi
Cc: Russell King, Heiner Kallweit, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, netdev, linux-kernel
On Sun, Jul 26, 2026 at 05:08:05PM +0200, Christian Marangi wrote:
> In phylink_create() if phylink_register_sfp() returns an error, link_gpio
> obtained by phylink_parse_fixedlink() is never released. While this is a
> very unlikely scenario, it's worth to fix/handle this.
>
> This was present from the very first implementation of phylink but got
> relevant only with the introduction of ce0aa27ff3f6 ("sfp: add sfp-bus to
> bridge between network devices and sfp cages") where additional function
> were added after phylink_parse_fixedlink() making the release of link_gpio
> needed if such additional function errored out.
>
> While at it, restructure the exit condition of phylink_create() with the
> goto pattern to reduce code duplication on handling error conditions.
>
> Fixes: ce0aa27ff3f6 ("sfp: add sfp-bus to bridge between network devices and sfp cages")
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net] net: phylink: put link_gpio if phylink_create fails
2026-07-26 15:08 [PATCH net] net: phylink: put link_gpio if phylink_create fails Christian Marangi
2026-07-26 16:50 ` Andrew Lunn
@ 2026-07-29 2:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-07-29 2:00 UTC (permalink / raw)
To: Christian Marangi
Cc: linux, andrew, hkallweit1, davem, edumazet, kuba, pabeni, netdev,
linux-kernel
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Sun, 26 Jul 2026 17:08:05 +0200 you wrote:
> In phylink_create() if phylink_register_sfp() returns an error, link_gpio
> obtained by phylink_parse_fixedlink() is never released. While this is a
> very unlikely scenario, it's worth to fix/handle this.
>
> This was present from the very first implementation of phylink but got
> relevant only with the introduction of ce0aa27ff3f6 ("sfp: add sfp-bus to
> bridge between network devices and sfp cages") where additional function
> were added after phylink_parse_fixedlink() making the release of link_gpio
> needed if such additional function errored out.
>
> [...]
Here is the summary with links:
- [net] net: phylink: put link_gpio if phylink_create fails
https://git.kernel.org/netdev/net/c/0fe1e3e8f338
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-29 2:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-26 15:08 [PATCH net] net: phylink: put link_gpio if phylink_create fails Christian Marangi
2026-07-26 16:50 ` Andrew Lunn
2026-07-29 2:00 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox