[PATCH] PCI/ASPM: Reject sysfs attempts to enable states that are not covered by policy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When trying to enable a state that is not covered by the policy,
then the change request will be silently ignored. That's not too
nice to the user, therefore reject such attempts explicitly.

Signed-off-by: Heiner Kallweit <hkallweit1@xxxxxxxxx>
---
 drivers/pci/pcie/aspm.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index b17e5ffd3..cd0f30ca9 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -1224,11 +1224,16 @@ static ssize_t aspm_attr_store_common(struct device *dev,
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
 	struct pcie_link_state *link = pcie_aspm_get_link(pdev);
+	u32 policy_state = policy_to_aspm_state(link);
 	bool state_enable;
 
 	if (strtobool(buf, &state_enable) < 0)
 		return -EINVAL;
 
+	/* reject attempts to enable states not covered by policy */
+	if (state_enable && state & ~policy_state)
+		return -EPERM;
+
 	down_read(&pci_bus_sem);
 	mutex_lock(&aspm_lock);
 
@@ -1241,7 +1246,7 @@ static ssize_t aspm_attr_store_common(struct device *dev,
 		link->aspm_disable |= state;
 	}
 
-	pcie_config_aspm_link(link, policy_to_aspm_state(link));
+	pcie_config_aspm_link(link, policy_state);
 
 	mutex_unlock(&aspm_lock);
 	up_read(&pci_bus_sem);
-- 
2.27.0




[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux