History

PCI/ASPM: Use standard parsing functions for sysfs setters

The functions link_state_store() and clk_ctl_store() had just subtracted ASCII '0' from input which could lead to undesired results. Instead, use Linux string functions to safely parse input. [bhelgaas: check kstrtouint() return value] Signed-off-by: Chris J Arges <chris.j.arges@canonical.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

Chris J Arges committed 11 years ago

Commit 94a90311 parent 97bf6af1 file · +7 −5Browse files

Unified · Split

drivers/pci/pcie/aspm.c+7−5
@@ -859,7 +859,10 @@ static ssize_t link_state_store(struct device *dev, · 858 unmodified lines
859{859{
860 struct pci_dev *pdev = to_pci_dev(dev);860 struct pci_dev *pdev = to_pci_dev(dev);
861 struct pcie_link_state *link, *root = pdev->link_state->root;861 struct pcie_link_state *link, *root = pdev->link_state->root;
862 u32 val = buf[0] - '0', state = 0;862 u32 val, state = 0;
863
864 if (kstrtouint(buf, 10, &val))
865 return -EINVAL;
863 866
864 if (aspm_disabled)867 if (aspm_disabled)
865 return -EPERM;868 return -EPERM;
@@ -900,15 +903,14 @@ static ssize_t clk_ctl_store(struct device *dev, · 34 unmodified lines
900 size_t n)903 size_t n)
901{904{
902 struct pci_dev *pdev = to_pci_dev(dev);905 struct pci_dev *pdev = to_pci_dev(dev);
903 int state;906 bool state;
904 907
905 if (n < 1)908 if (strtobool(buf, &state))
906 return -EINVAL;909 return -EINVAL;
907 state = buf[0]-'0';
908 910
909 down_read(&pci_bus_sem);911 down_read(&pci_bus_sem);
910 mutex_lock(&aspm_lock);912 mutex_lock(&aspm_lock);
911 pcie_set_clkpm_nocheck(pdev->link_state, !!state);913 pcie_set_clkpm_nocheck(pdev->link_state, state);
912 mutex_unlock(&aspm_lock);914 mutex_unlock(&aspm_lock);
913 up_read(&pci_bus_sem);915 up_read(&pci_bus_sem);
914 916

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t