mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: tianyu.lan@intel.com
To: tianyu.lan@intel.com, lenb@kernel.org, rjw@sisk.pl,
	linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] ACPI/Sys: make gpe's sysfs attribute only accept correct value
Date: Thu, 12 Sep 2013 03:32:05 -0400	[thread overview]
Message-ID: <1378971125-8896-4-git-send-email-tianyu.lan@intel.com> (raw)
In-Reply-To: <1378971125-8896-1-git-send-email-tianyu.lan@intel.com>

From: Lan Tianyu <tianyu.lan@intel.com>

According to design, gpe's sysfs attribute should accept "disable", "enable",
"clear" and integer number as params. Current code checks "disable",
"enable" and "clear" first. If the param didn't belong to previous kinds,
pass the param to strtoul as a string of integer number and assign the
return value to gpe number. It losses the check of whether the param
is a string of integer number and strtoul will return 0 if the string
is not a number.  This causes any params except for "enable"
, "disable", "clear" and number to make the gpe number to become 0. This
patch is to use kstrtoul() to replace strtoul() and check the return
value. If convertion is successful, assign to gpe number. If not, return
err.

Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
---
 drivers/acpi/sysfs.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
index 05306a5..b557787 100644
--- a/drivers/acpi/sysfs.c
+++ b/drivers/acpi/sysfs.c
@@ -564,6 +564,7 @@ static ssize_t counter_set(struct kobject *kobj,
 	acpi_event_status status;
 	acpi_handle handle;
 	int result = 0;
+	unsigned long tmp;
 
 	if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) {
 		int i;
@@ -596,8 +597,10 @@ static ssize_t counter_set(struct kobject *kobj,
 		else if (!strcmp(buf, "clear\n") &&
 			 (status & ACPI_EVENT_FLAG_SET))
 			result = acpi_clear_gpe(handle, index);
+		else if (!kstrtoul(buf, 0, &tmp))
+			all_counters[index].count = tmp;
 		else
-			all_counters[index].count = strtoul(buf, NULL, 0);
+			result = -EINVAL;
 	} else if (index < num_gpes + ACPI_NUM_FIXED_EVENTS) {
 		int event = index - num_gpes;
 		if (!strcmp(buf, "disable\n") &&
@@ -609,8 +612,10 @@ static ssize_t counter_set(struct kobject *kobj,
 		else if (!strcmp(buf, "clear\n") &&
 			 (status & ACPI_EVENT_FLAG_SET))
 			result = acpi_clear_event(event);
+		else if (!kstrtoul(buf, 0, &tmp))
+			all_counters[index].count = tmp;
 		else
-			all_counters[index].count = strtoul(buf, NULL, 0);
+			result = -EINVAL;
 	} else
 		all_counters[index].count = strtoul(buf, NULL, 0);
 
-- 
1.8.2.1


      parent reply	other threads:[~2013-09-12  7:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-12  7:32 [PATCH 0/3] ACPI: EC/Button drivers clean up and correct gpe's sysfs attribute tianyu.lan
2013-09-12  7:32 ` [PATCH 1/3] ACPI/Button: Using input_set_capability() to mark device's event capability tianyu.lan
2013-09-12  7:32 ` [PATCH 2/3] ACPI/EC: Convert all printk to dynamic debug function tianyu.lan
2013-09-12  7:32 ` tianyu.lan [this message]

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=1378971125-8896-4-git-send-email-tianyu.lan@intel.com \
    --to=tianyu.lan@intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rjw@sisk.pl \
    /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

all inboxes | Powered by JetHome®