Factor out getting the link associated with a pci_dev and use this helper where appropriate. In addition this helper will be used in a subsequent patch of this series. Signed-off-by: Heiner Kallweit <hkallweit1@xxxxxxxxx> --- v7: - add as separate patch --- drivers/pci/pcie/aspm.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 574f822bf..91cfea673 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -1066,19 +1066,28 @@ void pcie_aspm_powersave_config_link(struct pci_dev *pdev) up_read(&pci_bus_sem); } +static struct pcie_link_state *pcie_aspm_get_link(struct pci_dev *pdev) +{ + struct pci_dev *upstream; + + if (pcie_downstream_port(pdev)) + upstream = pdev; + else + upstream = pci_upstream_bridge(pdev); + + return upstream ? upstream->link_state : NULL; +} + static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem) { - struct pci_dev *parent = pdev->bus->self; struct pcie_link_state *link; if (!pci_is_pcie(pdev)) return 0; - if (pcie_downstream_port(pdev)) - parent = pdev; - if (!parent || !parent->link_state) + link = pcie_aspm_get_link(pdev); + if (!link) return -EINVAL; - /* * A driver requested that ASPM be disabled on this device, but * if we don't have permission to manage ASPM (e.g., on ACPI @@ -1095,7 +1104,6 @@ static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem) if (sem) down_read(&pci_bus_sem); mutex_lock(&aspm_lock); - link = parent->link_state; if (state & PCIE_LINK_STATE_L0S) link->aspm_disable |= ASPM_STATE_L0S; if (state & PCIE_LINK_STATE_L1) @@ -1188,14 +1196,14 @@ module_param_call(policy, pcie_aspm_set_policy, pcie_aspm_get_policy, */ bool pcie_aspm_enabled(struct pci_dev *pdev) { - struct pci_dev *bridge = pci_upstream_bridge(pdev); + struct pcie_link_state *link = pcie_aspm_get_link(pdev); bool ret; - if (!bridge) + if (!link) return false; mutex_lock(&aspm_lock); - ret = bridge->link_state ? !!bridge->link_state->aspm_enabled : false; + ret = link->aspm_enabled; mutex_unlock(&aspm_lock); return ret; -- 2.23.0