Skip to content

Commit baadb4a

Browse files
gnitkaanguy11
authored andcommitted
ice: fix PTP cleanup on driver removal in error path
Improve the cleanup on releasing PTP resources in error path. The error case might happen either at the driver probe and PTP feature initialization or on PTP restart (errors in reset handling, NVM update etc). In both cases, calls to PF PTP cleanup (ice_ptp_cleanup_pf function) and 'ps_lock' mutex deinitialization were missed. Additionally, ptp clock was not unregistered in the latter case. Keep PTP state as 'uninitialized' on init to distinguish between error scenarios and to avoid resource release duplication at driver removal. The consequence of missing ice_ptp_cleanup_pf call is the following call trace dumped when ice_adapter object is freed (port list is not empty, as it is required at this stage): [ T93022] ------------[ cut here ]------------ [ T93022] WARNING: CPU: 10 PID: 93022 at ice/ice_adapter.c:67 ice_adapter_put+0xef/0x100 [ice] ... [ T93022] RIP: 0010:ice_adapter_put+0xef/0x100 [ice] ... [ T93022] Call Trace: [ T93022] <TASK> [ T93022] ? ice_adapter_put+0xef/0x100 [ice 33d2647ad4f6d866d41eefff1806df37c68aef0c] [ T93022] ? __warn.cold+0xb0/0x10e [ T93022] ? ice_adapter_put+0xef/0x100 [ice 33d2647ad4f6d866d41eefff1806df37c68aef0c] [ T93022] ? report_bug+0xd8/0x150 [ T93022] ? handle_bug+0xe9/0x110 [ T93022] ? exc_invalid_op+0x17/0x70 [ T93022] ? asm_exc_invalid_op+0x1a/0x20 [ T93022] ? ice_adapter_put+0xef/0x100 [ice 33d2647ad4f6d866d41eefff1806df37c68aef0c] [ T93022] pci_device_remove+0x42/0xb0 [ T93022] device_release_driver_internal+0x19f/0x200 [ T93022] driver_detach+0x48/0x90 [ T93022] bus_remove_driver+0x70/0xf0 [ T93022] pci_unregister_driver+0x42/0xb0 [ T93022] ice_module_exit+0x10/0xdb0 [ice 33d2647ad4f6d866d41eefff1806df37c68aef0c] ... [ T93022] ---[ end trace 0000000000000000 ]--- [ T93022] ice: module unloaded Fixes: e800654 ("ice: Use ice_adapter for PTP shared data instead of auxdev") Signed-off-by: Grzegorz Nitka <[email protected]> Reviewed-by: Aleksandr Loktionov <[email protected]> Reviewed-by: Paul Menzel <[email protected]>
1 parent 5c70f87 commit baadb4a

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

drivers/net/ethernet/intel/ice/ice_ptp.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3246,7 +3246,7 @@ void ice_ptp_init(struct ice_pf *pf)
32463246

32473247
err = ice_ptp_init_port(pf, &ptp->port);
32483248
if (err)
3249-
goto err_exit;
3249+
goto err_clean_pf;
32503250

32513251
/* Start the PHY timestamping block */
32523252
ice_ptp_reset_phy_timestamping(pf);
@@ -3263,13 +3263,19 @@ void ice_ptp_init(struct ice_pf *pf)
32633263
dev_info(ice_pf_to_dev(pf), "PTP init successful\n");
32643264
return;
32653265

3266+
err_clean_pf:
3267+
mutex_destroy(&ptp->port.ps_lock);
3268+
ice_ptp_cleanup_pf(pf);
32663269
err_exit:
32673270
/* If we registered a PTP clock, release it */
32683271
if (pf->ptp.clock) {
32693272
ptp_clock_unregister(ptp->clock);
32703273
pf->ptp.clock = NULL;
32713274
}
3272-
ptp->state = ICE_PTP_ERROR;
3275+
/* Keep ICE_PTP_UNINIT state to avoid ambiguity at driver unload
3276+
* and to avoid duplicated resources release.
3277+
*/
3278+
ptp->state = ICE_PTP_UNINIT;
32733279
dev_err(ice_pf_to_dev(pf), "PTP failed %d\n", err);
32743280
}
32753281

@@ -3282,9 +3288,19 @@ void ice_ptp_init(struct ice_pf *pf)
32823288
*/
32833289
void ice_ptp_release(struct ice_pf *pf)
32843290
{
3285-
if (pf->ptp.state != ICE_PTP_READY)
3291+
if (pf->ptp.state == ICE_PTP_UNINIT)
32863292
return;
32873293

3294+
if (pf->ptp.state != ICE_PTP_READY) {
3295+
ice_ptp_cleanup_pf(pf);
3296+
mutex_destroy(&pf->ptp.port.ps_lock);
3297+
if (pf->ptp.clock) {
3298+
ptp_clock_unregister(pf->ptp.clock);
3299+
pf->ptp.clock = NULL;
3300+
}
3301+
return;
3302+
}
3303+
32883304
pf->ptp.state = ICE_PTP_UNINIT;
32893305

32903306
/* Disable timestamping for both Tx and Rx */

0 commit comments

Comments
 (0)