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
859859 {
860860 struct pci_dev *pdev = to_pci_dev(dev);
861861 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;
863866
864867 if (aspm_disabled)
865868 return -EPERM;
@@ -900,15 +903,14 @@ static ssize_t clk_ctl_store(struct device *dev, · 34 unmodified lines
900903 size_t n)
901904 {
902905 struct pci_dev *pdev = to_pci_dev(dev);
903− int state;
906+ bool state;
904907
905− if (n < 1)
908+ if (strtobool(buf, &state))
906909 return -EINVAL;
907− state = buf[0]-'0';
908910
909911 down_read(&pci_bus_sem);
910912 mutex_lock(&aspm_lock);
911− pcie_set_clkpm_nocheck(pdev->link_state, !!state);
913+ pcie_set_clkpm_nocheck(pdev->link_state, state);
912914 mutex_unlock(&aspm_lock);
913915 up_read(&pci_bus_sem);
914916

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