From: Chris J Arges <chris.j.arges@canonical.com>
To: linux-pci@vger.kernel.org
Cc: Chris J Arges <chris.j.arges@canonical.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Stephen Hemminger <stephen@networkplumber.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH] PCI/ASPM: use standard parsing functions for sysfs setters
Date: Fri, 5 Dec 2014 17:02:42 -0600 [thread overview]
Message-ID: <1417820598-8021-1-git-send-email-chris.j.arges@canonical.com> (raw)
The functions link_state_store, 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.
Signed-off-by: Chris J Arges <chris.j.arges@canonical.com>
---
drivers/pci/pcie/aspm.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index e1e7026..48e1714 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,
{
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 state = 0;
+ u32 val;
+
+ kstrtouint(buf, 10, &val);
if (aspm_disabled)
return -EPERM;
@@ -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);
--
1.9.1
next reply other threads:[~2014-12-05 23:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-05 23:02 Chris J Arges [this message]
2015-01-09 18:23 ` [PATCH] PCI/ASPM: use standard parsing functions for sysfs setters Bjorn Helgaas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1417820598-8021-1-git-send-email-chris.j.arges@canonical.com \
--to=chris.j.arges@canonical.com \
--cc=bhelgaas@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).