* [PATCH] net: phy: phylink: check the return value of phylink_validate()
@ 2022-02-25 9:12 Jia-Ju Bai
2022-02-25 9:19 ` Russell King (Oracle)
0 siblings, 1 reply; 2+ messages in thread
From: Jia-Ju Bai @ 2022-02-25 9:12 UTC (permalink / raw)
To: linux, andrew, hkallweit1, davem, kuba; +Cc: netdev, linux-kernel, Jia-Ju Bai
The function phylink_validate() can fail, so its return value should be
checked.
Fixes: 9525ae83959b ("phylink: add phylink infrastructure")
Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
drivers/net/phy/phylink.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 420201858564..597f7579b29f 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -584,7 +584,9 @@ static int phylink_parse_fixedlink(struct phylink *pl,
bitmap_fill(pl->supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
linkmode_copy(pl->link_config.advertising, pl->supported);
- phylink_validate(pl, pl->supported, &pl->link_config);
+ ret = phylink_validate(pl, pl->supported, &pl->link_config);
+ if (ret)
+ return ret;
s = phy_lookup_setting(pl->link_config.speed, pl->link_config.duplex,
pl->supported, true);
@@ -1261,7 +1263,11 @@ struct phylink *phylink_create(struct phylink_config *config,
bitmap_fill(pl->supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
linkmode_copy(pl->link_config.advertising, pl->supported);
- phylink_validate(pl, pl->supported, &pl->link_config);
+ ret = phylink_validate(pl, pl->supported, &pl->link_config);
+ if (ret < 0) {
+ kfree(pl);
+ return ERR_PTR(ret);
+ }
ret = phylink_parse_mode(pl, fwnode);
if (ret < 0) {
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] net: phy: phylink: check the return value of phylink_validate()
2022-02-25 9:12 [PATCH] net: phy: phylink: check the return value of phylink_validate() Jia-Ju Bai
@ 2022-02-25 9:19 ` Russell King (Oracle)
0 siblings, 0 replies; 2+ messages in thread
From: Russell King (Oracle) @ 2022-02-25 9:19 UTC (permalink / raw)
To: Jia-Ju Bai; +Cc: andrew, hkallweit1, davem, kuba, netdev, linux-kernel
On Fri, Feb 25, 2022 at 01:12:46AM -0800, Jia-Ju Bai wrote:
> The function phylink_validate() can fail, so its return value should be
> checked.
>
> Fixes: 9525ae83959b ("phylink: add phylink infrastructure")
> Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
> drivers/net/phy/phylink.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 420201858564..597f7579b29f 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
> @@ -584,7 +584,9 @@ static int phylink_parse_fixedlink(struct phylink *pl,
>
> bitmap_fill(pl->supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
> linkmode_copy(pl->link_config.advertising, pl->supported);
> - phylink_validate(pl, pl->supported, &pl->link_config);
> + ret = phylink_validate(pl, pl->supported, &pl->link_config);
> + if (ret)
> + return ret;
Completely unnecessary. pl->supported will be zero, leading to
phy_lookup_setting() failing.
> s = phy_lookup_setting(pl->link_config.speed, pl->link_config.duplex,
> pl->supported, true);
> @@ -1261,7 +1263,11 @@ struct phylink *phylink_create(struct phylink_config *config,
>
> bitmap_fill(pl->supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
> linkmode_copy(pl->link_config.advertising, pl->supported);
> - phylink_validate(pl, pl->supported, &pl->link_config);
> + ret = phylink_validate(pl, pl->supported, &pl->link_config);
> + if (ret < 0) {
> + kfree(pl);
> + return ERR_PTR(ret);
> + }
Again, intentional not to be checking here.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-02-25 9:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-25 9:12 [PATCH] net: phy: phylink: check the return value of phylink_validate() Jia-Ju Bai
2022-02-25 9:19 ` Russell King (Oracle)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).