Skip to content

Commit

Permalink
phc: fixed dangling pointer usage and reordered remove sequence
Browse files Browse the repository at this point in the history
octeon_device_t pointer was used as a dangling pointer in
the remove sequence. Also remove sequence, when firmware ready
work occurred, didn't clean resources allocated. Fixed the above bugs.

Signed-off-by: Shinas Rasheed <srasheed@marvell.com>
Change-Id: I6c9aef5468d8c54bee824426221eafebc543c996
Reviewed-on: https://sj1git1.cavium.com/c/IP/SW/pcie_ep/pcie_ep_octeon_host/+/111046
Tested-by: sa_ip-sw-jenkins <sa_ip-sw-jenkins@marvell.com>
Reviewed-by: Haseeb Gani <hgani@marvell.com>
  • Loading branch information
shinas-marvell authored and GaniHaseeb committed Oct 6, 2023
1 parent 8f91e74 commit a0dd5f4
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions drivers/phc/ep_phc.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ int octeon_ep_phc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
void octeon_ep_phc_remove(struct pci_dev *pdev)
{
octeon_device_t *oct_dev = pci_get_drvdata(pdev);
bool dev_inval = false;
int oct_idx;

oct_idx = oct_dev->octeon_id;
Expand All @@ -626,14 +627,15 @@ void octeon_ep_phc_remove(struct pci_dev *pdev)
if (atomic_read(&oct_dev->status) == OCT_DEV_CHECK_FW) {
atomic_set(&oct_dev->status, OCT_DEV_STOPPING);
while (true) {
if (atomic_read(&oct_dev->status) == OCT_DEV_STATE_INVALID)
return;
if (atomic_read(&oct_dev->status) == OCT_DEV_STATE_INVALID) {
dev_inval = true;
break;
}

dev_err(&oct_dev->pci_dev->dev, "OCT_PHC[%d]: Waiting for firmware ready work to end.\n",
oct_idx);
schedule_timeout_interruptible(HZ * 1);
}
goto before_exit;
}

atomic_set(&oct_dev->status, OCT_DEV_STOPPING);
Expand All @@ -648,10 +650,10 @@ void octeon_ep_phc_remove(struct pci_dev *pdev)
flush_workqueue(oct_dev->dev_init_wq.wq);
destroy_workqueue(oct_dev->dev_init_wq.wq);
oct_dev->dev_init_wq.wq = NULL;

if (dev_inval == true)
goto before_exit;

ptp_clock_unregister(oct_dev->oct_ep_ptp_clock->ptp_clock);
kfree(oct_dev->oct_ep_ptp_clock);

sysfs_remove_file(&oct_dev->phc_sysfs_kobject, &phc_ptp_attribute.attr);
sysfs_remove_file(&oct_dev->phc_sysfs_kobject, &phc_pcie_attribute.attr);
Expand All @@ -665,10 +667,10 @@ void octeon_ep_phc_remove(struct pci_dev *pdev)
/* This octeon device has been removed. Update the global
* data structure to reflect this. Free the device structure.
*/
octeon_free_device_mem(oct_dev);

before_exit:
dev_info(&oct_dev->pci_dev->dev, "OCT_PHC[%d]: Octeon device removed\n", oct_idx);
kfree(oct_dev->oct_ep_ptp_clock);
octeon_free_device_mem(oct_dev);
}


Expand Down

0 comments on commit a0dd5f4

Please sign in to comment.