cpufreq: Use sizeof(*ptr) convetion for computing sizes
authorViresh Kumar <viresh.kumar@linaro.org>
Tue, 6 Aug 2013 17:23:06 +0000 (22:53 +0530)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 7 Aug 2013 21:34:10 +0000 (23:34 +0200)
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: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
15 files changed:
drivers/cpufreq/acpi-cpufreq.c
drivers/cpufreq/cpufreq.c
drivers/cpufreq/cpufreq_conservative.c
drivers/cpufreq/cpufreq_ondemand.c
drivers/cpufreq/cpufreq_stats.c
drivers/cpufreq/e_powersaver.c
drivers/cpufreq/exynos-cpufreq.c
drivers/cpufreq/gx-suspmod.c
drivers/cpufreq/ia64-acpi-cpufreq.c
drivers/cpufreq/pmac64-cpufreq.c
drivers/cpufreq/powernow-k7.c
drivers/cpufreq/powernow-k8.c
drivers/cpufreq/s3c24xx-cpufreq.c
drivers/cpufreq/sparc-us2e-cpufreq.c
drivers/cpufreq/sparc-us3-cpufreq.c

index e673670d2321fdbfe53349dafc4754d08ebcadc0..44758ce9936d6cefd4e6a44a2e44ed6c8cfd5293 100644 (file)
@@ -709,7 +709,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
                return blacklisted;
 #endif
 
-       data = kzalloc(sizeof(struct acpi_cpufreq_data), GFP_KERNEL);
+       data = kzalloc(sizeof(*data), GFP_KERNEL);
        if (!data)
                return -ENOMEM;
 
@@ -799,7 +799,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
                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);
        if (!data->freq_table) {
                result = -ENOMEM;
index 1793fe82595d568c0b00123777267c9e68ae6500..9e83d9142072a27b5eaf555371a6ea712d9ea1ce 100644 (file)
@@ -873,7 +873,7 @@ static void cpufreq_init_policy(struct cpufreq_policy *policy)
        struct cpufreq_policy new_policy;
        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 */
        policy->governor = NULL;
 
@@ -1818,7 +1818,7 @@ int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu)
        if (!cpu_policy)
                return -EINVAL;
 
-       memcpy(policy, cpu_policy, sizeof(struct cpufreq_policy));
+       memcpy(policy, cpu_policy, sizeof(*policy));
 
        cpufreq_cpu_put(cpu_policy);
        return 0;
@@ -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,
                new_policy->min, new_policy->max);
 
