From: Lixue Liang <[email protected]>
Add the module parameter "allow_invalid_mac_address" to control the
behavior. When set to true, a random MAC address is assigned, and the
driver can be loaded, allowing the user to correct the invalid MAC address.
Signed-off-by: Lixue Liang <[email protected]>
---
Changelog:
* v7:
- To group each parameter together
Suggested-by Tony Nguyen <[email protected]>
* v6:
- Modify commit messages and naming of module parameters
- [PATCH v6] link:
https://lore.kernel.org/netdev/[email protected]/
Suggested-by Paul <[email protected]>
* v5:
- Through the setting of module parameters, it is allowed to complete
the loading of the igb network card driver with an invalid MAC address.
- [PATCH v5] link:
https://lore.kernel.org/netdev/[email protected]/
Suggested-by <[email protected]>
* v4:
- Change the igb_mian in the title to igb
- Fix dev_err message: replace "already assigned random MAC address"
with "Invalid MAC address. Assigned random MAC address"
- [PATCH v4] link:
https://lore.kernel.org/netdev/[email protected]/
Suggested-by Tony <[email protected]>
* v3:
- Add space after comma in commit message
- Correct spelling of MAC address
- [PATCH v3] link:
https://lore.kernel.org/netdev/[email protected]/
Suggested-by Paul <[email protected]>
* v2:
- Change memcpy to ether_addr_copy
- Change dev_info to dev_err
- Fix the description of the commit message
- Change eth_random_addr to eth_hw_addr_random
- [PATCH v2] link:
https://lore.kernel.org/netdev/[email protected]/
Reported-by: kernel test robot <[email protected]>
drivers/net/ethernet/intel/igb/igb_main.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index f8e32833226c..8ff0c698383c 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -241,6 +241,10 @@ static int debug = -1;
module_param(debug, int, 0);
MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
+static bool allow_invalid_mac_address;
+module_param(allow_invalid_mac_address, bool, 0);
+MODULE_PARM_DESC(allow_invalid_mac_address, "Allow NIC driver to be loaded with invalid MAC address");
+
struct igb_reg_info {
u32 ofs;
char *name;
@@ -3358,9 +3362,16 @@ static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
eth_hw_addr_set(netdev, hw->mac.addr);
if (!is_valid_ether_addr(netdev->dev_addr)) {
- dev_err(&pdev->dev, "Invalid MAC Address\n");
- err = -EIO;
- goto err_eeprom;
+ if (!allow_invalid_mac_address) {
+ dev_err(&pdev->dev, "Invalid MAC address\n");
+ err = -EIO;
+ goto err_eeprom;
+ } else {
+ eth_hw_addr_random(netdev);
+ ether_addr_copy(hw->mac.addr, netdev->dev_addr);
+ dev_err(&pdev->dev,
+ "Invalid MAC address. Assigned random MAC address\n");
+ }
}
igb_set_default_mac_filter(adapter);
--
2.27.0