f1f359bad7ac0deefe9a8904ef916ec540890f91
[openwrt/staging/blocktrron.git] /
1 From b7d78b46d5e8dc77c656c13885d31e931923b915 Mon Sep 17 00:00:00 2001
2 From: Vladimir Oltean <vladimir.oltean@nxp.com>
3 Date: Wed, 29 Jun 2022 22:33:58 +0300
4 Subject: [PATCH] net: phylink: fix NULL pl->pcs dereference during
5 phylink_pcs_poll_start
6
7 The current link mode of the phylink instance may not require an
8 attached PCS. However, phylink_major_config() unconditionally
9 dereferences this potentially NULL pointer when restarting the link poll
10 timer, which will panic the kernel.
11
12 Fix the problem by checking whether a PCS exists in phylink_pcs_poll_start(),
13 otherwise do nothing. The code prior to the blamed patch also only
14 looked at pcs->poll within an "if (pcs)" block.
15
16 Fixes: bfac8c490d60 ("net: phylink: disable PCS polling over major configuration")
17 Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
18 Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
19 Tested-by: Gerhard Engleder <gerhard@engleder-embedded.com>
20 Tested-by: Michael Walle <michael@walle.cc> # on kontron-kbox-a-230-ls
21 Tested-by: Nicolas Ferre <nicolas.ferre@microchip.com> # on sam9x60ek
22 Link: https://lore.kernel.org/r/20220629193358.4007923-1-vladimir.oltean@nxp.com
23 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
24 ---
25 drivers/net/phy/phylink.c | 2 +-
26 1 file changed, 1 insertion(+), 1 deletion(-)
27
28 --- a/drivers/net/phy/phylink.c
29 +++ b/drivers/net/phy/phylink.c
30 @@ -764,7 +764,7 @@ static void phylink_pcs_poll_stop(struct
31
32 static void phylink_pcs_poll_start(struct phylink *pl)
33 {
34 - if (pl->pcs->poll && pl->cfg_link_an_mode == MLO_AN_INBAND)
35 + if (pl->pcs && pl->pcs->poll && pl->cfg_link_an_mode == MLO_AN_INBAND)
36 mod_timer(&pl->link_poll, jiffies + HZ);
37 }
38