summaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorVictor(Weiguo) Pan <wpan@nvidia.com>2011-08-23 14:48:30 -0700
committerVarun Colbert <vcolbert@nvidia.com>2011-08-24 17:35:29 -0700
commitb9700e2fb18b8ba8f2b8df3e4c5ea64b1fe90753 (patch)
tree01c6d1e48a16c3c19da35bcd1bb1a273e853d446 /arch
parent56d91aea21041b154160b3bd79f33b6156f2ffbe (diff)
ARM: tegra: correctly access file in kernel
1. Tell the kernel the pointers from within the kernel address space are safe before accessing the file. Save/restore current process address before/after the file accessing. 2. Use macro IS_ERR to check file opening is successful or not because filp_open() returns negtive value once error happens. bug 865113 Change-Id: Ic8d779352d3daeaf3d3ef92e7c5feb82e55b47cd Reviewed-on: http://git-master/r/48775 Reviewed-by: Varun Colbert <vcolbert@nvidia.com> Tested-by: Varun Colbert <vcolbert@nvidia.com>
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/mach-tegra/common.c42
1 files changed, 30 insertions, 12 deletions
diff --git a/arch/arm/mach-tegra/common.c b/arch/arm/mach-tegra/common.c
index 5d280c6ffd91..679e12b97d9e 100644
--- a/arch/arm/mach-tegra/common.c
+++ b/arch/arm/mach-tegra/common.c
@@ -792,6 +792,7 @@ static char *cpufreq_gov_conservative_param="/sys/devices/system/cpu/cpufreq/con
static void cpufreq_set_governor(char *governor)
{
struct file *scaling_gov = NULL;
+ mm_segment_t old_fs;
char buf[128];
int i;
loff_t offset = 0;
@@ -799,10 +800,16 @@ static void cpufreq_set_governor(char *governor)
if (governor == NULL)
return;
+ /* change to KERNEL_DS address limit */
+ old_fs = get_fs();
+ set_fs(KERNEL_DS);
+
for_each_online_cpu(i) {
sprintf(buf, cpufreq_sysfs_place_holder, i);
scaling_gov = filp_open(buf, O_RDWR, 0);
- if (scaling_gov != NULL) {
+ if (IS_ERR_OR_NULL(scaling_gov)) {
+ pr_err("%s. Can't open %s\n", __func__, buf);
+ } else {
if (scaling_gov->f_op != NULL &&
scaling_gov->f_op->write != NULL)
scaling_gov->f_op->write(scaling_gov,
@@ -813,22 +820,28 @@ static void cpufreq_set_governor(char *governor)
pr_err("f_op might be null\n");
filp_close(scaling_gov, NULL);
- } else {
- pr_err("%s. Can't open %s\n", __func__, buf);
}
}
+ set_fs(old_fs);
}
void cpufreq_save_default_governor(void)
{
struct file *scaling_gov = NULL;
+ mm_segment_t old_fs;
char buf[128];
loff_t offset = 0;
+ /* change to KERNEL_DS address limit */
+ old_fs = get_fs();
+ set_fs(KERNEL_DS);
+
buf[127] = 0;
sprintf(buf, cpufreq_sysfs_place_holder,0);
scaling_gov = filp_open(buf, O_RDONLY, 0);
- if (scaling_gov != NULL) {
+ if (IS_ERR_OR_NULL(scaling_gov)) {
+ pr_err("%s. Can't open %s\n", __func__, buf);
+ } else {
if (scaling_gov->f_op != NULL &&
scaling_gov->f_op->read != NULL)
scaling_gov->f_op->read(scaling_gov,
@@ -839,9 +852,8 @@ void cpufreq_save_default_governor(void)
pr_err("f_op might be null\n");
filp_close(scaling_gov, NULL);
- } else {
- pr_err("%s. Can't open %s\n", __func__, buf);
}
+ set_fs(old_fs);
}
void cpufreq_restore_default_governor(void)
@@ -854,6 +866,7 @@ void cpufreq_set_conservative_governor_param(int up_th, int down_th)
struct file *gov_param = NULL;
static char buf[128],parm[8];
loff_t offset = 0;
+ mm_segment_t old_fs;
if (up_th <= down_th) {
printk(KERN_ERR "%s: up_th(%d) is lesser than down_th(%d)\n",
@@ -861,10 +874,16 @@ void cpufreq_set_conservative_governor_param(int up_th, int down_th)
return;
}
+ /* change to KERNEL_DS address limit */
+ old_fs = get_fs();
+ set_fs(KERNEL_DS);
+
sprintf(parm, "%d", up_th);
sprintf(buf, cpufreq_gov_conservative_param ,"up_threshold");
gov_param = filp_open(buf, O_RDONLY, 0);
- if (gov_param != NULL) {
+ if (IS_ERR_OR_NULL(gov_param)) {
+ pr_err("%s. Can't open %s\n", __func__, buf);
+ } else {
if (gov_param->f_op != NULL &&
gov_param->f_op->write != NULL)
gov_param->f_op->write(gov_param,
@@ -875,14 +894,14 @@ void cpufreq_set_conservative_governor_param(int up_th, int down_th)
pr_err("f_op might be null\n");
filp_close(gov_param, NULL);
- } else {
- pr_err("%s. Can't open %s\n", __func__, buf);
}
sprintf(parm, "%d", down_th);
sprintf(buf, cpufreq_gov_conservative_param ,"down_threshold");
gov_param = filp_open(buf, O_RDONLY, 0);
- if (gov_param != NULL) {
+ if (IS_ERR_OR_NULL(gov_param)) {
+ pr_err("%s. Can't open %s\n", __func__, buf);
+ } else {
if (gov_param->f_op != NULL &&
gov_param->f_op->write != NULL)
gov_param->f_op->write(gov_param,
@@ -893,9 +912,8 @@ void cpufreq_set_conservative_governor_param(int up_th, int down_th)
pr_err("f_op might be null\n");
filp_close(gov_param, NULL);
- } else {
- pr_err("%s. Can't open %s\n", __func__, buf);
}
+ set_fs(old_fs);
}
void cpufreq_set_conservative_governor(void)