aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/sysfs.c
diff options
context:
space:
mode:
authorLan Tianyu <tianyu.lan@intel.com>2013-09-12 03:32:05 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-09-25 11:21:34 -0400
commitc48b156517348a0130e9e6edbeba95f9b4e50d65 (patch)
tree95c98e48b360593276d7133d4733b84e0cda381b /drivers/acpi/sysfs.c
parent16a26e85279fd672050ffc3637038366629e8653 (diff)
ACPI / sysfs: make GPE sysfs attributes only accept correct values
According to the design, GPE sysfs attributes should accept "disable", "enable", "clear" and integer numbers as params. Current code checks "disable", "enable" and "clear" first. If the param doesn't match, pass it to strtoul() as a string representing an integer number and assign the return value to the given GPE count. It is missing the check of whether or not the param really represents an integer number and strtoul() will return 0 if the string is not a number. This causes any params except for "enable", "disable", "clear" and a number to make the GPE count become 0. This patch is to use kstrtoul() to replace strtoul() and check the return value. If the convertion is successful, use as the new GPE count. If not, return an error. Signed-off-by: Lan Tianyu <tianyu.lan@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/acpi/sysfs.c')
-rw-r--r--drivers/acpi/sysfs.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
index 05306a59aedc..b55778704444 100644
--- a/drivers/acpi/sysfs.c
+++ b/drivers/acpi/sysfs.c
@@ -564,6 +564,7 @@ static ssize_t counter_set(struct kobject *kobj,
564 acpi_event_status status; 564 acpi_event_status status;
565 acpi_handle handle; 565 acpi_handle handle;
566 int result = 0; 566 int result = 0;
567 unsigned long tmp;
567 568
568 if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) { 569 if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) {
569 int i; 570 int i;
@@ -596,8 +597,10 @@ static ssize_t counter_set(struct kobject *kobj,
596 else if (!strcmp(buf, "clear\n") && 597 else if (!strcmp(buf, "clear\n") &&
597 (status & ACPI_EVENT_FLAG_SET)) 598 (status & ACPI_EVENT_FLAG_SET))
598 result = acpi_clear_gpe(handle, index); 599 result = acpi_clear_gpe(handle, index);
600 else if (!kstrtoul(buf, 0, &tmp))
601 all_counters[index].count = tmp;
599 else 602 else
600 all_counters[index].count = strtoul(buf, NULL, 0); 603 result = -EINVAL;
601 } else if (index < num_gpes + ACPI_NUM_FIXED_EVENTS) { 604 } else if (index < num_gpes + ACPI_NUM_FIXED_EVENTS) {
602 int event = index - num_gpes; 605 int event = index - num_gpes;
603 if (!strcmp(buf, "disable\n") && 606 if (!strcmp(buf, "disable\n") &&
@@ -609,8 +612,10 @@ static ssize_t counter_set(struct kobject *kobj,
609 else if (!strcmp(buf, "clear\n") && 612 else if (!strcmp(buf, "clear\n") &&
610 (status & ACPI_EVENT_FLAG_SET)) 613 (status & ACPI_EVENT_FLAG_SET))
611 result = acpi_clear_event(event); 614 result = acpi_clear_event(event);
615 else if (!kstrtoul(buf, 0, &tmp))
616 all_counters[index].count = tmp;
612 else 617 else
613 all_counters[index].count = strtoul(buf, NULL, 0); 618 result = -EINVAL;
614 } else 619 } else
615 all_counters[index].count = strtoul(buf, NULL, 0); 620 all_counters[index].count = strtoul(buf, NULL, 0);
616 621