Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c48b1565 authored by Lan Tianyu's avatar Lan Tianyu Committed by Rafael J. Wysocki
Browse files

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: default avatarLan Tianyu <tianyu.lan@intel.com>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 16a26e85
Loading
Loading
Loading
Loading
+7 −2
Original line number Original line Diff line number Diff line
@@ -564,6 +564,7 @@ static ssize_t counter_set(struct kobject *kobj,
	acpi_event_status status;
	acpi_event_status status;
	acpi_handle handle;
	acpi_handle handle;
	int result = 0;
	int result = 0;
	unsigned long tmp;


	if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) {
	if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) {
		int i;
		int i;
@@ -596,8 +597,10 @@ static ssize_t counter_set(struct kobject *kobj,
		else if (!strcmp(buf, "clear\n") &&
		else if (!strcmp(buf, "clear\n") &&
			 (status & ACPI_EVENT_FLAG_SET))
			 (status & ACPI_EVENT_FLAG_SET))
			result = acpi_clear_gpe(handle, index);
			result = acpi_clear_gpe(handle, index);
		else if (!kstrtoul(buf, 0, &tmp))
			all_counters[index].count = tmp;
		else
		else
			all_counters[index].count = strtoul(buf, NULL, 0);
			result = -EINVAL;
	} else if (index < num_gpes + ACPI_NUM_FIXED_EVENTS) {
	} else if (index < num_gpes + ACPI_NUM_FIXED_EVENTS) {
		int event = index - num_gpes;
		int event = index - num_gpes;
		if (!strcmp(buf, "disable\n") &&
		if (!strcmp(buf, "disable\n") &&
@@ -609,8 +612,10 @@ static ssize_t counter_set(struct kobject *kobj,
		else if (!strcmp(buf, "clear\n") &&
		else if (!strcmp(buf, "clear\n") &&
			 (status & ACPI_EVENT_FLAG_SET))
			 (status & ACPI_EVENT_FLAG_SET))
			result = acpi_clear_event(event);
			result = acpi_clear_event(event);
		else if (!kstrtoul(buf, 0, &tmp))
			all_counters[index].count = tmp;
		else
		else
			all_counters[index].count = strtoul(buf, NULL, 0);
			result = -EINVAL;
	} else
	} else
		all_counters[index].count = strtoul(buf, NULL, 0);
		all_counters[index].count = strtoul(buf, NULL, 0);