Skip to content

Commit 2849752

Browse files
committed
xen/pcifront: move xenstore config scanning into sub-function
pcifront_try_connect() and pcifront_attach_devices() share a large chunk of duplicated code for reading the config information from Xenstore, which only differs regarding calling pcifront_rescan_root() or pcifront_scan_root(). Put that code into a new sub-function. It is fine to always call pcifront_rescan_root() from that common function, as it will fallback to pcifront_scan_root() if the domain/bus combination isn't known yet (and pcifront_scan_root() should never be called for an already known domain/bus combination anyway). In order to avoid duplicate messages for the fallback case move the check for domain/bus not known to the beginning of pcifront_rescan_root(). While at it fix the error reporting in case the root-xx node had the wrong format. As the return value of pcifront_try_connect() and pcifront_attach_devices() are not used anywhere make those functions return void. As an additional bonus this removes the dubious return of -EFAULT in case of an unexpected driver state. Signed-off-by: Juergen Gross <[email protected]> Reviewed-by: Jason Andryuk <[email protected]> Signed-off-by: Juergen Gross <[email protected]>
1 parent 5c13a4a commit 2849752

File tree

1 file changed

+37
-106
lines changed

1 file changed

+37
-106
lines changed

drivers/pci/xen-pcifront.c

Lines changed: 37 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -521,24 +521,14 @@ static int pcifront_rescan_root(struct pcifront_device *pdev,
521521
int err;
522522
struct pci_bus *b;
523523

524-
#ifndef CONFIG_PCI_DOMAINS
525-
if (domain != 0) {
526-
dev_err(&pdev->xdev->dev,
527-
"PCI Root in non-zero PCI Domain! domain=%d\n", domain);
528-
dev_err(&pdev->xdev->dev,
529-
"Please compile with CONFIG_PCI_DOMAINS\n");
530-
return -EINVAL;
531-
}
532-
#endif
533-
534-
dev_info(&pdev->xdev->dev, "Rescanning PCI Frontend Bus %04x:%02x\n",
535-
domain, bus);
536-
537524
b = pci_find_bus(domain, bus);
538525
if (!b)
539526
/* If the bus is unknown, create it. */
540527
return pcifront_scan_root(pdev, domain, bus);
541528

529+
dev_info(&pdev->xdev->dev, "Rescanning PCI Frontend Bus %04x:%02x\n",
530+
domain, bus);
531+
542532
err = pcifront_scan_bus(pdev, domain, bus, b);
543533

544534
/* Claim resources before going "live" with our devices */
@@ -819,76 +809,73 @@ static int pcifront_publish_info(struct pcifront_device *pdev)
819809
return err;
820810
}
821811

822-
static int pcifront_try_connect(struct pcifront_device *pdev)
812+
static void pcifront_connect(struct pcifront_device *pdev)
823813
{
824-
int err = -EFAULT;
814+
int err;
825815
int i, num_roots, len;
826816
char str[64];
827817
unsigned int domain, bus;
828818

829-
830-
/* Only connect once */
831-
if (xenbus_read_driver_state(pdev->xdev->nodename) !=
832-
XenbusStateInitialised)
833-
goto out;
834-
835-
err = pcifront_connect_and_init_dma(pdev);
836-
if (err && err != -EEXIST) {
837-
xenbus_dev_fatal(pdev->xdev, err,
838-
"Error setting up PCI Frontend");
839-
goto out;
840-
}
841-
842819
err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend,
843820
"root_num", "%d", &num_roots);
844821
if (err == -ENOENT) {
845822
xenbus_dev_error(pdev->xdev, err,
846823
"No PCI Roots found, trying 0000:00");
847-
err = pcifront_scan_root(pdev, 0, 0);
824+
err = pcifront_rescan_root(pdev, 0, 0);
848825
if (err) {
849826
xenbus_dev_fatal(pdev->xdev, err,
850827
"Error scanning PCI root 0000:00");
851-
goto out;
828+
return;
852829
}
853830
num_roots = 0;
854831
} else if (err != 1) {
855-
if (err == 0)
856-
err = -EINVAL;
857-
xenbus_dev_fatal(pdev->xdev, err,
832+
xenbus_dev_fatal(pdev->xdev, err >= 0 ? -EINVAL : err,
858833
"Error reading number of PCI roots");
859-
goto out;
834+
return;
860835
}
861836

862837
for (i = 0; i < num_roots; i++) {
863838
len = snprintf(str, sizeof(str), "root-%d", i);
864-
if (unlikely(len >= (sizeof(str) - 1))) {
865-
err = -ENOMEM;
866-
goto out;
867-
}
839+
if (unlikely(len >= (sizeof(str) - 1)))
840+
return;
868841

869842
err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, str,
870843
"%x:%x", &domain, &bus);
871844
if (err != 2) {
872-
if (err >= 0)
873-
err = -EINVAL;
874-
xenbus_dev_fatal(pdev->xdev, err,
845+
xenbus_dev_fatal(pdev->xdev, err >= 0 ? -EINVAL : err,
875846
"Error reading PCI root %d", i);
876-
goto out;
847+
return;
877848
}
878849

879-
err = pcifront_scan_root(pdev, domain, bus);
850+
err = pcifront_rescan_root(pdev, domain, bus);
880851
if (err) {
881852
xenbus_dev_fatal(pdev->xdev, err,
882853
"Error scanning PCI root %04x:%02x",
883854
domain, bus);
884-
goto out;
855+
return;
885856
}
886857
}
887858

888-
err = xenbus_switch_state(pdev->xdev, XenbusStateConnected);
859+
xenbus_switch_state(pdev->xdev, XenbusStateConnected);
860+
}
889861

