Skip to content

Commit e09e1a4

Browse files
committed
Merge tag 'pci-v5.17-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci
Pull pci fixes from Bjorn Helgaas: - Restructure j721e_pcie_probe() so we don't dereference a NULL pointer (Bjorn Helgaas) - Add a kirin_pcie_data struct to identify different Kirin variants to fix probe failure for controllers with an internal PHY (Bjorn Helgaas) * tag 'pci-v5.17-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci: PCI: kirin: Add dev struct for of_device_get_match_data() PCI: j721e: Initialize pcie->cdns_pcie before using it
2 parents 86286e4 + 7dd3876 commit e09e1a4

File tree

2 files changed

+60
-56
lines changed

2 files changed

+60
-56
lines changed

drivers/pci/controller/cadence/pci-j721e.c

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ static int j721e_pcie_probe(struct platform_device *pdev)
356356
const struct j721e_pcie_data *data;
357357
struct cdns_pcie *cdns_pcie;
358358
struct j721e_pcie *pcie;
359-
struct cdns_pcie_rc *rc;
360-
struct cdns_pcie_ep *ep;
359+
struct cdns_pcie_rc *rc = NULL;
360+
struct cdns_pcie_ep *ep = NULL;
361361
struct gpio_desc *gpiod;
362362
void __iomem *base;
363363
struct clk *clk;
@@ -376,6 +376,46 @@ static int j721e_pcie_probe(struct platform_device *pdev)
376376
if (!pcie)
377377
return -ENOMEM;
378378

379+
switch (mode) {
380+
case PCI_MODE_RC:
381+
if (!IS_ENABLED(CONFIG_PCIE_CADENCE_HOST))
382+
return -ENODEV;
383+
384+
bridge = devm_pci_alloc_host_bridge(dev, sizeof(*rc));
385+
if (!bridge)
386+
return -ENOMEM;
387+
388+
if (!data->byte_access_allowed)
389+
bridge->ops = &cdns_ti_pcie_host_ops;
390+
rc = pci_host_bridge_priv(bridge);
391+
rc->quirk_retrain_flag = data->quirk_retrain_flag;
392+
rc->quirk_detect_quiet_flag = data->quirk_detect_quiet_flag;
393+
394+
cdns_pcie = &rc->pcie;
395+
cdns_pcie->dev = dev;
396+
cdns_pcie->ops = &j721e_pcie_ops;
397+
pcie->cdns_pcie = cdns_pcie;
398+
break;
399+
case PCI_MODE_EP:
400+
if (!IS_ENABLED(CONFIG_PCIE_CADENCE_EP))
401+
return -ENODEV;
402+
403+
ep = devm_kzalloc(dev, sizeof(*ep), GFP_KERNEL);
404+
if (!ep)
405+
return -ENOMEM;
406+
407+
ep->quirk_detect_quiet_flag = data->quirk_detect_quiet_flag;
408+
409+
cdns_pcie = &ep->pcie;
410+
cdns_pcie->dev = dev;
411+
cdns_pcie->ops = &j721e_pcie_ops;
412+
pcie->cdns_pcie = cdns_pcie;
413+
break;
414+
default:
415+
dev_err(dev, "INVALID device type %d\n", mode);
416+
return 0;
417+
}
418+
379419
pcie->mode = mode;
380420
pcie->linkdown_irq_regfield = data->linkdown_irq_regfield;
381421

@@ -426,28 +466,6 @@ static int j721e_pcie_probe(struct platform_device *pdev)
426466

