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

cpufreq: Use sizeof(*ptr) convetion for computing sizes

Chapter 14 of Documentation/CodingStyle says:

The preferred form for passing a size of a struct is the following:

	p = kmalloc(sizeof(*p), ...);

The alternative form where struct name is spelled out hurts
readability and introduces an opportunity for a bug when the pointer
variable type is changed but the corresponding sizeof that is passed
to a memory allocator is not.

This wasn't followed consistently in drivers/cpufreq, let's make it
more consistent by always following this rule.
Signed-off-by: NViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
上级 3a3e9e06
...@@ -709,7 +709,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy) ...@@ -709,7 +709,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
return blacklisted; return blacklisted;
#endif #endif
data = kzalloc(sizeof(struct acpi_cpufreq_data), GFP_KERNEL); data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
...@@ -799,7 +799,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy) ...@@ -799,7 +799,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
goto err_unreg; goto err_unreg;
} }
data->freq_table = kmalloc(sizeof(struct cpufreq_frequency_table) * data->freq_table = kmalloc(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;
......
...@@ -873,7 +873,7 @@ static void cpufreq_init_policy(struct cpufreq_policy *policy) ...@@ -873,7 +873,7 @@ static void cpufreq_init_policy(struct cpufreq_policy *policy)
struct cpufreq_policy new_policy; struct cpufreq_policy new_policy;
int ret = 0; int ret = 0;
memcpy(&new_policy, policy, sizeof(struct cpufreq_policy)); memcpy(&new_policy, policy, sizeof(*policy));
/* assure that the starting sequence is run in __cpufreq_set_policy */ /* assure that the starting sequence is run in __cpufreq_set_policy */
policy->governor = NULL; policy->governor = NULL;
...@@ -1818,7 +1818,7 @@ int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu) ...@@ -1818,7 +1818,7 @@ int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu)
if (!cpu_policy) if (!cpu_policy)
return -EINVAL; return -EINVAL;
memcpy(policy, cpu_policy, sizeof(struct cpufreq_policy)); memcpy(policy, cpu_policy, sizeof(*policy));
cpufreq_cpu_put(cpu_policy); cpufreq_cpu_put(cpu_policy);
return 0; return 0;
...@@ -1837,8 +1837,7 @@ static int __cpufreq_set_policy(struct cpufreq_policy *policy, ...@@ -1837,8 +1837,7 @@ static int __cpufreq_set_policy(struct cpufreq_policy *policy,
pr_debug("setting new policy for CPU %u: %u - %u kHz\n", new_policy->cpu, pr_debug("setting new policy for CPU %u: %u - %u kHz\n", new_policy->cpu,
new_policy->min, new_policy->max); new_policy->min, new_policy->max);
memcpy(&new_policy->cpuinfo, &policy->cpuinfo, memcpy(&new_policy->cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo));
sizeof(struct cpufreq_cpuinfo));
if (new_policy->min > policy->max || new_policy->max < policy->min) { if (new_policy->min > policy->max || new_policy->max < policy->min) {
ret = -EINVAL; ret = -EINVAL;
...@@ -1957,7 +1956,7 @@ int cpufreq_update_policy(unsigned int cpu) ...@@ -1957,7 +1956,7 @@ int cpufreq_update_policy(unsigned int cpu)
} }
pr_debug("updating policy for CPU %u\n", cpu); pr_debug("updating policy for CPU %u\n", cpu);
memcpy(&new_policy, policy, sizeof(struct cpufreq_policy)); memcpy(&new_policy, policy, sizeof(*policy));
new_policy.min = policy->user_policy.min; new_policy.min = policy->user_policy.min;
new_policy.max = policy->user_policy.max; new_policy.max = policy->user_policy.max;
new_policy.policy = policy->user_policy.policy; new_policy.policy = policy->user_policy.policy;
......
...@@ -317,7 +317,7 @@ static int cs_init(struct dbs_data *dbs_data) ...@@ -317,7 +317,7 @@ static int cs_init(struct dbs_data *dbs_data)
{ {
struct cs_dbs_tuners *tuners; struct cs_dbs_tuners *tuners;
tuners = kzalloc(sizeof(struct cs_dbs_tuners), GFP_KERNEL); tuners = kzalloc(sizeof(*tuners), GFP_KERNEL);
if (!tuners) { if (!tuners) {
pr_err("%s: kzalloc failed\n", __func__); pr_err("%s: kzalloc failed\n", __func__);
return -ENOMEM; return -ENOMEM;
......
...@@ -482,7 +482,7 @@ static int od_init(struct dbs_data *dbs_data) ...@@ -482,7 +482,7 @@ static int od_init(struct dbs_data *dbs_data)
u64 idle_time; u64 idle_time;
int cpu; int cpu;
tuners = kzalloc(sizeof(struct od_dbs_tuners), GFP_KERNEL); tuners = kzalloc(sizeof(*tuners), GFP_KERNEL);
if (!tuners) { if (!tuners) {
pr_err("%s: kzalloc failed\n", __func__); pr_err("%s: kzalloc failed\n", __func__);
return -ENOMEM; return -ENOMEM;
......
...@@ -198,7 +198,7 @@ static int cpufreq_stats_create_table(struct cpufreq_policy *policy, ...@@ -198,7 +198,7 @@ static int cpufreq_stats_create_table(struct cpufreq_policy *policy,
unsigned int cpu = policy->cpu; unsigned int cpu = policy->cpu;
if (per_cpu(cpufreq_stats_table, cpu)) if (per_cpu(cpufreq_stats_table, cpu))
return -EBUSY; return -EBUSY;
stat = kzalloc(sizeof(struct cpufreq_stats), GFP_KERNEL); stat = kzalloc(sizeof(*stat), GFP_KERNEL);
if ((stat) == NULL) if ((stat) == NULL)
return -ENOMEM; return -ENOMEM;
......
...@@ -54,7 +54,7 @@ static struct acpi_processor_performance *eps_acpi_cpu_perf; ...@@ -54,7 +54,7 @@ static struct acpi_processor_performance *eps_acpi_cpu_perf;
/* Minimum necessary to get acpi_processor_get_bios_limit() working */ /* Minimum necessary to get acpi_processor_get_bios_limit() working */
static int eps_acpi_init(void) static int eps_acpi_init(void)
{ {
eps_acpi_cpu_perf = kzalloc(sizeof(struct acpi_processor_performance), eps_acpi_cpu_perf = kzalloc(sizeof(*eps_acpi_cpu_perf),
GFP_KERNEL); GFP_KERNEL);
if (!eps_acpi_cpu_perf) if (!eps_acpi_cpu_perf)
return -ENOMEM; return -ENOMEM;
...@@ -366,7 +366,7 @@ static int eps_cpu_init(struct cpufreq_policy *policy) ...@@ -366,7 +366,7 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
states = 2; states = 2;
/* Allocate private data and frequency table for current cpu */ /* Allocate private data and frequency table for current cpu */
centaur = kzalloc(sizeof(struct eps_cpu_data) centaur = kzalloc(sizeof(*centaur)
+ (states + 1) * sizeof(struct cpufreq_frequency_table), + (states + 1) * sizeof(struct cpufreq_frequency_table),
GFP_KERNEL); GFP_KERNEL);
if (!centaur) if (!centaur)
......
...@@ -289,7 +289,7 @@ static int __init exynos_cpufreq_init(void) ...@@ -289,7 +289,7 @@ static int __init exynos_cpufreq_init(void)
{ {
int ret = -EINVAL; int ret = -EINVAL;
exynos_info = kzalloc(sizeof(struct exynos_dvfs_info), GFP_KERNEL); exynos_info = kzalloc(sizeof(*exynos_info), GFP_KERNEL);
if (!exynos_info) if (!exynos_info)
return -ENOMEM; return -ENOMEM;
......
...@@ -466,7 +466,7 @@ static int __init cpufreq_gx_init(void) ...@@ -466,7 +466,7 @@ static int __init cpufreq_gx_init(void)
pr_debug("geode suspend modulation available.\n"); pr_debug("geode suspend modulation available.\n");
params = kzalloc(sizeof(struct gxfreq_params), GFP_KERNEL); params = kzalloc(sizeof(*params), GFP_KERNEL);
if (params == NULL) if (params == NULL)
return -ENOMEM; return -ENOMEM;
......
...@@ -274,7 +274,7 @@ acpi_cpufreq_cpu_init ( ...@@ -274,7 +274,7 @@ acpi_cpufreq_cpu_init (
pr_debug("acpi_cpufreq_cpu_init\n"); pr_debug("acpi_cpufreq_cpu_init\n");
data = kzalloc(sizeof(struct cpufreq_acpi_io), GFP_KERNEL); data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data) if (!data)
return (-ENOMEM); return (-ENOMEM);
...@@ -304,7 +304,7 @@ acpi_cpufreq_cpu_init ( ...@@ -304,7 +304,7 @@ acpi_cpufreq_cpu_init (
} }
/* alloc freq_table */ /* alloc freq_table */
data->freq_table = kmalloc(sizeof(struct cpufreq_frequency_table) * data->freq_table = kmalloc(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) {
......
...@@ -447,9 +447,8 @@ static int __init g5_neo2_cpufreq_init(struct device_node *cpus) ...@@ -447,9 +447,8 @@ static int __init g5_neo2_cpufreq_init(struct device_node *cpus)
if (!shdr) if (!shdr)
goto bail_noprops; goto bail_noprops;
g5_fvt_table = (struct smu_sdbp_fvt *)&shdr[1]; g5_fvt_table = (struct smu_sdbp_fvt *)&shdr[1];
ssize = (shdr->len * sizeof(u32)) - ssize = (shdr->len * sizeof(u32)) - sizeof(*shdr);
sizeof(struct smu_sdbp_header); g5_fvt_count = ssize / sizeof(*g5_fvt_table);
g5_fvt_count = ssize / sizeof(struct smu_sdbp_fvt);
g5_fvt_cur = 0; g5_fvt_cur = 0;
/* Sanity checking */ /* Sanity checking */
......
...@@ -177,7 +177,7 @@ static int get_ranges(unsigned char *pst) ...@@ -177,7 +177,7 @@ static int get_ranges(unsigned char *pst)
unsigned int speed; unsigned int speed;
u8 fid, vid; u8 fid, vid;
powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) * powernow_table = kzalloc((sizeof(*powernow_table) *
(number_scales + 1)), GFP_KERNEL); (number_scales + 1)), GFP_KERNEL);
if (!powernow_table) if (!powernow_table)
return -ENOMEM; return -ENOMEM;
...@@ -309,8 +309,7 @@ static int powernow_acpi_init(void) ...@@ -309,8 +309,7 @@ static int powernow_acpi_init(void)
goto err0; goto err0;
} }
acpi_processor_perf = kzalloc(sizeof(struct acpi_processor_performance), acpi_processor_perf = kzalloc(sizeof(*acpi_processor_perf), GFP_KERNEL);
GFP_KERNEL);
if (!acpi_processor_perf) { if (!acpi_processor_perf) {
retval = -ENOMEM; retval = -ENOMEM;
goto err0; goto err0;
...@@ -346,7 +345,7 @@ static int powernow_acpi_init(void) ...@@ -346,7 +345,7 @@ static int powernow_acpi_init(void)
goto err2; goto err2;
} }
powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) * powernow_table = kzalloc((sizeof(*powernow_table) *
(number_scales + 1)), GFP_KERNEL); (number_scales + 1)), GFP_KERNEL);
if (!powernow_table) { if (!powernow_table) {
retval = -ENOMEM; retval = -ENOMEM;
...@@ -497,7 +496,7 @@ static int powernow_decode_bios(int maxfid, int startvid) ...@@ -497,7 +496,7 @@ static int powernow_decode_bios(int maxfid, int startvid)
"relevant to this CPU).\n", "relevant to this CPU).\n",
psb->numpst); psb->numpst);
p += sizeof(struct psb_s); p += sizeof(*psb);
pst = (struct pst_s *) p; pst = (struct pst_s *) p;
...@@ -510,12 +509,12 @@ static int powernow_decode_bios(int maxfid, int startvid) ...@@ -510,12 +509,12 @@ static int powernow_decode_bios(int maxfid, int startvid)
(maxfid == pst->maxfid) && (maxfid == pst->maxfid) &&
(startvid == pst->startvid)) { (startvid == pst->startvid)) {
print_pst_entry(pst, j); print_pst_entry(pst, j);
p = (char *)pst + sizeof(struct pst_s); p = (char *)pst + sizeof(*pst);
ret = get_ranges(p); ret = get_ranges(p);
return ret; return ret;
} else { } else {
unsigned int k; unsigned int k;
p = (char *)pst + sizeof(struct pst_s); p = (char *)pst + sizeof(*pst);
for (k = 0; k < number_scales; k++) for (k = 0; k < number_scales; k++)
p += 2; p += 2;
} }
......
...@@ -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(struct cpufreq_frequency_table) powernow_table = kmalloc((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(struct cpufreq_frequency_table) powernow_table = kmalloc((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");
...@@ -1106,7 +1106,7 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol) ...@@ -1106,7 +1106,7 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol)
if (rc) if (rc)
return -ENODEV; return -ENODEV;
data = kzalloc(sizeof(struct powernow_k8_data), GFP_KERNEL); data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data) { if (!data) {
printk(KERN_ERR PFX "unable to alloc powernow_k8_data"); printk(KERN_ERR PFX "unable to alloc powernow_k8_data");
return -ENOMEM; return -ENOMEM;
......
...@@ -522,7 +522,7 @@ int __init s3c_cpufreq_setboard(struct s3c_cpufreq_board *board) ...@@ -522,7 +522,7 @@ int __init s3c_cpufreq_setboard(struct s3c_cpufreq_board *board)
/* Copy the board information so that each board can make this /* Copy the board information so that each board can make this
* initdata. */ * initdata. */
ours = kzalloc(sizeof(struct s3c_cpufreq_board), GFP_KERNEL); ours = kzalloc(sizeof(*ours), GFP_KERNEL);
if (ours == NULL) { if (ours == NULL) {
printk(KERN_ERR "%s: no memory\n", __func__); printk(KERN_ERR "%s: no memory\n", __func__);
return -ENOMEM; return -ENOMEM;
...@@ -615,7 +615,7 @@ static int s3c_cpufreq_build_freq(void) ...@@ -615,7 +615,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(struct cpufreq_frequency_table) * size, GFP_KERNEL); ftab = kmalloc(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;
...@@ -691,7 +691,7 @@ int __init s3c_plltab_register(struct cpufreq_frequency_table *plls, ...@@ -691,7 +691,7 @@ int __init s3c_plltab_register(struct cpufreq_frequency_table *plls,
struct cpufreq_frequency_table *vals; struct cpufreq_frequency_table *vals;
unsigned int size; unsigned int size;
size = sizeof(struct cpufreq_frequency_table) * (plls_no + 1); size = sizeof(*vals) * (plls_no + 1);
vals = kmalloc(size, GFP_KERNEL); vals = kmalloc(size, GFP_KERNEL);
if (vals) { if (vals) {
......
...@@ -351,12 +351,11 @@ static int __init us2e_freq_init(void) ...@@ -351,12 +351,11 @@ static int __init us2e_freq_init(void)
struct cpufreq_driver *driver; struct cpufreq_driver *driver;
ret = -ENOMEM; ret = -ENOMEM;
driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL); driver = kzalloc(sizeof(*driver), GFP_KERNEL);
if (!driver) if (!driver)
goto err_out; goto err_out;
us2e_freq_table = kzalloc( us2e_freq_table = kzalloc((NR_CPUS * sizeof(*us2e_freq_table)),
(NR_CPUS * sizeof(struct us2e_freq_percpu_info)),
GFP_KERNEL); GFP_KERNEL);
if (!us2e_freq_table) if (!us2e_freq_table)
goto err_out; goto err_out;
......
...@@ -212,12 +212,11 @@ static int __init us3_freq_init(void) ...@@ -212,12 +212,11 @@ static int __init us3_freq_init(void)
struct cpufreq_driver *driver; struct cpufreq_driver *driver;
ret = -ENOMEM; ret = -ENOMEM;
driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL); driver = kzalloc(sizeof(*driver), GFP_KERNEL);
if (!driver) if (!driver)
goto err_out; goto err_out;
us3_freq_table = kzalloc( us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
(NR_CPUS * sizeof(struct us3_freq_percpu_info)),
GFP_KERNEL); GFP_KERNEL);
if (!us3_freq_table) if (!us3_freq_table)
goto err_out; goto err_out;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册