{
        int i;
 
-       for (i = 0; i < MTK_MAC_COUNT; i++) {
+       for (i = 0; i < MTK_MAX_DEVS; i++) {
                if (!eth->mac[i] || !eth->mac[i]->hw_stats)
                        continue;
                if (spin_trylock(ð->mac[i]->hw_stats->stats_lock)) {
 {
        int i;
 
-       for (i = 0; i < MTK_MAC_COUNT; i++) {
+       for (i = 0; i < MTK_MAX_DEVS; i++) {
                if (!eth->netdev[i])
                        continue;
                if (netif_queue_stopped(eth->netdev[i]))
 {
        int i;
 
-       for (i = 0; i < MTK_MAC_COUNT; i++) {
+       for (i = 0; i < MTK_MAX_DEVS; i++) {
                if (!eth->netdev[i])
                        continue;
                netif_tx_wake_all_queues(eth->netdev[i]);
                         !(trxd.rxd4 & RX_DMA_SPECIAL_TAG))
                        mac = RX_DMA_GET_SPORT(trxd.rxd4) - 1;
 
-               if (unlikely(mac < 0 || mac >= MTK_MAC_COUNT ||
+               if (unlikely(mac < 0 || mac >= MTK_MAX_DEVS ||
                             !eth->netdev[mac]))
                        goto release_desc;
 
        const struct mtk_soc_data *soc = eth->soc;
        int i;
 
-       for (i = 0; i < MTK_MAC_COUNT; i++)
+       for (i = 0; i < MTK_MAX_DEVS; i++)
                if (eth->netdev[i])
                        netdev_reset_queue(eth->netdev[i]);
        if (eth->scratch_ring) {
        if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628))
                return;
 
-       for (i = 0; i < MTK_MAC_COUNT; i++) {
-               u32 val = mtk_r32(eth, MTK_GDMA_FWD_CFG(i));
+       for (i = 0; i < MTK_MAX_DEVS; i++) {
+               u32 val;
+
+               if (!eth->netdev[i])
+                       continue;
+
+               val = mtk_r32(eth, MTK_GDMA_FWD_CFG(i));
 
                /* default setup the forward port to send frame to PDMA */
                val &= ~0xffff;
 
                val |= config;
 
-               if (eth->netdev[i] && netdev_uses_dsa(eth->netdev[i]))
+               if (netdev_uses_dsa(eth->netdev[i]))
                        val |= MTK_GDMA_SPECIAL_TAG;
 
                mtk_w32(eth, val, MTK_GDMA_FWD_CFG(i));
         * up with the more appropriate value when mtk_mac_config call is being
         * invoked.
         */
-       for (i = 0; i < MTK_MAC_COUNT; i++) {
+       for (i = 0; i < MTK_MAX_DEVS; i++) {
                struct net_device *dev = eth->netdev[i];
 
-               mtk_w32(eth, MAC_MCR_FORCE_LINK_DOWN, MTK_MAC_MCR(i));
-               if (dev) {
-                       struct mtk_mac *mac = netdev_priv(dev);
+               if (!dev)
+                       continue;
 
-                       mtk_set_mcr_max_rx(mac, dev->mtu + MTK_RX_ETH_HLEN);
-               }
+               mtk_w32(eth, MAC_MCR_FORCE_LINK_DOWN, MTK_MAC_MCR(i));
+               mtk_set_mcr_max_rx(netdev_priv(dev),
+                                  dev->mtu + MTK_RX_ETH_HLEN);
        }
 
        /* Indicates CDM to parse the MTK special tag from CPU
        mtk_prepare_for_reset(eth);
 
        /* stop all devices to make sure that dma is properly shut down */
-       for (i = 0; i < MTK_MAC_COUNT; i++) {
+       for (i = 0; i < MTK_MAX_DEVS; i++) {
                if (!eth->netdev[i] || !netif_running(eth->netdev[i]))
                        continue;
 
        mtk_hw_init(eth, true);
 
        /* restart DMA and enable IRQs */
-       for (i = 0; i < MTK_MAC_COUNT; i++) {
-               if (!test_bit(i, &restart))
+       for (i = 0; i < MTK_MAX_DEVS; i++) {
+               if (!eth->netdev[i] || !test_bit(i, &restart))
                        continue;
 
                if (mtk_open(eth->netdev[i])) {
 {
        int i;
 
-       for (i = 0; i < MTK_MAC_COUNT; i++) {
+       for (i = 0; i < MTK_MAX_DEVS; i++) {
                if (!eth->netdev[i])
                        continue;
                free_netdev(eth->netdev[i]);
 {
        int i;
 
-       for (i = 0; i < MTK_MAC_COUNT; i++) {
+       for (i = 0; i < MTK_MAX_DEVS; i++) {
                struct mtk_mac *mac;
                if (!eth->netdev[i])
                        continue;
        }
 
        id = be32_to_cpup(_id);
-       if (id >= MTK_MAC_COUNT) {
+       if (id >= MTK_MAX_DEVS) {
                dev_err(eth->dev, "%d is not a valid mac id\n", id);
                return -EINVAL;
        }
 
        rtnl_lock();
 
-       for (i = 0; i < MTK_MAC_COUNT; i++) {
+       for (i = 0; i < MTK_MAX_DEVS; i++) {
                dev = eth->netdev[i];
 
                if (!dev || !(dev->flags & IFF_UP))
        int i;
 
        /* stop all devices to make sure that dma is properly shut down */
-       for (i = 0; i < MTK_MAC_COUNT; i++) {
+       for (i = 0; i < MTK_MAX_DEVS; i++) {
                if (!eth->netdev[i])
                        continue;
                mtk_stop(eth->netdev[i]);