427467
switch (mode) {
428468
case PCI_MODE_RC:
429-
if (!IS_ENABLED(CONFIG_PCIE_CADENCE_HOST)) {
430-
ret = -ENODEV;
431-
goto err_get_sync;
432-
}
433-
434-
bridge = devm_pci_alloc_host_bridge(dev, sizeof(*rc));
435-
if (!bridge) {
436-
ret = -ENOMEM;
437-
goto err_get_sync;
438-
}
439-
440-
if (!data->byte_access_allowed)
441-
bridge->ops = &cdns_ti_pcie_host_ops;
442-
rc = pci_host_bridge_priv(bridge);
443-
rc->quirk_retrain_flag = data->quirk_retrain_flag;
444-
rc->quirk_detect_quiet_flag = data->quirk_detect_quiet_flag;
445-
446-
cdns_pcie = &rc->pcie;
447-
cdns_pcie->dev = dev;
448-
cdns_pcie->ops = &j721e_pcie_ops;
449-
pcie->cdns_pcie = cdns_pcie;
450-
451469
gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
452470
if (IS_ERR(gpiod)) {
453471
ret = PTR_ERR(gpiod);
@@ -497,23 +515,6 @@ static int j721e_pcie_probe(struct platform_device *pdev)
497515

498516
break;
499517
case PCI_MODE_EP:
500-
if (!IS_ENABLED(CONFIG_PCIE_CADENCE_EP)) {
501-
ret = -ENODEV;
502-
goto err_get_sync;
503-
}
504-
505-
ep = devm_kzalloc(dev, sizeof(*ep), GFP_KERNEL);
506-
if (!ep) {
507-
ret = -ENOMEM;
508-
goto err_get_sync;
509-
}
510-
ep->quirk_detect_quiet_flag = data->quirk_detect_quiet_flag;
511-
512-
cdns_pcie = &ep->pcie;
513-
cdns_pcie->dev = dev;
514-
cdns_pcie->ops = &j721e_pcie_ops;
515-
pcie->cdns_pcie = cdns_pcie;
516-
517518
ret = cdns_pcie_init_phy(dev, cdns_pcie);
518519
if (ret) {
519520
dev_err(dev, "Failed to init phy\n");
@@ -525,8 +526,6 @@ static int j721e_pcie_probe(struct platform_device *pdev)
525526
goto err_pcie_setup;
526527

527528
break;
528-
default:
529-
dev_err(dev, "INVALID device type %d\n", mode);
530529
}
531530

532531
return 0;

drivers/pci/controller/dwc/pcie-kirin.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -756,22 +756,28 @@ static int __exit kirin_pcie_remove(struct platform_device *pdev)
756756
return 0;
757757
}
758758

759+
struct kirin_pcie_data {
760+
enum pcie_kirin_phy_type phy_type;
761+
};
762+
763+
static const struct kirin_pcie_data kirin_960_data = {
764+
.phy_type = PCIE_KIRIN_INTERNAL_PHY,
765+
};
766+
767+
static const struct kirin_pcie_data kirin_970_data = {
768+
.phy_type = PCIE_KIRIN_EXTERNAL_PHY,
769+
};
770+
759771
static const struct of_device_id kirin_pcie_match[] = {
760-
{
761-
.compatible = "hisilicon,kirin960-pcie",
762-
.data = (void *)PCIE_KIRIN_INTERNAL_PHY
763-
},
764-
{
765-
.compatible = "hisilicon,kirin970-pcie",
766-
.data = (void *)PCIE_KIRIN_EXTERNAL_PHY
767-
},
772+
{ .compatible = "hisilicon,kirin960-pcie", .data = &kirin_960_data },
773+
{ .compatible = "hisilicon,kirin970-pcie", .data = &kirin_970_data },
768774
{},
769775
};
770776

771777
static int kirin_pcie_probe(struct platform_device *pdev)
772778
{
773-
enum pcie_kirin_phy_type phy_type;
774779
struct device *dev = &pdev->dev;
780+
const struct kirin_pcie_data *data;
775781
struct kirin_pcie *kirin_pcie;
776782
struct dw_pcie *pci;
777783
int ret;
@@ -781,13 +787,12 @@ static int kirin_pcie_probe(struct platform_device *pdev)
781787
return -EINVAL;
782788
}
783789

784-
phy_type = (long)of_device_get_match_data(dev);
785-
if (!phy_type) {
790+
data = of_device_get_match_data(dev);
791+
if (!data) {
786792
dev_err(dev, "OF data missing\n");
787793
return -EINVAL;
788794
}
789795

790-
791796
kirin_pcie = devm_kzalloc(dev, sizeof(struct kirin_pcie), GFP_KERNEL);
792797
if (!kirin_pcie)
793798
return -ENOMEM;
@@ -800,7 +805,7 @@ static int kirin_pcie_probe(struct platform_device *pdev)
800805
pci->ops = &kirin_dw_pcie_ops;
801806
pci->pp.ops = &kirin_pcie_host_ops;
802807
kirin_pcie->pci = pci;
803-
kirin_pcie->type = phy_type;
808+
kirin_pcie->type = data->phy_type;
804809

805810
ret = kirin_pcie_get_resource(kirin_pcie, pdev);
806811
if (ret)

0 commit comments

Comments
 (0)