Skip to content

Commit 8e0f5a9

Browse files
Dan Carpenterkwilczynski
authored andcommitted
PCI: endpoint: Clean up error handling in vpci_scan_bus()
Smatch complains about inconsistent NULL checking in vpci_scan_bus(): drivers/pci/endpoint/functions/pci-epf-vntb.c:1024 vpci_scan_bus() error: we previously assumed 'vpci_bus' could be null (see line 1021) Instead of printing an error message and then crashing we should return an error code and clean up. Also the NULL check is reversed so it prints an error for success instead of failure. Fixes: e35f56b ("PCI: endpoint: Support NTB transfer between RC and EP") Link: https://lore.kernel.org/linux-pci/[email protected] Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]>
1 parent 03377a6 commit 8e0f5a9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,8 +1018,10 @@ static int vpci_scan_bus(void *sysdata)
10181018
struct epf_ntb *ndev = sysdata;
10191019

10201020
vpci_bus = pci_scan_bus(ndev->vbus_number, &vpci_ops, sysdata);
1021-
if (vpci_bus)
1022-
pr_err("create pci bus\n");
1021+
if (!vpci_bus) {
1022+
pr_err("create pci bus failed\n");
1023+
return -EINVAL;
1024+
}
10231025

10241026
pci_bus_add_devices(vpci_bus);
10251027

@@ -1338,10 +1340,14 @@ static int epf_ntb_bind(struct pci_epf *epf)
13381340
goto err_bar_alloc;
13391341
}
13401342

1341-
vpci_scan_bus(ntb);
1343+
ret = vpci_scan_bus(ntb);
1344+
if (ret)
1345+
goto err_unregister;
13421346

13431347
return 0;
13441348

1349+
err_unregister:
1350+
pci_unregister_driver(&vntb_pci_driver);
13451351
err_bar_alloc:
13461352
epf_ntb_config_spad_bar_free(ntb);
13471353

0 commit comments

Comments
 (0)