i40e: Cleanup PTP pins on probe failure
Subsystems (2)
PATCH 1/1 i40e: Cleanup PTP pins on probe failure
PTP pin structs are allocated early in probe, but never cleaned up.
Fix this by calling i40e_ptp_free_pins in the error path.
To support this, i40e_ptp_free_pins was added to the header and made idempotent. The idempotency supports the condition of pf->ptp_caps.pin_config not being allocated yet. pin_config is also correctly nullified after being freed.
This has been an issue since i40e_ptp_alloc_pins was introduced.
--- drivers/net/ethernet/intel/i40e/i40e.h | 1 + drivers/net/ethernet/intel/i40e/i40e_main.c | 1 + drivers/net/ethernet/intel/i40e/i40e_ptp.c | 9 ++++++--- 3 files changed, 8 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/i40e/i40e.h +1 -0
@@ -1318,6 +1318,7 @@ void i40e_ptp_restore_hw_time(struct i40e_pf *pf);void i40e_ptp_init (struct i40e_pf *pf);void i40e_ptp_stop (struct i40e_pf *pf);int i40e_ptp_alloc_pins (struct i40e_pf *pf); +void i40e_ptp_free_pins (struct i40e_pf *pf);int i40e_update_adq_vsi_queues (struct i40e_vsi *vsi,int vsi_offset);int i40e_is_vsi_uplink_mode_veb (struct i40e_vsi *vsi);int i40e_get_partition_bw_setting (struct i40e_pf *pf);
drivers/net/ethernet/intel/i40e/i40e_main.c +1 -0
@@ -16112,6 +16112,7 @@ static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)i40e_clear_interrupt_scheme (pf);kfree (pf->vsi); err_switch_setup: +i40e_ptp_free_pins (pf);i40e_reset_interrupt_capability (pf);timer_shutdown_sync (&pf->service_timer); err_mac_addr:
drivers/net/ethernet/intel/i40e/i40e_ptp.c +6 -3
@@ -940,12 +940,15 @@ int i40e_ptp_hwtstamp_get(struct net_device *netdev,* * Release memory allocated for PTP pins. **/ -static void i40e_ptp_free_pins (struct i40e_pf *pf) +void i40e_ptp_free_pins (struct i40e_pf *pf) {if (i40e_is_ptp_pin_dev (&pf->hw)) { -kfree (pf->ptp_pins); -kfree (pf->ptp_caps.pin_config); +if (pf->ptp_pins) +kfree (pf->ptp_pins); +if (pf->ptp_caps.pin_config) +kfree (pf->ptp_caps.pin_config); pf->ptp_pins =NULL ; + pf->ptp_caps.pin_config =NULL ; } }
Signature · 1 line
2.43.0
drivers/net/ethernet/intel/i40e/i40e_ptp.c int i40e_ptp_hwtstamp_get(struct net_device *netdev, · line 946
Quoted 13 lines · Matt Vollrath
drivers/net/ethernet/intel/i40e/i40e_ptp.c +2
-3@@ -940,12 +940,15 @@ int i40e_ptp_hwtstamp_get(struct net_device *netdev,* * Release memory allocated for PTP pins. **/ -static void i40e_ptp_free_pins (struct i40e_pf *pf) +void i40e_ptp_free_pins (struct i40e_pf *pf) {if (i40e_is_ptp_pin_dev (&pf->hw)) { -kfree (pf->ptp_pins); -kfree (pf->ptp_caps.pin_config); +if (pf->ptp_pins)
Not a big deal, but I don't think this guard is necessary, because kfree accepts NULL safely.
drivers/net/ethernet/intel/i40e/i40e_ptp.c int i40e_ptp_hwtstamp_get(struct net_device *netdev, · line 948
Quoted 2 lines
drivers/net/ethernet/intel/i40e/i40e_ptp.c +2
-0+kfree (pf->ptp_pins); +if (pf->ptp_caps.pin_config)
Same here.
Thank you for addressing!
Quoted 9 lines
drivers/net/ethernet/intel/i40e/i40e_ptp.c +2
-0+kfree (pf->ptp_caps.pin_config); pf->ptp_pins =NULL ; + pf->ptp_caps.pin_config =NULL ; } }Signature · 1 line
2.43.0