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(-)
From: Shailendra Verma <redacted>
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 [off-list ref]
Signed-off-by: Shailendra Verma <redacted>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
drivers/pci/host/pcie-hisi.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
The 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 [off-list ref]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
drivers/pci/host/pcie-iproc-platform.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
The 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 [off-list ref]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
drivers/pci/host/pci-layerscape.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
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[], 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.
Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
drivers/pci/host/pcie-rcar.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
@@ -1125,7 +1125,6 @@ static int rcar_pcie_probe(struct platform_device *pdev)structdevice*dev=&pdev->dev;structrcar_pcie*pcie;unsignedintdata;-conststructof_device_id*of_id;interr;int(*hw_init_fn)(structrcar_pcie*);
@@ -1149,11 +1148,6 @@ static int rcar_pcie_probe(struct platform_device *pdev)if(err)returnerr;-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");
On Tue, Jan 31, 2017 at 02:20:20PM -0600, Bjorn Helgaas wrote:
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[], 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.
Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
@@ -1125,7 +1125,6 @@ static int rcar_pcie_probe(struct platform_device *pdev)structdevice*dev=&pdev->dev;structrcar_pcie*pcie;unsignedintdata;-conststructof_device_id*of_id;interr;int(*hw_init_fn)(structrcar_pcie*);
@@ -1149,11 +1148,6 @@ static int rcar_pcie_probe(struct platform_device *pdev)if(err)returnerr;-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");
On Tue, Jan 31, 2017 at 02:19:51PM -0600, Bjorn Helgaas wrote:
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(-)
I applied these to pci/host-layerscape, pci/host-hisi, pci/host-iproc,
pci/host-rcar for v4.11.