-       memcpy(&new_policy->cpuinfo, &policy->cpuinfo,
-                               sizeof(struct cpufreq_cpuinfo));
+       memcpy(&new_policy->cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo));
 
        if (new_policy->min > policy->max || new_policy->max < policy->min) {
                ret = -EINVAL;
@@ -1957,7 +1956,7 @@ int cpufreq_update_policy(unsigned int 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.max = policy->user_policy.max;
        new_policy.policy = policy->user_policy.policy;
index 841e25699656bc6a316603d610baf8ef444e9353..c4009241e7338ef2d6168f7d1d8e843299349f95 100644 (file)
@@ -317,7 +317,7 @@ static int cs_init(struct dbs_data *dbs_data)
 {
        struct cs_dbs_tuners *tuners;
 
-       tuners = kzalloc(sizeof(struct cs_dbs_tuners), GFP_KERNEL);
+       tuners = kzalloc(sizeof(*tuners), GFP_KERNEL);
        if (!tuners) {
                pr_err("%s: kzalloc failed\n", __func__);
                return -ENOMEM;
index 47d4b69be7c6e4117c140ef4419c79d2b47b14c7..117278ab586968a99af32c56ed8e0a3db40cbf30 100644 (file)
@@ -482,7 +482,7 @@ static int od_init(struct dbs_data *dbs_data)
        u64 idle_time;
        int cpu;
 
-       tuners = kzalloc(sizeof(struct od_dbs_tuners), GFP_KERNEL);
+       tuners = kzalloc(sizeof(*tuners), GFP_KERNEL);
        if (!tuners) {
                pr_err("%s: kzalloc failed\n", __func__);
                return -ENOMEM;
index a17b14ee37d8513dc00fe0e179ce7c7051ed63b3..04452f026ed085a7b61f87c623c8677a2e242864 100644 (file)
@@ -198,7 +198,7 @@ static int cpufreq_stats_create_table(struct cpufreq_policy *policy,
        unsigned int cpu = policy->cpu;
        if (per_cpu(cpufreq_stats_table, cpu))
                return -EBUSY;
-       stat = kzalloc(sizeof(struct cpufreq_stats), GFP_KERNEL);
+       stat = kzalloc(sizeof(*stat), GFP_KERNEL);
        if ((stat) == NULL)
                return -ENOMEM;
 
index a60efaeb4cf8c17291ec97a0ba86bb383fe81d55..de974be6b7736fc839eb6d9d78103139eb660a5c 100644 (file)
@@ -54,7 +54,7 @@ static struct acpi_processor_performance *eps_acpi_cpu_perf;
 /* Minimum necessary to get acpi_processor_get_bios_limit() working */
 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);
        if (!eps_acpi_cpu_perf)
                return -ENOMEM;
@@ -366,7 +366,7 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
                states = 2;
 
        /* 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),
                    GFP_KERNEL);
        if (!centaur)
index 0d32f02ef4d644e5ec915b9205fd5fdf929b30b0..366475161c76aa86e320b881fd9d775d638b0065 100644 (file)
@@ -289,7 +289,7 @@ static int __init exynos_cpufreq_init(void)
 {
        int ret = -EINVAL;
 
-       exynos_info = kzalloc(sizeof(struct exynos_dvfs_info), GFP_KERNEL);
+       exynos_info = kzalloc(sizeof(*exynos_info), GFP_KERNEL);
        if (!exynos_info)
                return -ENOMEM;
 
index 3dfc99b9ca86f3228d0f0a8d8b600bd7ae11f260..4f25fb63c097bdd0ec87048e055786171e53bc27 100644 (file)
@@ -466,7 +466,7 @@ static int __init cpufreq_gx_init(void)
 
        pr_debug("geode suspend modulation available.\n");
 
-       params = kzalloc(sizeof(struct gxfreq_params), GFP_KERNEL);
+       params = kzalloc(sizeof(*params), GFP_KERNEL);
        if (params == NULL)
                return -ENOMEM;
 
index 573c14ea802df7690f0e57ff3d8764b46305e51c..08792dd4d62a96caa5820657d8c085e255f8c057 100644 (file)
@@ -274,7 +274,7 @@ acpi_cpufreq_cpu_init (
 
        pr_debug("acpi_cpufreq_cpu_init\n");
 
-       data = kzalloc(sizeof(struct cpufreq_acpi_io), GFP_KERNEL);
+       data = kzalloc(sizeof(*data), GFP_KERNEL);
        if (!data)
                return (-ENOMEM);
 
@@ -304,7 +304,7 @@ acpi_cpufreq_cpu_init (
        }
 
        /* 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),
                                   GFP_KERNEL);
        if (!data->freq_table) {
index 7ba423431cfe0dfb53fcbe3c7f7195882c36ac3d..4d7799b7af8666bcc8108b9c8c654005867a054c 100644 (file)
@@ -447,9 +447,8 @@ static int __init g5_neo2_cpufreq_init(struct device_node *cpus)
                if (!shdr)
                        goto bail_noprops;
                g5_fvt_table = (struct smu_sdbp_fvt *)&shdr[1];
-               ssize = (shdr->len * sizeof(u32)) -
-                       sizeof(struct smu_sdbp_header);
-               g5_fvt_count = ssize / sizeof(struct smu_sdbp_fvt);
+               ssize = (shdr->len * sizeof(u32)) - sizeof(*shdr);
+               g5_fvt_count = ssize / sizeof(*g5_fvt_table);
                g5_fvt_cur = 0;
 
                /* Sanity checking */
index 9558708779350a9b00ee6951241ac9bf24551766..4687d40d02195d46f277aee0b59cbcd9dbede061 100644 (file)
@@ -177,7 +177,7 @@ static int get_ranges(unsigned char *pst)
        unsigned int speed;
        u8 fid, vid;
 
-       powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) *
+       powernow_table = kzalloc((sizeof(*powernow_table) *
                                (number_scales + 1)), GFP_KERNEL);
        if (!powernow_table)
                return -ENOMEM;
@@ -309,8 +309,7 @@ static int powernow_acpi_init(void)
                goto err0;
        }
 
-       acpi_processor_perf = kzalloc(sizeof(struct acpi_processor_performance),
-                                     GFP_KERNEL);
+       acpi_processor_perf = kzalloc(sizeof(*acpi_processor_perf), GFP_KERNEL);
        if (!acpi_processor_perf) {
                retval = -ENOMEM;
                goto err0;
@@ -346,7 +345,7 @@ static int powernow_acpi_init(void)
                goto err2;
        }
 
-       powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) *
+       powernow_table = kzalloc((sizeof(*powernow_table) *
                                (number_scales + 1)), GFP_KERNEL);
        if (!powernow_table) {
                retval = -ENOMEM;
@@ -497,7 +496,7 @@ static int powernow_decode_bios(int maxfid, int startvid)
                                        "relevant to this CPU).\n",
                                        psb->numpst);
 
-                       p += sizeof(struct psb_s);
+                       p += sizeof(*psb);
 
                        pst = (struct pst_s *) p;
 
@@ -510,12 +509,12 @@ static int powernow_decode_bios(int maxfid, int startvid)
                                    (maxfid == pst->maxfid) &&
                                    (startvid == pst->startvid)) {
                                        print_pst_entry(pst, j);
-                                       p = (char *)pst + sizeof(struct pst_s);
+                                       p = (char *)pst + sizeof(*pst);
                                        ret = get_ranges(p);
                                        return ret;
                                } else {
                                        unsigned int k;
-                                       p = (char *)pst + sizeof(struct pst_s);
+                                       p = (char *)pst + sizeof(*pst);
                                        for (k = 0; k < number_scales; k++)
                                                p += 2;
                                }
index c39d189217cb6d5fedd521c602464d296b4d47bf..3f3c6cae91d08b5d3b8fc9092bb9125982adce53 100644 (file)
@@ -623,7 +623,7 @@ static int fill_powernow_table(struct powernow_k8_data *data,
        if (check_pst_table(data, pst, maxvid))
                return -EINVAL;
 
-       powernow_table = kmalloc((sizeof(struct cpufreq_frequency_table)
+       powernow_table = kmalloc((sizeof(*powernow_table)
                * (data->numps + 1)), GFP_KERNEL);
        if (!powernow_table) {
                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)
        }
 
        /* 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);
        if (!powernow_table) {
                pr_debug("powernow_table memory alloc failure\n");
@@ -1106,7 +1106,7 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol)
        if (rc)
                return -ENODEV;
 
-       data = kzalloc(sizeof(struct powernow_k8_data), GFP_KERNEL);
+       data = kzalloc(sizeof(*data), GFP_KERNEL);
        if (!data) {
                printk(KERN_ERR PFX "unable to alloc powernow_k8_data");
                return -ENOMEM;
index 87781eb20d6dce41c4b6c376f4937f67d808d0be..f169ee52e6ebf734d73e1bea4d956e829a18f7a3 100644 (file)
@@ -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
         * initdata. */
 
-       ours = kzalloc(sizeof(struct s3c_cpufreq_board), GFP_KERNEL);
+       ours = kzalloc(sizeof(*ours), GFP_KERNEL);
        if (ours == NULL) {
                printk(KERN_ERR "%s: no memory\n", __func__);
                return -ENOMEM;
@@ -615,7 +615,7 @@ static int s3c_cpufreq_build_freq(void)
        size = cpu_cur.info->calc_freqtable(&cpu_cur, NULL, 0);
        size++;
 
-       ftab = kmalloc(sizeof(struct cpufreq_frequency_table) * size, GFP_KERNEL);
+       ftab = kmalloc(sizeof(*ftab) * size, GFP_KERNEL);
        if (!ftab) {
                printk(KERN_ERR "%s: no memory for tables\n", __func__);
                return -ENOMEM;
@@ -691,7 +691,7 @@ int __init s3c_plltab_register(struct cpufreq_frequency_table *plls,
        struct cpufreq_frequency_table *vals;
        unsigned int size;
 
-       size = sizeof(struct cpufreq_frequency_table) * (plls_no + 1);
+       size = sizeof(*vals) * (plls_no + 1);
 
        vals = kmalloc(size, GFP_KERNEL);
        if (vals) {
index 93061a40877383b09ceff0cb7bd0bc2bba60a08a..7c43a725e5da573641c94f33b37e35dfef83230f 100644 (file)
@@ -351,12 +351,11 @@ static int __init us2e_freq_init(void)
                struct cpufreq_driver *driver;
 
                ret = -ENOMEM;
-               driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
+               driver = kzalloc(sizeof(*driver), GFP_KERNEL);
                if (!driver)
                        goto err_out;
 
-               us2e_freq_table = kzalloc(
-                       (NR_CPUS * sizeof(struct us2e_freq_percpu_info)),
+               us2e_freq_table = kzalloc((NR_CPUS * sizeof(*us2e_freq_table)),
                        GFP_KERNEL);
                if (!us2e_freq_table)
                        goto err_out;
index 880ee293d61eda8c131187d65579a5216ce2b00d..7f500c140bc3a81dff5c9a923e8904f3ae3c5a66 100644 (file)
@@ -212,12 +212,11 @@ static int __init us3_freq_init(void)
                struct cpufreq_driver *driver;
 
                ret = -ENOMEM;
-               driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
+               driver = kzalloc(sizeof(*driver), GFP_KERNEL);
                if (!driver)
                        goto err_out;
 
-               us3_freq_table = kzalloc(
-                       (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
+               us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
                        GFP_KERNEL);
                if (!us3_freq_table)
                        goto err_out;