aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorViresh Kumar <viresh.kumar@linaro.org>2014-03-28 09:41:46 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-04-07 08:43:49 -0400
commit71508a1f4f2286eea728a5994f1fb14b77340b47 (patch)
tree7cac28dfabc7182c562f185919fe66c2e4f363ce /drivers
parentae87f10f35f75deb8f74dbd92d062200932c2f26 (diff)
cpufreq: use kzalloc() to allocate memory for cpufreq_frequency_table
Few drivers are using kmalloc() to allocate memory for frequency tables and since we will have an additional field '.flags' in 'struct cpufreq_frequency_table', these might become unstable. Better get these fixed by replacing kmalloc() by kzalloc() instead. Along with that we also remove use of .driver_data from SPEAr driver as it doesn't use it at all. Also, writing zero to .driver_data is not required for powernow-k8 as it is already zero. Reported-and-reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/cpufreq/acpi-cpufreq.c2
-rw-r--r--drivers/cpufreq/ia64-acpi-cpufreq.c2
-rw-r--r--drivers/cpufreq/longhaul.c2
-rw-r--r--drivers/cpufreq/powernow-k8.c5
-rw-r--r--drivers/cpufreq/s3c24xx-cpufreq.c4
-rw-r--r--drivers/cpufreq/spear-cpufreq.c7
6 files changed, 9 insertions, 13 deletions
diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
index 822ca03a87f7..c91ef5785dfa 100644
--- a/drivers/cpufreq/acpi-cpufreq.c
+++ b/drivers/cpufreq/acpi-cpufreq.c
@@ -754,7 +754,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
754 goto err_unreg; 754 goto err_unreg;
755 } 755 }
756 756
757 data->freq_table = kmalloc(sizeof(*data->freq_table) * 757 data->freq_table = kzalloc(sizeof(*data->freq_table) *
758 (perf->state_count+1), GFP_KERNEL); 758 (perf->state_count+1), GFP_KERNEL);
759 if (!data->freq_table) { 759 if (!data->freq_table) {
760 result = -ENOMEM; 760 result = -ENOMEM;
diff --git a/drivers/cpufreq/ia64-acpi-cpufreq.c b/drivers/cpufreq/ia64-acpi-cpufreq.c
index beb191b589d4..c30aaa6a54e8 100644
--- a/drivers/cpufreq/ia64-acpi-cpufreq.c
+++ b/drivers/cpufreq/ia64-acpi-cpufreq.c
@@ -254,7 +254,7 @@ acpi_cpufreq_cpu_init (
254 } 254 }
255 255
256 /* alloc freq_table */ 256 /* alloc freq_table */
257 data->freq_table = kmalloc(sizeof(*data->freq_table) * 257 data->freq_table = kzalloc(sizeof(*data->freq_table) *
258 (data->acpi_data.state_count + 1), 258 (data->acpi_data.state_count + 1),
259 GFP_KERNEL); 259 GFP_KERNEL);
260 if (!data->freq_table) { 260 if (!data->freq_table) {
diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c
index 5c440f87ba8a..d00e5d1abd25 100644
--- a/drivers/cpufreq/longhaul.c
+++ b/drivers/cpufreq/longhaul.c
@@ -475,7 +475,7 @@ static int longhaul_get_ranges(void)
475 return -EINVAL; 475 return -EINVAL;
476 } 476 }
477 477
478 longhaul_table = kmalloc((numscales + 1) * sizeof(*longhaul_table), 478 longhaul_table = kzalloc((numscales + 1) * sizeof(*longhaul_table),
479 GFP_KERNEL); 479 GFP_KERNEL);
480 if (!longhaul_table) 480 if (!longhaul_table)
481 return -ENOMEM; 481 return -ENOMEM;
diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
index 770a9e1b3468..1b6ae6b57c11 100644
--- a/drivers/cpufreq/powernow-k8.c
+++ b/drivers/cpufreq/powernow-k8.c
@@ -623,7 +623,7 @@ static int fill_powernow_table(struct powernow_k8_data *data,
623 if (check_pst_table(data, pst, maxvid)) 623 if (check_pst_table(data, pst, maxvid))
624 return -EINVAL; 624 return -EINVAL;
625 625
626 powernow_table = kmalloc((sizeof(*powernow_table) 626 powernow_table = kzalloc((sizeof(*powernow_table)
627 * (data->numps + 1)), GFP_KERNEL); 627 * (data->numps + 1)), GFP_KERNEL);
628 if (!powernow_table) { 628 if (!powernow_table) {
629 printk(KERN_ERR PFX "powernow_table memory alloc failure\n"); 629 printk(KERN_ERR PFX "powernow_table memory alloc failure\n");
@@ -793,7 +793,7 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data)
793 } 793 }
794 794
795 /* fill in data->powernow_table */ 795 /* fill in data->powernow_table */
796 powernow_table = kmalloc((sizeof(*powernow_table) 796 powernow_table = kzalloc((sizeof(*powernow_table)
797 * (data->acpi_data.state_count + 1)), GFP_KERNEL); 797 * (data->acpi_data.state_count + 1)), GFP_KERNEL);
798 if (!powernow_table) { 798 if (!powernow_table) {
799 pr_debug("powernow_table memory alloc failure\n"); 799 pr_debug("powernow_table memory alloc failure\n");
@@ -810,7 +810,6 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data)
810 810
811 powernow_table[data->acpi_data.state_count].frequency = 811 powernow_table[data->acpi_data.state_count].frequency =
812 CPUFREQ_TABLE_END; 812 CPUFREQ_TABLE_END;
813 powernow_table[data->acpi_data.state_count].driver_data = 0;
814 data->powernow_table = powernow_table; 813 data->powernow_table = powernow_table;
815 814
816 if (cpumask_first(cpu_core_mask(data->cpu)) == data->cpu) 815 if (cpumask_first(cpu_core_mask(data->cpu)) == data->cpu)
diff --git a/drivers/cpufreq/s3c24xx-cpufreq.c b/drivers/cpufreq/s3c24xx-cpufreq.c
index a3dc192d21f9..be1b2b5c9753 100644
--- a/drivers/cpufreq/s3c24xx-cpufreq.c
+++ b/drivers/cpufreq/s3c24xx-cpufreq.c
@@ -586,7 +586,7 @@ static int s3c_cpufreq_build_freq(void)
586 size = cpu_cur.info->calc_freqtable(&cpu_cur, NULL, 0); 586 size = cpu_cur.info->calc_freqtable(&cpu_cur, NULL, 0);
587 size++; 587 size++;
588 588
589 ftab = kmalloc(sizeof(*ftab) * size, GFP_KERNEL); 589 ftab = kzalloc(sizeof(*ftab) * size, GFP_KERNEL);
590 if (!ftab) { 590 if (!ftab) {
591 printk(KERN_ERR "%s: no memory for tables\n", __func__); 591 printk(KERN_ERR "%s: no memory for tables\n", __func__);
592 return -ENOMEM; 592 return -ENOMEM;
@@ -664,7 +664,7 @@ int __init s3c_plltab_register(struct cpufreq_frequency_table *plls,
664 664
665 size = sizeof(*vals) * (plls_no + 1); 665 size = sizeof(*vals) * (plls_no + 1);
666 666
667 vals = kmalloc(size, GFP_KERNEL); 667 vals = kzalloc(size, GFP_KERNEL);
668 if (vals) { 668 if (vals) {
669 memcpy(vals, plls, size); 669 memcpy(vals, plls, size);
670 pll_reg = vals; 670 pll_reg = vals;
diff --git a/drivers/cpufreq/spear-cpufreq.c b/drivers/cpufreq/spear-cpufreq.c
index 4cfdcff8a310..38678396636d 100644
--- a/drivers/cpufreq/spear-cpufreq.c
+++ b/drivers/cpufreq/spear-cpufreq.c
@@ -195,18 +195,15 @@ static int spear_cpufreq_probe(struct platform_device *pdev)
195 cnt = prop->length / sizeof(u32); 195 cnt = prop->length / sizeof(u32);
196 val = prop->value; 196 val = prop->value;
197 197
198 freq_tbl = kmalloc(sizeof(*freq_tbl) * (cnt + 1), GFP_KERNEL); 198 freq_tbl = kzalloc(sizeof(*freq_tbl) * (cnt + 1), GFP_KERNEL);
199 if (!freq_tbl) { 199 if (!freq_tbl) {
200 ret = -ENOMEM; 200 ret = -ENOMEM;
201 goto out_put_node; 201 goto out_put_node;
202 } 202 }
203 203
204 for (i = 0; i < cnt; i++) { 204 for (i = 0; i < cnt; i++)
205 freq_tbl[i].driver_data = i;
206 freq_tbl[i].frequency = be32_to_cpup(val++); 205 freq_tbl[i].frequency = be32_to_cpup(val++);
207 }
208 206
209 freq_tbl[i].driver_data = i;
210 freq_tbl[i].frequency = CPUFREQ_TABLE_END; 207 freq_tbl[i].frequency = CPUFREQ_TABLE_END;
211 208
212 spear_cpufreq.freq_tbl = freq_tbl; 209 spear_cpufreq.freq_tbl = freq_tbl;