powerpc: Use sizeof(*foo) rather than sizeof(struct foo)
authorMarkus Elfring <elfring@users.sourceforge.net>
Thu, 19 Jan 2017 16:15:30 +0000 (17:15 +0100)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 20 Mar 2018 05:47:53 +0000 (16:47 +1100)
It's slightly less error prone to use sizeof(*foo) rather than
specifying the type.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
[mpe: Consolidate into one patch, rewrite change log]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
20 files changed:
arch/powerpc/kernel/nvram_64.c
arch/powerpc/oprofile/cell/spu_task_sync.c
arch/powerpc/oprofile/cell/vma_map.c
arch/powerpc/platforms/4xx/msi.c
arch/powerpc/platforms/4xx/ocm.c
arch/powerpc/platforms/cell/axon_msi.c
arch/powerpc/platforms/cell/spider-pci.c
arch/powerpc/platforms/cell/spufs/lscsa_alloc.c
arch/powerpc/platforms/powermac/low_i2c.c
arch/powerpc/platforms/powermac/pfunc_core.c
arch/powerpc/platforms/powernv/opal-flash.c
arch/powerpc/platforms/powernv/opal-hmi.c
arch/powerpc/platforms/powernv/opal-imc.c
arch/powerpc/platforms/powernv/opal-memory-errors.c
arch/powerpc/platforms/powernv/opal-psr.c
arch/powerpc/platforms/powernv/opal-sensor-groups.c
arch/powerpc/platforms/powernv/opal-xscom.c
arch/powerpc/platforms/powernv/pci-ioda.c
arch/powerpc/platforms/ps3/mm.c
drivers/macintosh/rack-meter.c

