}
 EXPORT_SYMBOL(ocelot_get_ts_info);
 
+static u32 ocelot_get_bond_mask(struct ocelot *ocelot, struct net_device *bond)
+{
+       u32 mask = 0;
+       int port;
+
+       for (port = 0; port < ocelot->num_phys_ports; port++) {
+               struct ocelot_port *ocelot_port = ocelot->ports[port];
+
+               if (!ocelot_port)
+                       continue;
+
+               if (ocelot_port->bond == bond)
+                       mask |= BIT(port);
+       }
+
+       return mask;
+}
+
 static u32 ocelot_get_dsa_8021q_cpu_mask(struct ocelot *ocelot)
 {
        u32 mask = 0;
                         struct net_device *bond,
                         struct netdev_lag_upper_info *info)
 {
-       struct net_device *ndev;
        u32 bond_mask = 0;
        int lag, lp;
 
        if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH)
                return -EOPNOTSUPP;
 
-       rcu_read_lock();
-       for_each_netdev_in_bond_rcu(bond, ndev) {
-               struct ocelot_port_private *priv = netdev_priv(ndev);
+       ocelot->ports[port]->bond = bond;
 
-               bond_mask |= BIT(priv->chip_port);
-       }
-       rcu_read_unlock();
+       bond_mask = ocelot_get_bond_mask(ocelot, bond);
 
        lp = __ffs(bond_mask);
 
        u32 port_cfg;
        int i;
 
+       ocelot->ports[port]->bond = NULL;
+
        /* Remove port from any lag */
        for (i = 0; i < ocelot->num_phys_ports; i++)
                ocelot->lags[i] &= ~BIT(port);