Skip to contentSkip to conversation

net: dsa: mv88e6xxx: fix marvell 6350 probe crash

PATCH Superseded Greg Ungerer 2 participants 3 messages Nov 22, 2023 – Nov 24, 2023

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 net: dsa: mv88e6xxx: fix marvell 6350 probe crash

As of commit b92143d4420f ("net: dsa: mv88e6xxx: add infrastructure for phylink_pcs") probing of a Marvell 88e6350 switch causes a NULL pointer dereference like this example:

    ...
    mv88e6085 d0072004.mdio-mii:11: switch 0x3710 detected: Marvell 88E6350, revision 2
    8<--- cut here ---
    Unable to handle kernel NULL pointer dereference at virtual address 00000000 when read
    [00000000] *pgd=00000000
    Internal error: Oops: 5 [#1] ARM
    Modules linked in:
    CPU: 0 PID: 8 Comm: kworker/u2:0 Not tainted 6.7.0-rc2-dirty #26
    Hardware name: Marvell Armada 370/XP (Device Tree)
    Workqueue: events_unbound deferred_probe_work_func
    PC is at mv88e6xxx_port_setup+0x1c/0x44
    LR is at dsa_port_devlink_setup+0x74/0x154
    pc : [<c057ea24>]    lr : [<c0819598>]    psr: a0000013
    sp : c184fce0  ip : c542b8f4  fp : 00000000
    r10: 00000001  r9 : c542a540  r8 : c542bc00
    r7 : c542b838  r6 : c5244580  r5 : 00000005  r4 : c5244580
    r3 : 00000000  r2 : c542b840  r1 : 00000005  r0 : c1a02040
    ...

The Marvell 88e6350 switch has no SERDES interface and so has no corresponding pcs_ops defined for it. But during probing a call is made to mv88e6xxx_port_setup() which unconditionally expects pcs_ops to exist, though the presence of the pcs_ops->pcs_init function is optional.

Modify the code to check for pcs_ops first, before checking for and calling pcs_ops->pcs_init.

Fixes b92143d4420f ("net: dsa: mv88e6xxx: add infrastructure for phylink_pcs")
---
 drivers/net/dsa/mv88e6xxx/chip.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/dsa/mv88e6xxx/chip.c +2 -1
index e9adf9711c09..38f76ee3035b 100644
@@ -3892,7 +3892,8 @@ static int mv88e6xxx_port_setup(struct dsa_switch *ds, int port)
 	struct mv88e6xxx_chip *chip = ds->priv;
 	int err;
 
-	if (chip->info->ops->pcs_ops->pcs_init) {
+	if (chip->info->ops->pcs_ops &&
+	    chip->info->ops->pcs_ops->pcs_init) {
 		err = chip->info->ops->pcs_ops->pcs_init(chip, port);
 		if (err)
 			return err;
Signature · 1 line
2.25.1
maintainer
#1 lore raw

drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6xxx_port_setup(struct dsa_switch *ds, int port) · line 3899

Quoted 10 lines
drivers/net/dsa/mv88e6xxx/chip.c +2 -1
@@ -3892,7 +3892,8 @@ static int mv88e6xxx_port_setup(struct dsa_switch *ds, int port)
 	struct mv88e6xxx_chip *chip = ds->priv;
 	int err;
 
-	if (chip->info->ops->pcs_ops->pcs_init) {
+	if (chip->info->ops->pcs_ops &&
+	    chip->info->ops->pcs_ops->pcs_init) {
 		err = chip->info->ops->pcs_ops->pcs_init(chip, port);
 		if (err)
 			return err;

mv88e6xxx_port_teardown() seems to have the same problem. Could you fix that as well?

Thanks

Andrew

#2 lore raw
Quoted 4 lines · Andrew Lunn
Quoted 4 lines
drivers/net/dsa/mv88e6xxx/chip.c +0 -0
@@ -3892,7 +3892,8 @@ static int mv88e6xxx_port_setup(struct dsa_switch *ds, int port)
  	struct mv88e6xxx_chip *chip = ds->priv;
  	int err;
 
Quoted 9 lines

drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6xxx_port_setup(struct dsa_switch *ds, int port) · line 3899

Quoted 6 lines
drivers/net/dsa/mv88e6xxx/chip.c +2 -1
-	if (chip->info->ops->pcs_ops->pcs_init) {
+	if (chip->info->ops->pcs_ops &&
+	    chip->info->ops->pcs_ops->pcs_init) {
  		err = chip->info->ops->pcs_ops->pcs_init(chip, port);
  		if (err)
  			return err;

mv88e6xxx_port_teardown() seems to have the same problem. Could you fix that as well?

Yep, will do.

Regards
Greg