index 496d6393bd41824b565c66b731e1b4147c7e3923..ba681dac7b467be703dee435260e9e2e7a72ef19 100644 (file)
@@ -207,8 +207,7 @@ int nvram_write_os_partition(struct nvram_os_partition *part,
 
        tmp_index = part->index;
 
-       rc = ppc_md.nvram_write((char *)&info, sizeof(struct err_log_info),
-                               &tmp_index);
+       rc = ppc_md.nvram_write((char *)&info, sizeof(info), &tmp_index);
        if (rc <= 0) {
                pr_err("%s: Failed nvram_write (%d)\n", __func__, rc);
                return rc;
@@ -244,9 +243,7 @@ int nvram_read_partition(struct nvram_os_partition *part, char *buff,
        tmp_index = part->index;
 
        if (part->os_partition) {
-               rc = ppc_md.nvram_read((char *)&info,
-                                       sizeof(struct err_log_info),
-                                       &tmp_index);
+               rc = ppc_md.nvram_read((char *)&info, sizeof(info), &tmp_index);
                if (rc <= 0) {
                        pr_err("%s: Failed nvram_read (%d)\n", __func__, rc);
                        return rc;
@@ -1173,7 +1170,7 @@ int __init nvram_scan_partitions(void)
                               "detected: 0-length partition\n");
                        goto out;
                }
-               tmp_part = kmalloc(sizeof(struct nvram_partition), GFP_KERNEL);
+               tmp_part = kmalloc(sizeof(*tmp_part), GFP_KERNEL);
                err = -ENOMEM;
                if (!tmp_part) {
                        printk(KERN_ERR "nvram_scan_partitions: kmalloc failed\n");
index 44d67b167e0b18eeb512e3c059817c31fcc0f2cc..2668cc414e4e0153411472020f287da3bfc1abae 100644 (file)
@@ -208,7 +208,7 @@ prepare_cached_spu_info(struct spu *spu, unsigned long objectId)
        /* Create cached_info and set spu_info[spu->number] to point to it.
         * spu->number is a system-wide value, not a per-node value.
         */
-       info = kzalloc(sizeof(struct cached_info), GFP_KERNEL);
+       info = kzalloc(sizeof(*info), GFP_KERNEL);
        if (!info) {
                printk(KERN_ERR "SPU_PROF: "
                       "%s, line %d: create vma_map failed\n",
index c579b16845da453b06517662c031d631a9db9b18..f40e37316dd67b77a2ee91876882701ff446e91f 100644 (file)
@@ -69,8 +69,8 @@ vma_map_add(struct vma_to_fileoffset_map *map, unsigned int vma,
            unsigned int size, unsigned int offset, unsigned int guard_ptr,
            unsigned int guard_val)
 {
-       struct vma_to_fileoffset_map *new =
-               kzalloc(sizeof(struct vma_to_fileoffset_map), GFP_KERNEL);
+       struct vma_to_fileoffset_map *new = kzalloc(sizeof(*new), GFP_KERNEL);
+
        if (!new) {
                printk(KERN_ERR "SPU_PROF: %s, line %d: malloc failed\n",
                       __func__, __LINE__);
index d50417e23add8961d8b96addbfeefd38d384464d..4b859c840ea9a8dcf75feee432b857c9b62f0fdc 100644 (file)
@@ -223,7 +223,7 @@ static int ppc4xx_msi_probe(struct platform_device *dev)
 
        dev_dbg(&dev->dev, "PCIE-MSI: Setting up MSI support...\n");
 
-       msi = kzalloc(sizeof(struct ppc4xx_msi), GFP_KERNEL);
+       msi = kzalloc(sizeof(*msi), GFP_KERNEL);
        if (!msi) {
                dev_err(&dev->dev, "No memory for MSI structure\n");
                return -ENOMEM;
index 85d9e37f5ccbf76c93c2cf71c1d70677d7a14366..69d9f60d9fe5357a5fd3c18b28833cb5198e1211 100644 (file)
@@ -339,7 +339,7 @@ void *ppc4xx_ocm_alloc(phys_addr_t *phys, int size, int align,
                if (IS_ERR_VALUE(offset))
                        continue;
 
-               ocm_blk = kzalloc(sizeof(struct ocm_block), GFP_KERNEL);
+               ocm_blk = kzalloc(sizeof(*ocm_blk), GFP_KERNEL);
                if (!ocm_blk) {
                        printk(KERN_ERR "PPC4XX OCM: could not allocate ocm block");
                        rh_free(ocm_reg->rh, offset);
index 6ea3f248b1558550bcde3df3d8749d7708c44a2c..326d34e2aa0295a5d6831091071d07f61ffc83c1 100644 (file)
@@ -342,7 +342,7 @@ static int axon_msi_probe(struct platform_device *device)
 
        pr_devel("axon_msi: setting up dn %pOF\n", dn);
 
-       msic = kzalloc(sizeof(struct axon_msic), GFP_KERNEL);
+       msic = kzalloc(sizeof(*msic), GFP_KERNEL);
        if (!msic) {
                printk(KERN_ERR "axon_msi: couldn't allocate msic for %pOF\n",
                       dn);
index d1e61e273e64a8ba4e4eefc768c70698e94dc3f3..1200d0dea512dc6ca0997e9913cb4dc2d6a3e429 100644 (file)
@@ -133,7 +133,7 @@ int __init spiderpci_iowa_init(struct iowa_bus *bus, void *data)
        pr_debug("SPIDERPCI-IOWA:Bus initialize for spider(%pOF)\n",
                 np);
 
-       priv = kzalloc(sizeof(struct spiderpci_iowa_private), GFP_KERNEL);
+       priv = kzalloc(sizeof(*priv), GFP_KERNEL);
        if (!priv) {
                pr_err("SPIDERPCI-IOWA:"
                       "Can't allocate struct spiderpci_iowa_private");
index b847e94035664dbdd6f5d9c3c4223d27c921f81d..d9de848dae478c20fbace99a95ecdce4baab4ab2 100644 (file)
@@ -36,7 +36,7 @@ int spu_alloc_lscsa(struct spu_state *csa)
        struct spu_lscsa *lscsa;
        unsigned char *p;
 
-       lscsa = vzalloc(sizeof(struct spu_lscsa));
+       lscsa = vzalloc(sizeof(*lscsa));
        if (!lscsa)
                return -ENOMEM;
        csa->lscsa = lscsa;
index 3408f315ef48ed238a43f81c82e63a9bcb652e00..fa89f30e7f27c138c0610777f4d86321be60239e 100644 (file)
@@ -492,7 +492,7 @@ static struct pmac_i2c_host_kw *__init kw_i2c_host_init(struct device_node *np)
        const u32               *psteps, *prate, *addrp;
        u32                     steps;
 
-       host = kzalloc(sizeof(struct pmac_i2c_host_kw), GFP_KERNEL);
+       host = kzalloc(sizeof(*host), GFP_KERNEL);
        if (host == NULL) {
                printk(KERN_ERR "low_i2c: Can't allocate host for %pOF\n",
                       np);
index df3c93bef228b6fa73ae4a72288f97d16e258c0e..e0462fedcdb8f50e50eb1267dfb76d2683bf5e58 100644 (file)
@@ -643,7 +643,7 @@ static int pmf_add_function_prop(struct pmf_device *dev, void *driverdata,
 
        while (length >= 12) {
                /* Allocate a structure */
-               func = kzalloc(sizeof(struct pmf_function), GFP_KERNEL);
+               func = kzalloc(sizeof(*func), GFP_KERNEL);
                if (func == NULL)
                        goto bail;
                kref_init(&func->ref);
@@ -719,7 +719,7 @@ int pmf_register_driver(struct device_node *np,
                return -EBUSY;
        }
 
-       dev = kzalloc(sizeof(struct pmf_device), GFP_KERNEL);
+       dev = kzalloc(sizeof(*dev), GFP_KERNEL);
        if (dev == NULL) {
                DBG("pmf: no memory !\n");
                return -ENOMEM;
index 2fa3ac80cb4e5c002ae17b1382e2d278282363e0..1cb0b895a236eef025478a3c4da2fe789ac6a3a5 100644 (file)
@@ -418,12 +418,12 @@ static int alloc_image_buf(char *buffer, size_t count)
        void *addr;
        int size;
 
-       if (count < sizeof(struct image_header_t)) {
+       if (count < sizeof(image_header)) {
                pr_warn("FLASH: Invalid candidate image\n");
                return -EINVAL;
        }
 
-       memcpy(&image_header, (void *)buffer, sizeof(struct image_header_t));
+       memcpy(&image_header, (void *)buffer, sizeof(image_header));
        image_data.size = be32_to_cpu(image_header.size);
        pr_debug("FLASH: Candidate image size = %u\n", image_data.size);
 
index c9e1a4ff295ccea0d9a716b3c6992adbf54b5aba..4efc95b4c7d41b199a316dcdbc7e6bbd175a1626 100644 (file)
@@ -314,7 +314,7 @@ static int opal_handle_hmi_event(struct notifier_block *nb,
                pr_err("HMI: out of memory, Opal message event not handled\n");
                return -ENOMEM;
        }
-       memcpy(&msg_node->hmi_evt, hmi_evt, sizeof(struct OpalHMIEvent));
+       memcpy(&msg_node->hmi_evt, hmi_evt, sizeof(*hmi_evt));
 
        spin_lock_irqsave(&opal_hmi_evt_lock, flags);
        list_add(&msg_node->list, &opal_hmi_evt_list);
index f6f55ab4980e7684a09942a510daf689f79f6d1c..2a14fda5ea26007754b69052efb1736cd054e79e 100644 (file)
@@ -110,11 +110,11 @@ static int imc_get_mem_addr_nest(struct device_node *node,
        if (nr_chips <= 0)
                return -ENODEV;
 
-       base_addr_arr = kcalloc(nr_chips, sizeof(u64), GFP_KERNEL);
+       base_addr_arr = kcalloc(nr_chips, sizeof(*base_addr_arr), GFP_KERNEL);
        if (!base_addr_arr)
                return -ENOMEM;
 
-       chipid_arr = kcalloc(nr_chips, sizeof(u32), GFP_KERNEL);
+       chipid_arr = kcalloc(nr_chips, sizeof(*chipid_arr), GFP_KERNEL);
        if (!chipid_arr)
                return -ENOMEM;
 
@@ -125,8 +125,8 @@ static int imc_get_mem_addr_nest(struct device_node *node,
                                                                nr_chips))
                goto error;
 
-       pmu_ptr->mem_info = kcalloc(nr_chips, sizeof(struct imc_mem_info),
-                                                               GFP_KERNEL);
+       pmu_ptr->mem_info = kcalloc(nr_chips, sizeof(*pmu_ptr->mem_info),
+                                   GFP_KERNEL);
        if (!pmu_ptr->mem_info)
                goto error;
 
@@ -161,7 +161,7 @@ static int imc_pmu_create(struct device_node *parent, int pmu_index, int domain)
        u32 offset;
 
        /* memory for pmu */
-       pmu_ptr = kzalloc(sizeof(struct imc_pmu), GFP_KERNEL);
+       pmu_ptr = kzalloc(sizeof(*pmu_ptr), GFP_KERNEL);
        if (!pmu_ptr)
                return -ENOMEM;
 
index 8ddc1accf199d3f6fbc6ce58c880afaa044e8914..dcb42bcb5efa2417a99d74ada4c066bc5f9214b2 100644 (file)
@@ -112,7 +112,7 @@ static int opal_memory_err_event(struct notifier_block *nb,
                       "handled\n");
                return -ENOMEM;
        }
-       memcpy(&msg_node->msg, msg, sizeof(struct opal_msg));
+       memcpy(&msg_node->msg, msg, sizeof(msg_node->msg));
 
        spin_lock_irqsave(&opal_mem_err_lock, flags);
        list_add(&msg_node->list, &opal_memory_err_list);
index 7313b7fc9071f889cd3053ce938de9b2cf313a57..74986b35cf774a2032441b5167e3697ac06a5c4b 100644 (file)
@@ -136,7 +136,7 @@ void __init opal_psr_init(void)
                return;
        }
 
-       psr_attrs = kcalloc(of_get_child_count(psr), sizeof(struct psr_attr),
+       psr_attrs = kcalloc(of_get_child_count(psr), sizeof(*psr_attrs),
                            GFP_KERNEL);
        if (!psr_attrs)
                return;
index 7e5a235ebf767700649d2a57202ec3dd4b3616ff..541c9ea04a32f6fac9094b2d36779978aa1043cb 100644 (file)
@@ -166,13 +166,13 @@ void __init opal_sensor_groups_init(void)
                if (!nr_attrs)
                        continue;
 
-               sgs[i].sgattrs = kcalloc(nr_attrs, sizeof(struct sg_attr),
+               sgs[i].sgattrs = kcalloc(nr_attrs, sizeof(*sgs[i].sgattrs),
                                         GFP_KERNEL);
                if (!sgs[i].sgattrs)
                        goto out_sgs_sgattrs;
 
                sgs[i].sg.attrs = kcalloc(nr_attrs + 1,
-                                         sizeof(struct attribute *),
+                                         sizeof(*sgs[i].sg.attrs),
                                          GFP_KERNEL);
 
                if (!sgs[i].sg.attrs) {
index 81c0a943dea9bb581d0f6d663df5c431a5529127..22d5e1110dbb9e8a25d3c1c600b91897250eb642 100644 (file)
@@ -46,7 +46,7 @@ static scom_map_t opal_scom_map(struct device_node *dev, u64 reg, u64 count)
                        __func__, dev);
                return SCOM_MAP_INVALID;
        }
-       m = kmalloc(sizeof(struct opal_scom_map), GFP_KERNEL);
+       m = kmalloc(sizeof(*m), GFP_KERNEL);
        if (!m)
                return NULL;
        m->chip = be32_to_cpup(gcid);
index a6c92c78c9b20b9cc2507cfb5c3e749e05a6e19d..6c307f0650bb2a22a1e76ad12ce107f4290483cb 100644 (file)
@@ -3843,7 +3843,7 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,
        phb_id = be64_to_cpup(prop64);
        pr_debug("  PHB-ID  : 0x%016llx\n", phb_id);
 
-       phb = memblock_virt_alloc(sizeof(struct pnv_phb), 0);
+       phb = memblock_virt_alloc(sizeof(*phb), 0);
 
        /* Allocate PCI controller */
        phb->hose = hose = pcibios_alloc_controller(np);
index 7f870ec29daf0675e366daff6552096de03adb41..8c7009d001d96aba4766a2f590ea3011347b9181 100644 (file)
@@ -524,8 +524,7 @@ static int dma_sb_map_pages(struct ps3_dma_region *r, unsigned long phys_addr,
        int result;
        struct dma_chunk *c;
 
-       c = kzalloc(sizeof(struct dma_chunk), GFP_ATOMIC);
-
+       c = kzalloc(sizeof(*c), GFP_ATOMIC);
        if (!c) {
                result = -ENOMEM;
                goto fail_alloc;
@@ -570,8 +569,7 @@ static int dma_ioc0_map_pages(struct ps3_dma_region *r, unsigned long phys_addr,
 
        DBG(KERN_ERR "%s: phy=%#lx, lpar%#lx, len=%#lx\n", __func__,
            phys_addr, ps3_mm_phys_to_lpar(phys_addr), len);
-       c = kzalloc(sizeof(struct dma_chunk), GFP_ATOMIC);
-
+       c = kzalloc(sizeof(*c), GFP_ATOMIC);
        if (!c) {
                result = -ENOMEM;
                goto fail_alloc;
index 910b5b6f96b1439a5843b8b08aa81b86e6ca5e9b..190c9efeace5d312f65b63115e4233c28395d75f 100644 (file)
@@ -397,7 +397,7 @@ static int rackmeter_probe(struct macio_dev* mdev,
        }
 
        /* Create and initialize our instance data */
-       rm = kzalloc(sizeof(struct rackmeter), GFP_KERNEL);
+       rm = kzalloc(sizeof(*rm), GFP_KERNEL);
        if (rm == NULL) {
                printk(KERN_ERR "rackmeter: failed to allocate memory !\n");
                rc = -ENOMEM;