Skip to content

Commit

Permalink
PCI/ASPM: Use standard parsing functions for sysfs setters
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Chris J Arges authored and Bjorn Helgaas committed Jan 9, 2015
1 parent 97bf6af commit 94a9031
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions drivers/pci/pcie/aspm.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,10 @@ static ssize_t link_state_store(struct device *dev,
{
struct pci_dev *pdev = to_pci_dev(dev);
struct pcie_link_state *link, *root = pdev->link_state->root;
u32 val = buf[0] - '0', state = 0;
u32 val, state = 0;

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

if (aspm_disabled)
return -EPERM;
Expand Down Expand Up @@ -900,15 +903,14 @@ static ssize_t clk_ctl_store(struct device *dev,
size_t n)
{
struct pci_dev *pdev = to_pci_dev(dev);
int state;
bool state;

if (n < 1)
if (strtobool(buf, &state))
return -EINVAL;
state = buf[0]-'0';

down_read(&pci_bus_sem);
mutex_lock(&aspm_lock);
pcie_set_clkpm_nocheck(pdev->link_state, !!state);
pcie_set_clkpm_nocheck(pdev->link_state, state);
mutex_unlock(&aspm_lock);
up_read(&pci_bus_sem);

Expand Down

0 comments on commit 94a9031

Please sign in to comment.