PCI: Use of_device_get_match_data() to simplify probe
Bjorn Helgaas
maintainercover PCI: Use of_device_get_match_data() to simplify probe
This turned into much ado about nothing, but Shailendra's hisi patch prompted similar cleanups in other drivers. It's a minor simplification, but I think worth doing consistently across drivers.
Basically this is Geert's observation that when the driver probe function is called only as a result of matching something in <match_table>, a subsequent of_match_device(<match_table>, dev) call should never fail.
Therefore, instead of this:
struct of_device_id *match;
match = of_match_device(<match_table>, dev); ... = match->data;
we can do this:
... = of_device_get_match_data(dev);
---
Bjorn Helgaas (3):
PCI: iproc: Use of_device_get_match_data() to simplify probe
PCI: layerscape: Use of_device_get_match_data() to simplify probe
PCI: rcar: Use of_device_get_match_data() to simplify probe
Shailendra Verma (1):
PCI: hisi: Use of_device_get_match_data() to simplify probe
drivers/pci/host/pci-layerscape.c | 7 +------ drivers/pci/host/pcie-hisi.c | 8 +++----- drivers/pci/host/pcie-iproc-platform.c | 7 +------ drivers/pci/host/pcie-rcar.c | 7 +------ 4 files changed, 6 insertions(+), 23 deletions(-)
Bjorn Helgaas
maintainerPATCH 1/4 PCI: hisi: Use of_device_get_match_data() to simplify probe
From: Shailendra Verma <[email protected]>
The only way to call hisi_pcie_probe() is to match an entry in hisi_pcie_of_match[], so match cannot be NULL.
Use of_device_get_match_data() to retrieve the soc_ops pointer. No functional change intended.
[bhelgaas: use of_device_get_match_data(), changelog]
Based-on-suggestion-from: Geert Uytterhoeven <[email protected]>
--- drivers/pci/host/pcie-hisi.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/pci/host/pcie-hisi.c +3 -5
@@ -139,7 +139,7 @@ struct hisi_pcie {struct pcie_port pp;/* pp.dbi_base is DT rc_dbi */ struct regmap *subctrl;u32 port_id; -struct pcie_soc_ops *soc_ops; +const struct pcie_soc_ops *soc_ops; };/* HipXX PCIe host only supports 32-bit config access */
@@ -259,7 +259,6 @@ static int hisi_pcie_probe(struct platform_device *pdev)struct device *dev = &pdev->dev;struct hisi_pcie *hisi_pcie;struct pcie_port *pp; -const struct of_device_id *match;struct resource *reg;struct device_driver *driver;int ret;
@@ -272,11 +271,10 @@ static int hisi_pcie_probe(struct platform_device *pdev) pp->dev = dev; driver = dev->driver; - match =of_match_device (driver->of_match_table, dev); - hisi_pcie->soc_ops = (struct pcie_soc_ops *) match->data; + hisi_pcie->soc_ops =of_device_get_match_data (dev); hisi_pcie->subctrl = -syscon_regmap_lookup_by_compatible ("hisilicon,pcie-sas-subctrl" ); +syscon_regmap_lookup_by_compatible ("hisilicon,pcie-sas-subctrl" );if (IS_ERR (hisi_pcie->subctrl)) {dev_err (dev,"cannot get subctrl base\n" );return PTR_ERR (hisi_pcie->subctrl);
Bjorn Helgaas
maintainerPATCH 2/4 PCI: iproc: Use of_device_get_match_data() to simplify probe
In reply to Bjorn HelgaasThe only way to call iproc_pcie_pltfm_probe() is to match an entry in iproc_pcie_of_match_table[], so match cannot be NULL.
Use of_device_get_match_data() to retrieve the pcie->type. No functional change intended.
Based-on-suggestion-from: Geert Uytterhoeven <[email protected]>
--- drivers/pci/host/pcie-iproc-platform.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/pci/host/pcie-iproc-platform.c +1 -6
@@ -47,7 +47,6 @@ MODULE_DEVICE_TABLE(of, iproc_pcie_of_match_table);static int iproc_pcie_pltfm_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; -const struct of_device_id *of_id;struct iproc_pcie *pcie;struct device_node *np = dev->of_node;struct resource reg;
@@ -55,16 +54,12 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)LIST_HEAD (res);int ret; - of_id =of_match_device (iproc_pcie_of_match_table, dev); -if (!of_id) -return -EINVAL ; - pcie =devm_kzalloc (dev,sizeof (*pcie),GFP_KERNEL );if (!pcie)return -ENOMEM ; pcie->dev = dev; - pcie->type = (enum iproc_pcie_type )of_id->data; + pcie->type = (enum iproc_pcie_type )of_device_get_match_data (dev); ret =of_address_to_resource (np,0 , ®);if (ret <0 ) {
Bjorn Helgaas
maintainerPATCH 3/4 PCI: layerscape: Use of_device_get_match_data() to simplify probe
In reply to Bjorn HelgaasThe only way to call ls_pcie_probe() is to match an entry in ls_pcie_of_match[], so match cannot be NULL.
Use of_device_get_match_data() to retrieve the drvdata pointer. No functional change intended.
Based-on-suggestion-from: Geert Uytterhoeven <[email protected]>
--- drivers/pci/host/pci-layerscape.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/pci/host/pci-layerscape.c +1 -6
@@ -239,23 +239,18 @@ static int __init ls_add_pcie_port(struct ls_pcie *pcie)static int __init ls_pcie_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; -const struct of_device_id *match;struct ls_pcie *pcie;struct pcie_port *pp;struct resource *dbi_base;int ret; - match =of_match_device (ls_pcie_of_match, dev); -if (!match) -return -ENODEV ; - pcie =devm_kzalloc (dev,sizeof (*pcie),GFP_KERNEL );if (!pcie)return -ENOMEM ; pp = &pcie->pp; pp->dev = dev; - pcie->drvdata = match->data; + pcie->drvdata =of_device_get_match_data (dev); pp->ops = pcie->drvdata->ops; dbi_base =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"regs" );
Bjorn Helgaas
maintainerPATCH 4/4 PCI: rcar: Use of_device_get_match_data() to simplify probe
In reply to Bjorn HelgaasThis is a DT-only driver, so the only way to call rcar_pcie_probe() is to match an entry in rcar_pcie_of_match[], so of_id cannot be NULL.
Furthermore, of_id->data can only be NULL if an rcar_pcie_of_match[] entry has a NULL .data member. That's a driver defect, and we don't want to return -EINVAL, which is easy to ignore. We'd rather take the NULL pointer dereference so we notice the problem and fix it.
Use of_device_get_match_data() to retrieve the hw_init_fn pointer. No functional change intended.
--- drivers/pci/host/pcie-rcar.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/pci/host/pcie-rcar.c +1 -6
@@ -1125,7 +1125,6 @@ static int rcar_pcie_probe(struct platform_device *pdev)struct device *dev = &pdev->dev;struct rcar_pcie *pcie;unsigned int data; -const struct of_device_id *of_id;int err;int (*hw_init_fn)(struct rcar_pcie *);
@@ -1149,11 +1148,6 @@ static int rcar_pcie_probe(struct platform_device *pdev)if (err)return err; - of_id =of_match_device (rcar_pcie_of_match, dev); -if (!of_id || !of_id->data) -return -EINVAL ; - hw_init_fn = of_id->data; -pm_runtime_enable (dev); err =pm_runtime_get_sync (dev);if (err <0 ) {
@@ -1162,6 +1156,7 @@ static int rcar_pcie_probe(struct platform_device *pdev) }/* Failure to get a link might just be that no cards are inserted */ + hw_init_fn =of_device_get_match_data (dev); err =hw_init_fn (pcie);if (err) {dev_info (dev,"PCIe link down\n" );
PATCH 4/4 PCI: rcar: Use of_device_get_match_data() to simplify probe
Quoted 8 lines · Bjorn Helgaas
This is a DT-only driver, so the only way to call
rcar_pcie_probe()is to match an entry in rcar_pcie_of_match[], soof_idcannot be NULL.Furthermore,
of_id->datacan only be NULL if an rcar_pcie_of_match[] entry has a NULL .data member. That's a driver defect, and we don't want to return-EINVAL, which is easy to ignore. We'd rather take the NULL pointer dereference so we notice the problem and fix it.
Quoted 5 lines
Use
of_device_get_match_data()to retrieve thehw_init_fnpointer. No functional change intended.Suggested-by Geert Uytterhoeven <[email protected]>Signed-off-by Bjorn Helgaas <[email protected]>
Quoted 37 lines
--- drivers/pci/host/pcie-rcar.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)drivers/pci/host/pcie-rcar.c +1
-6@@ -1125,7 +1125,6 @@ static int rcar_pcie_probe(struct platform_device *pdev)struct device *dev = &pdev->dev;struct rcar_pcie *pcie;unsigned int data; -const struct of_device_id *of_id;int err;int (*hw_init_fn)(struct rcar_pcie *);@@ -1149,11 +1148,6 @@ static int rcar_pcie_probe(struct platform_device *pdev)if (err)return err; - of_id =of_match_device (rcar_pcie_of_match, dev); -if (!of_id || !of_id->data) -return -EINVAL ; - hw_init_fn = of_id->data; -pm_runtime_enable (dev); err =pm_runtime_get_sync (dev);if (err <0 ) {@@ -1162,6 +1156,7 @@ static int rcar_pcie_probe(struct platform_device *pdev) }/* Failure to get a link might just be that no cards are inserted */ + hw_init_fn =of_device_get_match_data (dev); err =hw_init_fn (pcie);if (err) {dev_info (dev,"PCIe link down\n" );
Bjorn Helgaas
Appliedcover PCI: Use of_device_get_match_data() to simplify probe
In reply to Bjorn HelgaasQuoted 30 lines · Bjorn Helgaas
This turned into much ado about nothing, but Shailendra's hisi patch prompted similar cleanups in other drivers. It's a minor simplification, but I think worth doing consistently across drivers.
Basically this is Geert's observation that when the driver probe function is called only as a result of matching something in <
match_table>, a subsequentof_match_device(<match_table>, dev)call should never fail.Therefore, instead of this:
struct
of_device_id*match;match = of_match_device(<match_table>, dev); ... = match->data;we can do this:
... = of_device_get_match_data(dev);---
Bjorn Helgaas (3):
PCI: iproc: Useof_device_get_match_data()to simplify probe
PCI: layerscape: Useof_device_get_match_data()to simplify probe
PCI: rcar: Useof_device_get_match_data()to simplify probeShailendra Verma (1):
PCI: hisi: Useof_device_get_match_data()to simplify probe
Quoted 5 lines
drivers/pci/host/pci-layerscape.c | 7 +------ drivers/pci/host/pcie-hisi.c | 8 +++----- drivers/pci/host/pcie-iproc-platform.c | 7 +------ drivers/pci/host/pcie-rcar.c | 7 +------ 4 files changed, 6 insertions(+), 23 deletions(-)
I applied these to pci/host-layerscape, pci/host-hisi, pci/host-iproc, pci/host-rcar for v4.11.