Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PCI: dwc: Use devm_pci_alloc_host_bridge() to simplify code

Use devm_pci_alloc_host_bridge() to simplify the error code path. This
also fixes a leak in the dw_pcie_host_init() error path.

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
CC: stable@vger.kernel.org # v4.13+

authored by

Jisheng Zhang and committed by
Bjorn Helgaas
e6fdd3bf 9e2b5de5

+8 -13
+8 -13
drivers/pci/controller/dwc/pcie-designware-host.c
··· 358 358 dev_err(dev, "Missing *config* reg space\n"); 359 359 } 360 360 361 - bridge = pci_alloc_host_bridge(0); 361 + bridge = devm_pci_alloc_host_bridge(dev, 0); 362 362 if (!bridge) 363 363 return -ENOMEM; 364 364 ··· 369 369 370 370 ret = devm_request_pci_bus_resources(dev, &bridge->windows); 371 371 if (ret) 372 - goto error; 372 + return ret; 373 373 374 374 /* Get the I/O and memory ranges from DT */ 375 375 resource_list_for_each_entry_safe(win, tmp, &bridge->windows) { ··· 413 413 resource_size(pp->cfg)); 414 414 if (!pci->dbi_base) { 415 415 dev_err(dev, "Error with ioremap\n"); 416 - ret = -ENOMEM; 417 - goto error; 416 + return -ENOMEM; 418 417 } 419 418 } 420 419 ··· 424 425 pp->cfg0_base, pp->cfg0_size); 425 426 if (!pp->va_cfg0_base) { 426 427 dev_err(dev, "Error with ioremap in function\n"); 427 - ret = -ENOMEM; 428 - goto error; 428 + return -ENOMEM; 429 429 } 430 430 } 431 431 ··· 434 436 pp->cfg1_size); 435 437 if (!pp->va_cfg1_base) { 436 438 dev_err(dev, "Error with ioremap\n"); 437 - ret = -ENOMEM; 438 - goto error; 439 + return -ENOMEM; 439 440 } 440 441 } 441 442 ··· 457 460 pp->num_vectors == 0) { 458 461 dev_err(dev, 459 462 "Invalid number of vectors\n"); 460 - goto error; 463 + return -EINVAL; 461 464 } 462 465 } 463 466 464 467 if (!pp->ops->msi_host_init) { 465 468 ret = dw_pcie_allocate_domains(pp); 466 469 if (ret) 467 - goto error; 470 + return ret; 468 471 469 472 if (pp->msi_irq) 470 473 irq_set_chained_handler_and_data(pp->msi_irq, ··· 473 476 } else { 474 477 ret = pp->ops->msi_host_init(pp); 475 478 if (ret < 0) 476 - goto error; 479 + return ret; 477 480 } 478 481 } 479 482 ··· 513 516 err_free_msi: 514 517 if (pci_msi_enabled() && !pp->ops->msi_host_init) 515 518 dw_pcie_free_msi(pp); 516 - error: 517 - pci_free_host_bridge(bridge); 518 519 return ret; 519 520 } 520 521