aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris J Arges <chris.j.arges@canonical.com>2014-12-05 18:02:42 -0500
committerBjorn Helgaas <bhelgaas@google.com>2015-01-09 12:55:16 -0500
commit94a90312e4ef1b03469086d41fedfa55e67a1532 (patch)
treee115eae3c5c4cdad5eda0e324259a9a28d323320
parent97bf6af1f928216fd6c5a66e8a57bfa95a659672 (diff)
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>
-rw-r--r--drivers/pci/pcie/aspm.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index e1e7026b838d..820740a22e94 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -859,7 +859,10 @@ static ssize_t link_state_store(struct device *dev,
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,
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