diff options
author | Victor(Weiguo) Pan <wpan@nvidia.com> | 2011-08-23 14:48:30 -0700 |
---|---|---|
committer | Ryan Wong <ryanw@nvidia.com> | 2011-08-24 17:14:38 -0700 |
commit | 76d0a832b0fb8c5c6446f9c86ccc743701ff704e (patch) | |
tree | 83a4453f742ef9beace749f84961532a93009347 | |
parent | e7e8f99ba91b49d67884ee912748ce8200c22784 (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: Idbcd400a7c93576930651a0cf95e6928e1f8db3a
Reviewed-on: http://git-master/r/48788
Reviewed-by: Bhushan Rayrikar <brayrikar@nvidia.com>
Tested-by: Bhushan Rayrikar <brayrikar@nvidia.com>
Reviewed-by: Ryan Wong <ryanw@nvidia.com>
Tested-by: Ryan Wong <ryanw@nvidia.com>
-rw-r--r-- | arch/arm/mach-tegra/common.c | 42 |
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) |