ath9k: ath9k_hw_init_macaddr should not overwrite valid MAC addresses
authorMartin Blumenstingl <martin.blumenstingl@googlemail.com>
Thu, 23 Jun 2016 14:57:11 +0000 (16:57 +0200)
committerKalle Valo <kvalo@qca.qualcomm.com>
Fri, 8 Jul 2016 14:01:23 +0000 (17:01 +0300)
Currently setting the MAC address via ath9k_platform_data works only due
to the order in which init.c sets common->macaddr, which is done after
ath9k_hw_init_macaddr was executed. It would be better if the latter
was independent of the order in which it's being called.

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Signed-off-by: Kalle Valo <kvalo@qca.qualcomm.com>
drivers/net/wireless/ath/ath9k/hw.c

index 4f98ca0f9888e1e5c96826ae82d9ff1eade11ee7..4dd3acab1db1f775f3a34024805aef283daac945 100644 (file)
@@ -478,21 +478,25 @@ static int ath9k_hw_init_macaddr(struct ath_hw *ah)
        u16 eeval;
        static const u32 EEP_MAC[] = { EEP_MAC_LSW, EEP_MAC_MID, EEP_MAC_MSW };
 
+       /* MAC address may already be loaded via ath9k_platform_data */
+       if (is_valid_ether_addr(common->macaddr))
+               return 0;
+
        for (i = 0; i < 3; i++) {
                eeval = ah->eep_ops->get_eeprom(ah, EEP_MAC[i]);
                common->macaddr[2 * i] = eeval >> 8;
                common->macaddr[2 * i + 1] = eeval & 0xff;
        }
-       if (!is_valid_ether_addr(common->macaddr)) {
-               ath_err(common,
-                       "eeprom contains invalid mac address: %pM\n",
-                       common->macaddr);
 
-               random_ether_addr(common->macaddr);
-               ath_err(common,
-                       "random mac address will be used: %pM\n",
-                       common->macaddr);
-       }
+       if (is_valid_ether_addr(common->macaddr))
+               return 0;
+
+       ath_err(common, "eeprom contains invalid mac address: %pM\n",
+               common->macaddr);
+
+       random_ether_addr(common->macaddr);
+       ath_err(common, "random mac address will be used: %pM\n",
+               common->macaddr);
 
        return 0;
 }