提交 71508a1f 编写于 作者: V Viresh Kumar 提交者: Rafael J. Wysocki

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: NGautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: NViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
上级 ae87f10f
...@@ -754,7 +754,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy) ...@@ -754,7 +754,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
goto err_unreg; goto err_unreg;
} }
data->freq_table = kmalloc(sizeof(*data->freq_table) * data->freq_table = kzalloc(sizeof(*data->freq_table) *
(perf->state_count+1), GFP_KERNEL); (perf->state_count+1), GFP_KERNEL);
if (!data->freq_table) { if (!data->freq_table) {
result = -ENOMEM; result = -ENOMEM;
......
...@@ -254,7 +254,7 @@ acpi_cpufreq_cpu_init ( ...@@ -254,7 +254,7 @@ acpi_cpufreq_cpu_init (
} }
/* alloc freq_table */ /* alloc freq_table */
data->freq_table = kmalloc(sizeof(*data->freq_table) * data->freq_table = kzalloc(sizeof(*data->freq_table) *
(data->acpi_data.state_count + 1), (data->acpi_data.state_count + 1),
GFP_KERNEL); GFP_KERNEL);
if (!data->freq_table) { if (!data->freq_table) {
......
...@@ -475,7 +475,7 @@ static int longhaul_get_ranges(void) ...@@ -475,7 +475,7 @@ static int longhaul_get_ranges(void)
return -EINVAL; return -EINVAL;
} }
longhaul_table = kmalloc((numscales + 1) * sizeof(*longhaul_table), longhaul_table = kzalloc((numscales + 1) * sizeof(*longhaul_table),
GFP_KERNEL); GFP_KERNEL);
if (!longhaul_table) if (!longhaul_table)
return -ENOMEM; return -ENOMEM;
......
...@@ -623,7 +623,7 @@ static int fill_powernow_table(struct powernow_k8_data *data, ...@@ -623,7 +623,7 @@ static int fill_powernow_table(struct powernow_k8_data *data,
if (check_pst_table(data, pst, maxvid)) if (check_pst_table(data, pst, maxvid))
return -EINVAL; return -EINVAL;
powernow_table = kmalloc((sizeof(*powernow_table) powernow_table = kzalloc((sizeof(*powernow_table)
* (data->numps + 1)), GFP_KERNEL); * (data->numps + 1)), GFP_KERNEL);
if (!powernow_table) { if (!powernow_table) {
printk(KERN_ERR PFX "powernow_table memory alloc failure\n"); 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,7 +793,7 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data)
} }
/* fill in data->powernow_table */ /* fill in data->powernow_table */
powernow_table = kmalloc((sizeof(*powernow_table) powernow_table = kzalloc((sizeof(*powernow_table)
* (data->acpi_data.state_count + 1)), GFP_KERNEL); * (data->acpi_data.state_count + 1)), GFP_KERNEL);
if (!powernow_table) { if (!powernow_table) {
pr_debug("powernow_table memory alloc failure\n"); 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,7 +810,6 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data)
powernow_table[data->acpi_data.state_count].frequency = powernow_table[data->acpi_data.state_count].frequency =
CPUFREQ_TABLE_END; CPUFREQ_TABLE_END;
powernow_table[data->acpi_data.state_count].driver_data = 0;
data->powernow_table = powernow_table; data->powernow_table = powernow_table;
if (cpumask_first(cpu_core_mask(data->cpu)) == data->cpu) if (cpumask_first(cpu_core_mask(data->cpu)) == data->cpu)
......
...@@ -586,7 +586,7 @@ static int s3c_cpufreq_build_freq(void) ...@@ -586,7 +586,7 @@ static int s3c_cpufreq_build_freq(void)
size = cpu_cur.info->calc_freqtable(&cpu_cur, NULL, 0); size = cpu_cur.info->calc_freqtable(&cpu_cur, NULL, 0);
size++; size++;
ftab = kmalloc(sizeof(*ftab) * size, GFP_KERNEL); ftab = kzalloc(sizeof(*ftab) * size, GFP_KERNEL);
if (!ftab) { if (!ftab) {
printk(KERN_ERR "%s: no memory for tables\n", __func__); printk(KERN_ERR "%s: no memory for tables\n", __func__);
return -ENOMEM; return -ENOMEM;
...@@ -664,7 +664,7 @@ int __init s3c_plltab_register(struct cpufreq_frequency_table *plls, ...@@ -664,7 +664,7 @@ int __init s3c_plltab_register(struct cpufreq_frequency_table *plls,
size = sizeof(*vals) * (plls_no + 1); size = sizeof(*vals) * (plls_no + 1);
vals = kmalloc(size, GFP_KERNEL); vals = kzalloc(size, GFP_KERNEL);
if (vals) { if (vals) {
memcpy(vals, plls, size); memcpy(vals, plls, size);
pll_reg = vals; pll_reg = vals;
......
...@@ -195,18 +195,15 @@ static int spear_cpufreq_probe(struct platform_device *pdev) ...@@ -195,18 +195,15 @@ static int spear_cpufreq_probe(struct platform_device *pdev)
cnt = prop->length / sizeof(u32); cnt = prop->length / sizeof(u32);
val = prop->value; val = prop->value;
freq_tbl = kmalloc(sizeof(*freq_tbl) * (cnt + 1), GFP_KERNEL); freq_tbl = kzalloc(sizeof(*freq_tbl) * (cnt + 1), GFP_KERNEL);
if (!freq_tbl) { if (!freq_tbl) {
ret = -ENOMEM; ret = -ENOMEM;
goto out_put_node; goto out_put_node;
} }
for (i = 0; i < cnt; i++) { for (i = 0; i < cnt; i++)
freq_tbl[i].driver_data = i;
freq_tbl[i].frequency = be32_to_cpup(val++); freq_tbl[i].frequency = be32_to_cpup(val++);
}
freq_tbl[i].driver_data = i;
freq_tbl[i].frequency = CPUFREQ_TABLE_END; freq_tbl[i].frequency = CPUFREQ_TABLE_END;
spear_cpufreq.freq_tbl = freq_tbl; spear_cpufreq.freq_tbl = freq_tbl;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册