net: phylink: put link_gpio if phylink_create fails
authorChristian Marangi <ansuelsmth@gmail.com>
Sun, 26 Jul 2026 15:08:05 +0000 (17:08 +0200)
committerJakub Kicinski <kuba@kernel.org>
Wed, 29 Jul 2026 01:31:11 +0000 (18:31 -0700)
commit0fe1e3e8f3380d7862296a73b528d164e96c76b8
tree81a16f301a47af2cf8363d74d5db355a28245a07
parent0408e7f6f6a1af236ca32e668f5f3f5833bec5af
net: phylink: put link_gpio if phylink_create fails

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>
Link: https://patch.msgid.link/20260726150806.2437-1-ansuelsmth@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/phy/phylink.c