igb: unregister the i2c adapter when register_netdev() fails
Subsystems (3)
PATCH 1/1 igb: unregister the i2c adapter when register_netdev() fails
From: Linkui Xiao <[email protected]>
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.
--- drivers/net/ethernet/intel/igb/igb_main.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/net/ethernet/intel/igb/igb_main.c +11 -11
@@ -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
Signature · 1 line
2.25.1