890-
out:
891-
return err;
862+
static void pcifront_try_connect(struct pcifront_device *pdev)
863+
{
864+
int err;
865+
866+
/* Only connect once */
867+
if (xenbus_read_driver_state(pdev->xdev->nodename) !=
868+
XenbusStateInitialised)
869+
return;
870+
871+
err = pcifront_connect_and_init_dma(pdev);
872+
if (err && err != -EEXIST) {
873+
xenbus_dev_fatal(pdev->xdev, err,
874+
"Error setting up PCI Frontend");
875+
return;
876+
}
877+
878+
pcifront_connect(pdev);
892879
}
893880

894881
static int pcifront_try_disconnect(struct pcifront_device *pdev)
@@ -914,67 +901,11 @@ static int pcifront_try_disconnect(struct pcifront_device *pdev)
914901
return err;
915902
}
916903

917-
static int pcifront_attach_devices(struct pcifront_device *pdev)
904+
static void pcifront_attach_devices(struct pcifront_device *pdev)
918905
{
919-
int err = -EFAULT;
920-
int i, num_roots, len;
921-
unsigned int domain, bus;
922-
char str[64];
923-
924-
if (xenbus_read_driver_state(pdev->xdev->nodename) !=
906+
if (xenbus_read_driver_state(pdev->xdev->nodename) ==
925907
XenbusStateReconfiguring)
926-
goto out;
927-
928-
err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend,
929-
"root_num", "%d", &num_roots);
930-
if (err == -ENOENT) {
931-
xenbus_dev_error(pdev->xdev, err,
932-
"No PCI Roots found, trying 0000:00");
933-
err = pcifront_rescan_root(pdev, 0, 0);
934-
if (err) {
935-
xenbus_dev_fatal(pdev->xdev, err,
936-
"Error scanning PCI root 0000:00");
937-
goto out;
938-
}
939-
num_roots = 0;
940-
} else if (err != 1) {
941-
if (err == 0)
942-
err = -EINVAL;
943-
xenbus_dev_fatal(pdev->xdev, err,
944-
"Error reading number of PCI roots");
945-
goto out;
946-
}
947-
948-
for (i = 0; i < num_roots; i++) {
949-
len = snprintf(str, sizeof(str), "root-%d", i);
950-
if (unlikely(len >= (sizeof(str) - 1))) {
951-
err = -ENOMEM;
952-
goto out;
953-
}
954-
955-
err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, str,
956-
"%x:%x", &domain, &bus);
957-
if (err != 2) {
958-
if (err >= 0)
959-
err = -EINVAL;
960-
xenbus_dev_fatal(pdev->xdev, err,
961-
"Error reading PCI root %d", i);
962-
goto out;
963-
}
964-
965-
err = pcifront_rescan_root(pdev, domain, bus);
966-
if (err) {
967-
xenbus_dev_fatal(pdev->xdev, err,
968-
"Error scanning PCI root %04x:%02x",
969-
domain, bus);
970-
goto out;
971-
}
972-
}
973-
974-
xenbus_switch_state(pdev->xdev, XenbusStateConnected);
975-
976-
out:
977-
return err;
908+
pcifront_connect(pdev);
978909
}
979910

980911
static int pcifront_detach_devices(struct pcifront_device *pdev)

0 commit comments

Comments
 (0)