LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Yi Yang <yi.y.yang@intel.com>
To: linux-acpi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, lenb@kernel.org,
acpi-bugzilla@lists.sourceforge.net
Subject: [PATCH] ACPI: fix processor limit set error
Date: Tue, 08 Jan 2008 11:21:26 +0800 [thread overview]
Message-ID: <1199762486.3551.22.camel@yangyi-dev.bj.intel.com> (raw)
In-Reply-To: <1199688961.3551.19.camel@yangyi-dev.bj.intel.com>
Subject: ACPI: fix processor limit set error
From: Yi Yang <yi.y.yang@intel.com>
when echo some invalid values to /proc/acpi/processor/CPU*/limit,
it doesn't return any error info, on the contrary, it successes
and sets some other values, for example:
[root@localhost /]# echo "0:0A" >/proc/acpi/processor/CPU0/limit
[root@localhost /]# cat /proc/acpi/processor/CPU0/limit
active limit: P0:T0
user limit: P0:T0
thermal limit: P0:T0
[root@localhost /]# echo "0:0F" >/proc/acpi/processor/CPU0/limit
[root@localhost /]# cat /proc/acpi/processor/CPU0/limit
active limit: P0:T0
user limit: P0:T0
thermal limit: P0:T0
[root@localhost /]# echo "0:0 0:1 0:2" >/proc/acpi/processor/CPU0/limit
[root@localhost /]# cat /proc/acpi/processor/CPU0/limit
active limit: P0:T0
user limit: P0:T0
thermal limit: P0:T0
[root@localhost /]#
A correct way is that it should fail and return error info.
This patch fixed this issue, it accepts not only such inputs as "*:*",
but also accepts such inputs as "p*:t*" or "P*:T*" or "p*:*" or "*:t*",
the former "*" in inputs means the allowed processor performance state,
currently it is only a stub and not set to the processor limit data
structure, the latter "*" means the allowed processor throttling state
which rages from 0 to 7 generally. This patch strictly limits inputs to
meet the above conditions, any input which can't meet the above conditions
is considered as invalid input.
Before applying this patch, the test result is below:
[root@localhost /]# echo "0:0A" >/proc/acpi/processor/CPU0/limit
[root@localhost /]# cat /proc/acpi/processor/CPU0/limit
active limit: P0:T0
user limit: P0:T0
thermal limit: P0:T0
[root@localhost /]# echo "0:0F" >/proc/acpi/processor/CPU0/limit
[root@localhost /]# cat /proc/acpi/processor/CPU0/limit
active limit: P0:T0
user limit: P0:T0
thermal limit: P0:T0
[root@localhost /]# echo "10:2F" >/proc/acpi/processor/CPU0/limit
[root@localhost /]# cat /proc/acpi/processor/CPU0/limit
active limit: P0:T2
user limit: P0:T2
thermal limit: P0:T0
[root@localhost /]# echo "0:0 0:1 0:2" >/proc/acpi/processor/CPU0/limit
[root@localhost /]# cat /proc/acpi/processor/CPU0/limit
active limit: P0:T0
user limit: P0:T0
thermal limit: P0:T0
[root@localhost /]#
After applying this patch, the test result is below:
[root@localhost ~]# cat /proc/acpi/processor/CPU0/limit
active limit: P0:T0
user limit: P0:T0
thermal limit: P0:T0
[root@localhost ~]# echo "0:0A" > /proc/acpi/processor/CPU0/limit
-bash: echo: write error: Invalid argument
[root@localhost ~]# echo "0:0F" > /proc/acpi/processor/CPU0/limit
-bash: echo: write error: Invalid argument
[root@localhost ~]# echo "P0:T1" > /proc/acpi/processor/CPU0/limit
[root@localhost ~]# cat /proc/acpi/processor/CPU0/limit
active limit: P0:T1
user limit: P0:T1
thermal limit: P0:T0
[root@localhost ~]# echo "p0:t1" > /proc/acpi/processor/CPU0/limit
[root@localhost ~]# cat /proc/acpi/processor/CPU0/limit
active limit: P0:T1
user limit: P0:T1
thermal limit: P0:T0
[root@localhost ~]# echo "p0:x1" > /proc/acpi/processor/CPU0/limit
-bash: echo: write error: Invalid argument
[root@localhost ~]# echo "q0:x1" > /proc/acpi/processor/CPU0/limit
-bash: echo: write error: Invalid argument
[root@localhost ~]# echo "p0:1" > /proc/acpi/processor/CPU0/limit
[root@localhost ~]# echo "q0:x1" > /proc/acpi/processor/CPU0/limit
-bash: echo: write error: Invalid argument
[root@localhost ~]# cat /proc/acpi/processor/CPU0/limit
active limit: P0:T1
user limit: P0:T1
thermal limit: P0:T0
[root@localhost ~]# echo "0:t1" > /proc/acpi/processor/CPU0/limit
[root@localhost ~]# cat /proc/acpi/processor/CPU0/limit
active limit: P0:T1
user limit: P0:T1
thermal limit: P0:T0
[root@localhost ~]# echo "0:t1F" > /proc/acpi/processor/CPU0/limit
-bash: echo: write error: Invalid argument
[root@localhost ~]# echo "" > /proc/acpi/processor/CPU0/limit
-bash: echo: write error: Invalid argument
[root@localhost ~]# echo "0:0 0:0 0:2 " > /proc/acpi/processor/CPU0/limit
-bash: echo: write error: Invalid argument
[root@localhost ~]# echo "P0:T1" > /proc/acpi/processor/CPU0/limit
[root@localhost ~]# cat /proc/acpi/processor/CPU0/limit
active limit: P0:T1
user limit: P0:T1
thermal limit: P0:T0
[root@localhost ~]#
Signed-off-by: Yi Yang <yi.y.yang@intel.com>
---
processor_thermal.c | 42 +++++++++++++++++++++++++++++++-----------
1 file changed, 31 insertions(+), 11 deletions(-)
diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c
index 06e6f3f..262d56e 100644
--- a/drivers/acpi/processor_thermal.c
+++ b/drivers/acpi/processor_thermal.c
@@ -349,9 +349,11 @@ static ssize_t acpi_processor_write_limit(struct file * file,
int result = 0;
struct seq_file *m = file->private_data;
struct acpi_processor *pr = m->private;
- char limit_string[25] = { '\0' };
+ char limit_string[10] = "";
int px = 0;
int tx = 0;
+ char *tmpp = NULL;
+ char tmpstring[10] = "";
if (!pr || (count > sizeof(limit_string) - 1)) {
@@ -363,21 +365,39 @@ static ssize_t acpi_processor_write_limit(struct file * file,
}
limit_string[count] = '\0';
+ if ((count > 0) && (limit_string[count-1] == '\n'))
+ limit_string[count-1] = '\0';
- if (sscanf(limit_string, "%d:%d", &px, &tx) != 2) {
- printk(KERN_ERR PREFIX "Invalid data format\n");
+ tmpp = memchr(limit_string, ':', count);
+ if (tmpp == NULL)
+ return -EINVAL;
+
+ *tmpp = '\0';
+ tmpp = limit_string;
+ if ((limit_string[0] == 'p') || (limit_string[0] == 'P'))
+ tmpp++;
+ px = simple_strtoul(tmpp, NULL, 0);
+ snprintf(tmpstring, 10, "%d", px);
+ if (strcmp(tmpp, tmpstring) != 0)
+ return -EINVAL;
+
+ tmpp += strlen(tmpp) + 1;
+ if ((tmpp[0] == 't') || (tmpp[0] == 'T'))
+ tmpp++;
+ tx = simple_strtoul(tmpp, NULL, 0);
+ if (tx > (pr->throttling.state_count - 1))
+ return -EINVAL;
+ snprintf(tmpstring, 10, "%d", tx);
+ if (strcmp(tmpp, tmpstring) != 0)
return -EINVAL;
- }
if (pr->flags.throttling) {
- if ((tx < 0) || (tx > (pr->throttling.state_count - 1))) {
- printk(KERN_ERR PREFIX "Invalid tx\n");
- return -EINVAL;
- }
pr->limit.user.tx = tx;
- }
-
- result = acpi_processor_apply_limit(pr);
+ result = acpi_processor_apply_limit(pr);
+ if (result != 0)
+ return result;
+ } else
+ return -ENODEV;
return count;
}
next prev parent reply other threads:[~2008-01-08 6:57 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-27 6:47 [PATCH linux-acpi] Fix /proc/acpi/alarm " Yi Yang
2007-12-27 8:41 ` [PATCH linux-acpi] Remove superfluous code and correct counting error in function acpi_system_write_alarm Yi Yang
2007-12-29 8:22 ` [PATCH linux-acpi] Correct wakeup set error and append a new column PCI ID Yi Yang
2008-01-01 23:20 ` Pavel Machek
2008-01-02 2:03 ` Yi Yang
2008-01-02 16:09 ` Pavel Machek
2008-01-03 2:02 ` Yi Yang
2008-01-03 2:11 ` Yi Yang
2008-01-04 8:16 ` [PATCH linux-acpi] fix acpi fan state set error Yi Yang
2008-01-07 6:56 ` [PATCH] ACPI: fix processor throttling " Yi Yang
2008-01-08 3:21 ` Yi Yang [this message]
2008-01-24 0:45 ` [PATCH] ACPI: create proc entry 'power' only if C2 or C3 is supported Yi Yang
2008-01-24 14:43 ` Mark Lord
2008-01-09 22:21 ` [PATCH] ACPI: Add sysfs interface for acpi device wakeup Yi Yang
2008-01-10 7:43 ` Maxim Levitsky
2008-01-09 23:59 ` Yi Yang
2008-01-10 10:30 ` Matthew Garrett
2008-01-13 18:16 ` Pavel Machek
2008-01-11 8:16 ` Zhang Rui
2008-01-10 23:55 ` Yi Yang
2008-03-19 13:06 ` Thomas Renninger
2008-03-19 14:37 ` Yi Yang
2008-03-20 4:32 ` Zhao Yakui
2008-03-19 18:52 ` David Brownell
2008-03-20 5:12 ` Zhao Yakui
2008-03-20 6:12 ` David Brownell
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=1199762486.3551.22.camel@yangyi-dev.bj.intel.com \
--to=yi.y.yang@intel.com \
--cc=acpi-bugzilla@lists.sourceforge.net \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--subject='Re: [PATCH] ACPI: fix processor limit set error' \
/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
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).