Skip to content

Commit f490af4

Browse files
Jerry Wugregkh
authored andcommitted
net: mscc: ocelot: Fix crash when adding interface under a lag
[ Upstream commit 34f3ff5 ] Commit 15faa1f ("lan966x: Fix crash when adding interface under a lag") fixed a similar issue in the lan966x driver caused by a NULL pointer dereference. The ocelot_set_aggr_pgids() function in the ocelot driver has similar logic and is susceptible to the same crash. This issue specifically affects the ocelot_vsc7514.c frontend, which leaves unused ports as NULL pointers. The felix_vsc9959.c frontend is unaffected as it uses the DSA framework which registers all ports. Fix this by checking if the port pointer is valid before accessing it. Fixes: 528d3f1 ("net: mscc: ocelot: drop the use of the "lags" array") Signed-off-by: Jerry Wu <w.7erry@foxmail.com> Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com> Link: https://patch.msgid.link/tencent_75EF812B305E26B0869C673DD1160866C90A@qq.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent b53fca6 commit f490af4

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

drivers/net/ethernet/mscc/ocelot.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,14 +2307,16 @@ static void ocelot_set_aggr_pgids(struct ocelot *ocelot)
23072307

23082308
/* Now, set PGIDs for each active LAG */
23092309
for (lag = 0; lag < ocelot->num_phys_ports; lag++) {
2310-
struct net_device *bond = ocelot->ports[lag]->bond;
2310+
struct ocelot_port *ocelot_port = ocelot->ports[lag];
23112311
int num_active_ports = 0;
2312+
struct net_device *bond;
23122313
unsigned long bond_mask;
23132314
u8 aggr_idx[16];
23142315

2315-
if (!bond || (visited & BIT(lag)))
2316+
if (!ocelot_port || !ocelot_port->bond || (visited & BIT(lag)))
23162317
continue;
23172318

2319+
bond = ocelot_port->bond;
23182320
bond_mask = ocelot_get_bond_mask(ocelot, bond);
23192321

23202322
for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) {

0 commit comments

Comments
 (0)