Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 57d86a04 authored by Andy Lutomirski's avatar Andy Lutomirski Committed by Bjorn Helgaas
Browse files

PCI/ASPM: Make sysfs link_state_store() consistent with link_state_show()



If CONFIG_PCIEASPM_DEBUG is set, then PCI devices have a link_state
attribute.  Reading that attribute shows the state as a bit mask: 1
means L0S upstream, 2 means L0S downstream, and 4 means L1.

Oddly, writing to link_state is inconsistent and gets translated, leading
to mysterious results in which the value you store isn't comparable the
value you load back out.

Fix it by making link_state_store() match link_state_show().

[bhelgaas: Check "aspm_disabled" *before* validating input.  When
"aspm_disabled" is set, this changes the error for invalid input from
-EINVAL to -EPERM.]

Signed-off-by: default avatarAndy Lutomirski <luto@kernel.org>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
parent 1ec21837
Loading
Loading
Loading
Loading
+5 −11
Original line number Original line Diff line number Diff line
@@ -834,21 +834,15 @@ static ssize_t link_state_store(struct device *dev,
{
{
	struct pci_dev *pdev = to_pci_dev(dev);
	struct pci_dev *pdev = to_pci_dev(dev);
	struct pcie_link_state *link, *root = pdev->link_state->root;
	struct pcie_link_state *link, *root = pdev->link_state->root;
	u32 val, state = 0;
	u32 state;

	if (kstrtouint(buf, 10, &val))
		return -EINVAL;


	if (aspm_disabled)
	if (aspm_disabled)
		return -EPERM;
		return -EPERM;
	if (n < 1 || val > 3)
		return -EINVAL;


	/* Convert requested state to ASPM state */
	if (kstrtouint(buf, 10, &state))
	if (val & PCIE_LINK_STATE_L0S)
		return -EINVAL;
		state |= ASPM_STATE_L0S;
	if ((state & ~ASPM_STATE_ALL) != 0)
	if (val & PCIE_LINK_STATE_L1)
		return -EINVAL;
		state |= ASPM_STATE_L1;


	down_read(&pci_bus_sem);
	down_read(&pci_bus_sem);
	mutex_lock(&aspm_lock);
	mutex_lock(&aspm_lock);