From: "Loktionov, Aleksandr" <aleksandr.loktionov@intel.com>
To: Linkui Xiao <xiaolinkui@126.com>,
"Nguyen, Anthony L" <anthony.l.nguyen@intel.com>,
"Kitszel, Przemyslaw" <przemyslaw.kitszel@intel.com>,
"andrew+netdev@lunn.ch" <andrew+netdev@lunn.ch>,
"davem@davemloft.net" <davem@davemloft.net>,
"edumazet@google.com" <edumazet@google.com>,
"kuba@kernel.org" <kuba@kernel.org>,
"pabeni@redhat.com" <pabeni@redhat.com>
Cc: "intel-wired-lan@lists.osuosl.org"
<intel-wired-lan@lists.osuosl.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Linkui Xiao <xiaolinkui@kylinos.cn>,
"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: RE: [Intel-wired-lan] [PATCH net] igb: unregister the i2c adapter when register_netdev() fails
Date: Thu, 17 Sep 2026 09:40:35 +0000 [thread overview]
Message-ID: <IA3PR11MB8986193C242880AF4F66A18BE5B82@IA3PR11MB8986.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20260916132740.1001797-1-xiaolinkui@126.com>
> -----Original Message-----
> From: Linkui Xiao <xiaolinkui@126.com>
> Sent: Wednesday, September 16, 2026 3:28 PM
> To: Nguyen, Anthony L <anthony.l.nguyen@intel.com>; Kitszel,
> Przemyslaw <przemyslaw.kitszel@intel.com>; andrew+netdev@lunn.ch;
> davem@davemloft.net; edumazet@google.com; kuba@kernel.org;
> pabeni@redhat.com
> Cc: intel-wired-lan@lists.osuosl.org; netdev@vger.kernel.org; linux-
> kernel@vger.kernel.org; Linkui Xiao <xiaolinkui@kylinos.cn>;
> stable@vger.kernel.org
> Subject: [Intel-wired-lan] [PATCH net] igb: unregister the i2c adapter
> when register_netdev() fails
>
> From: Linkui Xiao <xiaolinkui@kylinos.cn>
>
> igb_probe() sets up the bit-banging i2c adapter with igb_init_i2c()
> before it registers the netdev, but the err_register path only zeroes
> adapter->i2c_adap instead of unregistering the adapter. On i350 parts,
> where igb_init_i2c() really registers the bus, the adapter is
> therefore still registered when free_netdev() releases the memory that
> embeds it.
> The i2c core keeps pointing at the freed adapter, so any later access
> to that bus dereferences freed memory, and the adapter number is
> leaked.
>
> Call igb_remove_i2c() instead, the same way igb_remove() tears the bus
> down. Move the helper next to igb_init_i2c() so that it is in scope
> for igb_probe(). i2c_del_adapter() returns early for an adapter that
> was never registered, so the parts without i2c support are unaffected.
>
> Fixes: 441fc6fdb47a ("igb: Add i2c interface to igb.")
> Cc: stable@vger.kernel.org
> Signed-off-by: Linkui Xiao <xiaolinkui@kylinos.cn>
> ---
> drivers/net/ethernet/intel/igb/igb_main.c | 22 +++++++++++-----------
> 1 file changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/igb/igb_main.c
> b/drivers/net/ethernet/intel/igb/igb_main.c
> index d4a897a8c82c..f965ca144f42 100644
> --- a/drivers/net/ethernet/intel/igb/igb_main.c
> +++ b/drivers/net/ethernet/intel/igb/igb_main.c
> @@ -3190,6 +3190,16 @@ static s32 igb_init_i2c(struct igb_adapter
> *adapter)
> return status;
> }
>
> +/**
> + * igb_remove_i2c - Cleanup I2C interface
> + * @adapter: pointer to adapter structure **/ static void
> +igb_remove_i2c(struct igb_adapter *adapter) {
> + /* free the adapter bus structure */
> + i2c_del_adapter(&adapter->i2c_adap);
> +}
> +
> /**
> * igb_probe - Device Initialization Routine
> * @pdev: PCI device information struct @@ -3657,7 +3667,7 @@ static
> int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>
> err_register:
> igb_release_hw_control(adapter);
> - memset(&adapter->i2c_adap, 0, sizeof(adapter->i2c_adap));
> + igb_remove_i2c(adapter);
> err_eeprom:
> if (!igb_check_reset_block(hw))
> igb_reset_phy(hw);
> @@ -3849,16 +3859,6 @@ static int igb_enable_sriov(struct pci_dev
> *pdev, int num_vfs, bool reinit) }
>
> #endif
> -/**
> - * igb_remove_i2c - Cleanup I2C interface
> - * @adapter: pointer to adapter structure
> - **/
> -static void igb_remove_i2c(struct igb_adapter *adapter) -{
> - /* free the adapter bus structure */
> - i2c_del_adapter(&adapter->i2c_adap);
> -}
> -
> /**
> * igb_remove - Device Removal Routine
> * @pdev: PCI device information struct
> --
> 2.25.1
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
next prev parent reply other threads:[~2026-09-17 9:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 13:27 Linkui Xiao
2026-09-17 9:40 ` Loktionov, Aleksandr [this message]
2026-10-27 5:49 ` Singh, Ayush1X
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=IA3PR11MB8986193C242880AF4F66A18BE5B82@IA3PR11MB8986.namprd11.prod.outlook.com \
--to=aleksandr.loktionov@intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=anthony.l.nguyen@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=stable@vger.kernel.org \
--cc=xiaolinkui@126.com \
--cc=xiaolinkui@kylinos.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®