Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0cefa974 authored by Martin Blumenstingl's avatar Martin Blumenstingl Committed by Kalle Valo
Browse files

ath9k: ath9k_hw_init_macaddr should not overwrite valid MAC addresses



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: default avatarMartin Blumenstingl <martin.blumenstingl@googlemail.com>
Signed-off-by: default avatarKalle Valo <kvalo@qca.qualcomm.com>
parent b27301f8
Loading
Loading
Loading
Loading
+13 −9
Original line number Original line Diff line number Diff line
@@ -478,21 +478,25 @@ static int ath9k_hw_init_macaddr(struct ath_hw *ah)
	u16 eeval;
	u16 eeval;
	static const u32 EEP_MAC[] = { EEP_MAC_LSW, EEP_MAC_MID, EEP_MAC_MSW };
	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++) {
	for (i = 0; i < 3; i++) {
		eeval = ah->eep_ops->get_eeprom(ah, EEP_MAC[i]);
		eeval = ah->eep_ops->get_eeprom(ah, EEP_MAC[i]);
		common->macaddr[2 * i] = eeval >> 8;
		common->macaddr[2 * i] = eeval >> 8;
		common->macaddr[2 * i + 1] = eeval & 0xff;
		common->macaddr[2 * i + 1] = eeval & 0xff;
	}
	}
	if (!is_valid_ether_addr(common->macaddr)) {

		ath_err(common,
	if (is_valid_ether_addr(common->macaddr))
			"eeprom contains invalid mac address: %pM\n",
		return 0;

	ath_err(common, "eeprom contains invalid mac address: %pM\n",
		common->macaddr);
		common->macaddr);


	random_ether_addr(common->macaddr);
	random_ether_addr(common->macaddr);
		ath_err(common,
	ath_err(common, "random mac address will be used: %pM\n",
			"random mac address will be used: %pM\n",
		common->macaddr);
		common->macaddr);
	}


	return 0;
	return 0;
}
}