* [PATCH] PCI/ASPM: use standard parsing functions for sysfs setters
@ 2014-12-05 23:02 Chris J Arges
2015-01-09 18:23 ` Bjorn Helgaas
0 siblings, 1 reply; 2+ messages in thread
From: Chris J Arges @ 2014-12-05 23:02 UTC (permalink / raw)
To: linux-pci; +Cc: Chris J Arges, Bjorn Helgaas, Stephen Hemminger, linux-kernel
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] PCI/ASPM: use standard parsing functions for sysfs setters
2014-12-05 23:02 [PATCH] PCI/ASPM: use standard parsing functions for sysfs setters Chris J Arges
@ 2015-01-09 18:23 ` Bjorn Helgaas
0 siblings, 0 replies; 2+ messages in thread
From: Bjorn Helgaas @ 2015-01-09 18:23 UTC (permalink / raw)
To: Chris J Arges; +Cc: linux-pci, Stephen Hemminger, linux-kernel
On Fri, Dec 05, 2014 at 05:02:42PM -0600, Chris J Arges wrote:
> 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>
Applied to pci/misc for v3.20, thanks.
> ---
> 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
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-01-09 18:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-05 23:02 [PATCH] PCI/ASPM: use standard parsing functions for sysfs setters Chris J Arges
2015-01-09 18:23 ` Bjorn Helgaas
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).