Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp305915rwb; Tue, 13 Dec 2022 18:02:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ENMsNrSoOGPnwDwi4WLd3xQ6Ch6Wqg0YwU3eZ41ksInFFRimTugrZMgiYFNtfBil/Afre X-Received: by 2002:a17:906:5496:b0:7bc:14e7:cfae with SMTP id r22-20020a170906549600b007bc14e7cfaemr18450393ejo.49.1670983344741; Tue, 13 Dec 2022 18:02:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670983344; cv=none; d=google.com; s=arc-20160816; b=MocA8IcPdr3BIe0UPh/ZdrAS9fSFP8VctP3qzoz4geXvFTq6Kbgl/VTZROMhJsLDXg TRiUNeCzOBkFwp3VhIf6SO/ZObtHx6B0b1FIXmCRuSJN6gbipSRCYuK/fC8rO5ITZCDF VBsJFH8bkeAUAgsbI8UiGmCtA3R42eqXqLsoJAhrylzl5FWOm0W45QA2NZLhvuVja/oG 2AD8yKMbgpXdm219SX+gV72QSczx3n/Mia3iZtE/UGRpSs8n7cLfZuaPEWZ9Ocl7/YFq Pp3fDq/HC4dd8oVjpdbv0gCFoa3D0JPLB1G/bI+k6ZOw/LF97pG0E9lOnsthj2ebYbhR DiXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=5ip81+wNz5xtBTBVts1Fb1RLCzaC6pg2EyPJm4Juic8=; b=LjRyQH3av+2oMCwVfGWNzc0x+c3m732I0Pu5dCK9OT4FpkGU7aejJGeE1hdItxdUOg T13dvmATouRAOonxy+iJQV5DZovRno3SoMSgRU7vHtONwMbZvOKwQ3q200aR0v9ymWpg cTDtsXsrfr+0KB2yxZTud4ckoFQcJy6F8lXfp19t5D+spC/J4tij6BftPcrUVemITE94 jBT9CwArcsBF2anZXQ2XpF5WJL5SCuy6xdj+4Kcgxvy5VWnpiceftYzKdeZxlhqIVmay iRE/rXuy/Vmu4tIahqODroJzx4bJqbbPYmpozFOlnBP1/72o7RLMBl+A6Q9qAW45wtvw 4Chg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@126.com header.s=s110527 header.b=WEOsSfCU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=126.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sa17-20020a1709076d1100b007b99436026dsi10392847ejc.968.2022.12.13.18.02.07; Tue, 13 Dec 2022 18:02:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@126.com header.s=s110527 header.b=WEOsSfCU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=126.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236923AbiLNBqc (ORCPT + 72 others); Tue, 13 Dec 2022 20:46:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229870AbiLNBqa (ORCPT ); Tue, 13 Dec 2022 20:46:30 -0500 X-Greylist: delayed 1876 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 13 Dec 2022 17:46:28 PST Received: from m15112.mail.126.com (m15112.mail.126.com [220.181.15.112]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 282851CFEA for ; Tue, 13 Dec 2022 17:46:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=5ip81 +wNz5xtBTBVts1Fb1RLCzaC6pg2EyPJm4Juic8=; b=WEOsSfCUJD0aqoNqa9gyi zDrK9ScOUzX3F9KIH7ev+bBMnNOouQ9wRY6ki/oEBZYLLRFa/ljjipw9ZAuzNkOv 7VgYDPCGBxDRTsgj57247iUifpDQcz/GzSqySG0HpY6PS4Ml+5AhGJwhuVh7b58v inMlebLPIF68I1w7v8+0G0= Received: from localhost.localdomain (unknown [117.136.79.146]) by smtp2 (Coremail) with SMTP id DMmowADHz7MtI5lj3iuJEw--.5203S2; Wed, 14 Dec 2022 09:13:20 +0800 (CST) From: Lixue Liang To: anthony.l.nguyen@intel.com, kuba@kernel.org, linux-kernel@vger.kernel.org Cc: jesse.brandeburg@intel.com, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, netdev@vger.kernel.org, richardcochran@gmail.com, ast@kernel.org, lianglixue@greatwall.com.cn, intel-wired-lan@lists.osuosl.org, kernel test robot Subject: [PATCH v7] igb: Assign random MAC address instead of fail in case of invalid one Date: Wed, 14 Dec 2022 01:12:14 +0000 Message-Id: <20221214011214.51836-1-lianglixuehao@126.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: DMmowADHz7MtI5lj3iuJEw--.5203S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxZw1ruFWxAr17Ar43tF4xJFb_yoW5uF4Upa y0gF43Wryktr47Zw4kWw4xZF95W3WDJ3yfGa9xZw1F9FnIv34DArW8K343Jry0qrZYkayx Jr17ZFZ7ua1qva7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UR89NUUUUU= X-Originating-IP: [117.136.79.146] X-CM-SenderInfo: xold0w5ol03vxkdrqiyswou0bp/xtbBGgnXFl-HaSMZAgAAsb X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lixue Liang 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 --- Changelog: * v7: - To group each parameter together Suggested-by Tony Nguyen * v6: - Modify commit messages and naming of module parameters - [PATCH v6] link: https://lore.kernel.org/netdev/20220610023922.74892-1-lianglixuehao@126.com/ Suggested-by Paul * 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/20220609083904.91778-1-lianglixuehao@126.com/ Suggested-by * 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/20220601150428.33945-1-lianglixuehao@126.com/ Suggested-by Tony * v3: - Add space after comma in commit message - Correct spelling of MAC address - [PATCH v3] link: https://lore.kernel.org/netdev/20220530105834.97175-1-lianglixuehao@126.com/ Suggested-by Paul * 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/20220512093918.86084-1-lianglixue@greatwall.com.cn/ Reported-by: kernel test robot 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