Skip to content

Commit 7dd3876

Browse files
committed
PCI: kirin: Add dev struct for of_device_get_match_data()
Bean reported that a622435 ("PCI: kirin: Prefer of_device_get_match_data()") broke kirin_pcie_probe() because it assumed match data of 0 was a failure when in fact, it meant the match data was "(void *)PCIE_KIRIN_INTERNAL_PHY". Therefore, probing of "hisilicon,kirin960-pcie" devices failed with -EINVAL and an "OF data missing" message. Add a struct kirin_pcie_data to encode the PHY type. Then the result of of_device_get_match_data() should always be a non-NULL pointer to a struct kirin_pcie_data that contains the PHY type. Fixes: a622435 ("PCI: kirin: Prefer of_device_get_match_data()") Link: https://lore.kernel.org/r/20220202162659.GA12603@bhelgaas Link: https://lore.kernel.org/r/20220201215941.1203155-1-huobean@gmail.com Reported-by: Bean Huo <beanhuo@micron.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent 053ca37 commit 7dd3876

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

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)