Message ID | 20230717170001.30539-2-shannon.nelson@amd.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | ionic: add FLR support | expand |
On Mon, Jul 17, 2023 at 09:59:58AM -0700, Shannon Nelson wrote: > Pull out a chunk of code from ionic_remove() that will > be common in teardown paths. > > Signed-off-by: Shannon Nelson <shannon.nelson@amd.com> > --- > .../ethernet/pensando/ionic/ionic_bus_pci.c | 25 ++++++++++--------- > 1 file changed, 13 insertions(+), 12 deletions(-) > > diff --git a/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c b/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c > index ab7d217b98b3..2bc3cab3967d 100644 > --- a/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c > +++ b/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c > @@ -213,6 +213,13 @@ static int ionic_sriov_configure(struct pci_dev *pdev, int num_vfs) > return ret; > } > > +static void ionic_clear_pci(struct ionic *ionic) > +{ > + ionic_unmap_bars(ionic); > + pci_release_regions(ionic->pdev); > + pci_disable_device(ionic->pdev); Hi Shannon, is it safe to call pci_release_regions() even if a successful call to pci_request_regions() has not been made? > +} > + > static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) > { > struct device *dev = &pdev->dev; > @@ -249,20 +256,20 @@ static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) > err = pci_request_regions(pdev, IONIC_DRV_NAME); > if (err) { > dev_err(dev, "Cannot request PCI regions: %d, aborting\n", err); > - goto err_out_pci_disable_device; > + goto err_out_clear_pci; > } > > pcie_print_link_status(pdev); > > err = ionic_map_bars(ionic); > if (err) > - goto err_out_pci_release_regions; > + goto err_out_clear_pci; > > /* Configure the device */ > err = ionic_setup(ionic); > if (err) { > dev_err(dev, "Cannot setup device: %d, aborting\n", err); > - goto err_out_unmap_bars; > + goto err_out_clear_pci; > } > pci_set_master(pdev); > > @@ -353,12 +360,8 @@ static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) > ionic_reset(ionic); > err_out_teardown: > ionic_dev_teardown(ionic); > -err_out_unmap_bars: > - ionic_unmap_bars(ionic); > -err_out_pci_release_regions: > - pci_release_regions(pdev); > -err_out_pci_disable_device: > - pci_disable_device(pdev); > +err_out_clear_pci: > + ionic_clear_pci(ionic); > err_out_debugfs_del_dev: > ionic_debugfs_del_dev(ionic); > err_out_clear_drvdata: ...
On 7/19/23 10:34 AM, Simon Horman wrote: > > On Mon, Jul 17, 2023 at 09:59:58AM -0700, Shannon Nelson wrote: >> Pull out a chunk of code from ionic_remove() that will >> be common in teardown paths. >> >> Signed-off-by: Shannon Nelson <shannon.nelson@amd.com> >> --- >> .../ethernet/pensando/ionic/ionic_bus_pci.c | 25 ++++++++++--------- >> 1 file changed, 13 insertions(+), 12 deletions(-) >> >> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c b/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c >> index ab7d217b98b3..2bc3cab3967d 100644 >> --- a/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c >> +++ b/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c >> @@ -213,6 +213,13 @@ static int ionic_sriov_configure(struct pci_dev *pdev, int num_vfs) >> return ret; >> } >> >> +static void ionic_clear_pci(struct ionic *ionic) >> +{ >> + ionic_unmap_bars(ionic); >> + pci_release_regions(ionic->pdev); >> + pci_disable_device(ionic->pdev); > > Hi Shannon, > > is it safe to call pci_release_regions() even if a successful call to > pci_request_regions() has not been made? It complains a bit about freeing non-existent regions, but otherwise is safe. Of course if we're on that path there are other more seriously broken things for this device. I figured the cleaner code is worth an extra log complaint in a probably never seen path. sln > >> +} >> + >> static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) >> { >> struct device *dev = &pdev->dev; >> @@ -249,20 +256,20 @@ static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) >> err = pci_request_regions(pdev, IONIC_DRV_NAME); >> if (err) { >> dev_err(dev, "Cannot request PCI regions: %d, aborting\n", err); >> - goto err_out_pci_disable_device; >> + goto err_out_clear_pci; >> } >> >> pcie_print_link_status(pdev); >> >> err = ionic_map_bars(ionic); >> if (err) >> - goto err_out_pci_release_regions; >> + goto err_out_clear_pci; >> >> /* Configure the device */ >> err = ionic_setup(ionic); >> if (err) { >> dev_err(dev, "Cannot setup device: %d, aborting\n", err); >> - goto err_out_unmap_bars; >> + goto err_out_clear_pci; >> } >> pci_set_master(pdev); >> >> @@ -353,12 +360,8 @@ static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) >> ionic_reset(ionic); >> err_out_teardown: >> ionic_dev_teardown(ionic); >> -err_out_unmap_bars: >> - ionic_unmap_bars(ionic); >> -err_out_pci_release_regions: >> - pci_release_regions(pdev); >> -err_out_pci_disable_device: >> - pci_disable_device(pdev); >> +err_out_clear_pci: >> + ionic_clear_pci(ionic); >> err_out_debugfs_del_dev: >> ionic_debugfs_del_dev(ionic); >> err_out_clear_drvdata: > > ...
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c b/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c index ab7d217b98b3..2bc3cab3967d 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +++ b/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c @@ -213,6 +213,13 @@ static int ionic_sriov_configure(struct pci_dev *pdev, int num_vfs) return ret; } +static void ionic_clear_pci(struct ionic *ionic) +{ + ionic_unmap_bars(ionic); + pci_release_regions(ionic->pdev); + pci_disable_device(ionic->pdev); +} + static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { struct device *dev = &pdev->dev; @@ -249,20 +256,20 @@ static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err = pci_request_regions(pdev, IONIC_DRV_NAME); if (err) { dev_err(dev, "Cannot request PCI regions: %d, aborting\n", err); - goto err_out_pci_disable_device; + goto err_out_clear_pci; } pcie_print_link_status(pdev); err = ionic_map_bars(ionic); if (err) - goto err_out_pci_release_regions; + goto err_out_clear_pci; /* Configure the device */ err = ionic_setup(ionic); if (err) { dev_err(dev, "Cannot setup device: %d, aborting\n", err); - goto err_out_unmap_bars; + goto err_out_clear_pci; } pci_set_master(pdev); @@ -353,12 +360,8 @@ static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ionic_reset(ionic); err_out_teardown: ionic_dev_teardown(ionic); -err_out_unmap_bars: - ionic_unmap_bars(ionic); -err_out_pci_release_regions: - pci_release_regions(pdev); -err_out_pci_disable_device: - pci_disable_device(pdev); +err_out_clear_pci: + ionic_clear_pci(ionic); err_out_debugfs_del_dev: ionic_debugfs_del_dev(ionic); err_out_clear_drvdata: @@ -386,9 +389,7 @@ static void ionic_remove(struct pci_dev *pdev) ionic_port_reset(ionic); ionic_reset(ionic); ionic_dev_teardown(ionic); - ionic_unmap_bars(ionic); - pci_release_regions(pdev); - pci_disable_device(pdev); + ionic_clear_pci(ionic); ionic_debugfs_del_dev(ionic); mutex_destroy(&ionic->dev_cmd_lock); ionic_devlink_free(ionic);
Pull out a chunk of code from ionic_remove() that will be common in teardown paths. Signed-off-by: Shannon Nelson <shannon.nelson@amd.com> --- .../ethernet/pensando/ionic/ionic_bus_pci.c | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-)