Skip to content

Commit 942ceba

Browse files
Mani-Sadhasivambjorn-helgaas
authored andcommitted
PCI: endpoint: pci-epf-test: Refactor pci_epf_test_unbind() function
Move the pci_epc_clear_bar() and pci_epf_free_space() code to respective helper functions. This allows reusing the helpers in future commits. This also requires moving the pci_epf_test_unbind() definition below pci_epf_test_bind() to avoid forward declaration of the above helpers. No functional change. Link: https://lore.kernel.org/linux-pci/[email protected] Tested-by: Niklas Cassel <[email protected]> Signed-off-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Niklas Cassel <[email protected]>
1 parent f58838d commit 942ceba

File tree

1 file changed

+39
-19
lines changed

1 file changed

+39
-19
lines changed

drivers/pci/endpoint/functions/pci-epf-test.c

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -686,25 +686,6 @@ static void pci_epf_test_cmd_handler(struct work_struct *work)
686686
msecs_to_jiffies(1));
687687
}
688688

689-
static void pci_epf_test_unbind(struct pci_epf *epf)
690-
{
691-
struct pci_epf_test *epf_test = epf_get_drvdata(epf);
692-
struct pci_epc *epc = epf->epc;
693-
int bar;
694-
695-
cancel_delayed_work(&epf_test->cmd_handler);
696-
pci_epf_test_clean_dma_chan(epf_test);
697-
for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
698-
if (!epf_test->reg[bar])
699-
continue;
700-
701-
pci_epc_clear_bar(epc, epf->func_no, epf->vfunc_no,
702-
&epf->bar[bar]);
703-
pci_epf_free_space(epf, epf_test->reg[bar], bar,
704-
PRIMARY_INTERFACE);
705-
}
706-
}
707-
708689
static int pci_epf_test_set_bar(struct pci_epf *epf)
709690
{
710691
int bar, ret;
@@ -731,6 +712,21 @@ static int pci_epf_test_set_bar(struct pci_epf *epf)
731712
return 0;
732713
}
733714

715+
static void pci_epf_test_clear_bar(struct pci_epf *epf)
716+
{
717+
struct pci_epf_test *epf_test = epf_get_drvdata(epf);
718+
struct pci_epc *epc = epf->epc;
719+
int bar;
720+
721+
for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
722+
if (!epf_test->reg[bar])
723+
continue;
724+
725+
pci_epc_clear_bar(epc, epf->func_no, epf->vfunc_no,
726+
&epf->bar[bar]);
727+
}
728+
}
729+
734730
static int pci_epf_test_epc_init(struct pci_epf *epf)
735731
{
736732
struct pci_epf_test *epf_test = epf_get_drvdata(epf);
@@ -845,6 +841,20 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)
845841
return 0;
846842
}
847843

844+
static void pci_epf_test_free_space(struct pci_epf *epf)
845+
{
846+
struct pci_epf_test *epf_test = epf_get_drvdata(epf);
847+
int bar;
848+
849+
for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
850+
if (!epf_test->reg[bar])
851+
continue;
852+
853+
pci_epf_free_space(epf, epf_test->reg[bar], bar,
854+
PRIMARY_INTERFACE);
855+
}
856+
}
857+
848858
static int pci_epf_test_bind(struct pci_epf *epf)
849859
{
850860
int ret;
@@ -882,6 +892,16 @@ static int pci_epf_test_bind(struct pci_epf *epf)
882892
return 0;
883893
}
884894

895+
static void pci_epf_test_unbind(struct pci_epf *epf)
896+
{
897+
struct pci_epf_test *epf_test = epf_get_drvdata(epf);
898+
899+
cancel_delayed_work(&epf_test->cmd_handler);
900+
pci_epf_test_clean_dma_chan(epf_test);
901+
pci_epf_test_clear_bar(epf);
902+
pci_epf_test_free_space(epf);
903+
}
904+
885905
static const struct pci_epf_device_id pci_epf_test_ids[] = {
886906
{
887907
.name = "pci_epf_test",

0 commit comments

Comments
 (0)