Skip to content

Commit a0828cf

Browse files
elfringmpe
authored andcommitted
powerpc: Use sizeof(*foo) rather than sizeof(struct foo)
It's slightly less error prone to use sizeof(*foo) rather than specifying the type. Signed-off-by: Markus Elfring <[email protected]> [mpe: Consolidate into one patch, rewrite change log] Signed-off-by: Michael Ellerman <[email protected]>
1 parent 3151320 commit a0828cf

File tree

20 files changed

+31
-36
lines changed

20 files changed

+31
-36
lines changed

arch/powerpc/kernel/nvram_64.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ int nvram_write_os_partition(struct nvram_os_partition *part,
207207

208208
tmp_index = part->index;
209209

210-
rc = ppc_md.nvram_write((char *)&info, sizeof(struct err_log_info),
211-
&tmp_index);
210+
rc = ppc_md.nvram_write((char *)&info, sizeof(info), &tmp_index);
212211
if (rc <= 0) {
213212
pr_err("%s: Failed nvram_write (%d)\n", __func__, rc);
214213
return rc;
@@ -244,9 +243,7 @@ int nvram_read_partition(struct nvram_os_partition *part, char *buff,
244243
tmp_index = part->index;
245244

246245
if (part->os_partition) {
247-
rc = ppc_md.nvram_read((char *)&info,
248-
sizeof(struct err_log_info),
249-
&tmp_index);
246+
rc = ppc_md.nvram_read((char *)&info, sizeof(info), &tmp_index);
250247
if (rc <= 0) {
251248
pr_err("%s: Failed nvram_read (%d)\n", __func__, rc);
252249
return rc;
@@ -1173,7 +1170,7 @@ int __init nvram_scan_partitions(void)
11731170
"detected: 0-length partition\n");
11741171
goto out;
11751172
}
1176-
tmp_part = kmalloc(sizeof(struct nvram_partition), GFP_KERNEL);
1173+
tmp_part = kmalloc(sizeof(*tmp_part), GFP_KERNEL);
11771174
err = -ENOMEM;
11781175
if (!tmp_part) {
11791176
printk(KERN_ERR "nvram_scan_partitions: kmalloc failed\n");

arch/powerpc/oprofile/cell/spu_task_sync.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ prepare_cached_spu_info(struct spu *spu, unsigned long objectId)
208208
/* Create cached_info and set spu_info[spu->number] to point to it.
209209
* spu->number is a system-wide value, not a per-node value.
210210
*/
211-
info = kzalloc(sizeof(struct cached_info), GFP_KERNEL);
211+
info = kzalloc(sizeof(*info), GFP_KERNEL);
212212
if (!info) {
213213
printk(KERN_ERR "SPU_PROF: "
214214
"%s, line %d: create vma_map failed\n",

arch/powerpc/oprofile/cell/vma_map.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ vma_map_add(struct vma_to_fileoffset_map *map, unsigned int vma,
6969
unsigned int size, unsigned int offset, unsigned int guard_ptr,
7070
unsigned int guard_val)
7171
{
72-
struct vma_to_fileoffset_map *new =
73-
kzalloc(sizeof(struct vma_to_fileoffset_map), GFP_KERNEL);
72+
struct vma_to_fileoffset_map *new = kzalloc(sizeof(*new), GFP_KERNEL);
73+
7474
if (!new) {
7575
printk(KERN_ERR "SPU_PROF: %s, line %d: malloc failed\n",
7676
__func__, __LINE__);

arch/powerpc/platforms/4xx/msi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static int ppc4xx_msi_probe(struct platform_device *dev)
223223

224224
dev_dbg(&dev->dev, "PCIE-MSI: Setting up MSI support...\n");
225225

226-
msi = kzalloc(sizeof(struct ppc4xx_msi), GFP_KERNEL);
226+
msi = kzalloc(sizeof(*msi), GFP_KERNEL);
227227
if (!msi) {
228228
dev_err(&dev->dev, "No memory for MSI structure\n");
229229
return -ENOMEM;

arch/powerpc/platforms/4xx/ocm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ void *ppc4xx_ocm_alloc(phys_addr_t *phys, int size, int align,
339339
if (IS_ERR_VALUE(offset))
340340
continue;
341341

342-
ocm_blk = kzalloc(sizeof(struct ocm_block), GFP_KERNEL);
342+
ocm_blk = kzalloc(sizeof(*ocm_blk), GFP_KERNEL);
343343
if (!ocm_blk) {
344344
printk(KERN_ERR "PPC4XX OCM: could not allocate ocm block");
345345
rh_free(ocm_reg->rh, offset);

arch/powerpc/platforms/cell/axon_msi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ static int axon_msi_probe(struct platform_device *device)
342342

343343
pr_devel("axon_msi: setting up dn %pOF\n", dn);
344344

345-
msic = kzalloc(sizeof(struct axon_msic), GFP_KERNEL);
345+
msic = kzalloc(sizeof(*msic), GFP_KERNEL);
346346
if (!msic) {
347347
printk(KERN_ERR "axon_msi: couldn't allocate msic for %pOF\n",
348348
dn);

arch/powerpc/platforms/cell/spider-pci.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ int __init spiderpci_iowa_init(struct iowa_bus *bus, void *data)
133133
pr_debug("SPIDERPCI-IOWA:Bus initialize for spider(%pOF)\n",
134134
np);
135135

136-
priv = kzalloc(sizeof(struct spiderpci_iowa_private), GFP_KERNEL);
136+
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
137137
if (!priv) {
138138
pr_err("SPIDERPCI-IOWA:"
139139
"Can't allocate struct spiderpci_iowa_private");

arch/powerpc/platforms/cell/spufs/lscsa_alloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int spu_alloc_lscsa(struct spu_state *csa)
3636
struct spu_lscsa *lscsa;
3737
unsigned char *p;
3838

39-
lscsa = vzalloc(sizeof(struct spu_lscsa));
39+
lscsa = vzalloc(sizeof(*lscsa));
4040
if (!lscsa)
4141
return -ENOMEM;
4242
csa->lscsa = lscsa;

arch/powerpc/platforms/powermac/low_i2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ static struct pmac_i2c_host_kw *__init kw_i2c_host_init(struct device_node *np)
492492
const u32 *psteps, *prate, *addrp;
493493
u32 steps;
494494

495-
host = kzalloc(sizeof(struct pmac_i2c_host_kw), GFP_KERNEL);
495+
host = kzalloc(sizeof(*host), GFP_KERNEL);
496496
if (host == NULL) {
497497
printk(KERN_ERR "low_i2c: Can't allocate host for %pOF\n",
498498
np);

arch/powerpc/platforms/powermac/pfunc_core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ static int pmf_add_function_prop(struct pmf_device *dev, void *driverdata,
643643

644644
while (length >= 12) {
645645
/* Allocate a structure */
646-
func = kzalloc(sizeof(struct pmf_function), GFP_KERNEL);
646+
func = kzalloc(sizeof(*func), GFP_KERNEL);
647647
if (func == NULL)
648648
goto bail;
649649
kref_init(&func->ref);
@@ -719,7 +719,7 @@ int pmf_register_driver(struct device_node *np,
719719
return -EBUSY;
720720
}
721721

722-
dev = kzalloc(sizeof(struct pmf_device), GFP_KERNEL);
722+
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
723723
if (dev == NULL) {
724724
DBG("pmf: no memory !\n");
725725
return -ENOMEM;

arch/powerpc/platforms/powernv/opal-flash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,12 @@ static int alloc_image_buf(char *buffer, size_t count)
418418
void *addr;
419419
int size;
420420

421-
if (count < sizeof(struct image_header_t)) {
421+
if (count < sizeof(image_header)) {
422422
pr_warn("FLASH: Invalid candidate image\n");
423423
return -EINVAL;
424424
}
425425

426-
memcpy(&image_header, (void *)buffer, sizeof(struct image_header_t));
426+
memcpy(&image_header, (void *)buffer, sizeof(image_header));
427427
image_data.size = be32_to_cpu(image_header.size);
428428
pr_debug("FLASH: Candidate image size = %u\n", image_data.size);
429429

arch/powerpc/platforms/powernv/opal-hmi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ static int opal_handle_hmi_event(struct notifier_block *nb,
314314
pr_err("HMI: out of memory, Opal message event not handled\n");
315315
return -ENOMEM;
316316
}
317-
memcpy(&msg_node->hmi_evt, hmi_evt, sizeof(struct OpalHMIEvent));
317+
memcpy(&msg_node->hmi_evt, hmi_evt, sizeof(*hmi_evt));
318318

319319
spin_lock_irqsave(&opal_hmi_evt_lock, flags);
320320
list_add(&msg_node->list, &opal_hmi_evt_list);

arch/powerpc/platforms/powernv/opal-imc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ static int imc_get_mem_addr_nest(struct device_node *node,
110110
if (nr_chips <= 0)
111111
return -ENODEV;
112112

113-
base_addr_arr = kcalloc(nr_chips, sizeof(u64), GFP_KERNEL);
113+
base_addr_arr = kcalloc(nr_chips, sizeof(*base_addr_arr), GFP_KERNEL);
114114
if (!base_addr_arr)
115115
return -ENOMEM;
116116

117-
chipid_arr = kcalloc(nr_chips, sizeof(u32), GFP_KERNEL);
117+
chipid_arr = kcalloc(nr_chips, sizeof(*chipid_arr), GFP_KERNEL);
118118
if (!chipid_arr)
119119
return -ENOMEM;
120120

@@ -125,8 +125,8 @@ static int imc_get_mem_addr_nest(struct device_node *node,
125125
nr_chips))
126126
goto error;
127127

128-
pmu_ptr->mem_info = kcalloc(nr_chips, sizeof(struct imc_mem_info),
129-
GFP_KERNEL);
128+
pmu_ptr->mem_info = kcalloc(nr_chips, sizeof(*pmu_ptr->mem_info),
129+
GFP_KERNEL);
130130
if (!pmu_ptr->mem_info)
131131
goto error;
132132

@@ -161,7 +161,7 @@ static int imc_pmu_create(struct device_node *parent, int pmu_index, int domain)
161161
u32 offset;
162162

163163
/* memory for pmu */
164-
pmu_ptr = kzalloc(sizeof(struct imc_pmu), GFP_KERNEL);
164+
pmu_ptr = kzalloc(sizeof(*pmu_ptr), GFP_KERNEL);
165165
if (!pmu_ptr)
166166
return -ENOMEM;
167167

arch/powerpc/platforms/powernv/opal-memory-errors.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static int opal_memory_err_event(struct notifier_block *nb,
112112
"handled\n");
113113
return -ENOMEM;
114114
}
115-
memcpy(&msg_node->msg, msg, sizeof(struct opal_msg));
115+
memcpy(&msg_node->msg, msg, sizeof(msg_node->msg));
116116

117117
spin_lock_irqsave(&opal_mem_err_lock, flags);
118118
list_add(&msg_node->list, &opal_memory_err_list);

arch/powerpc/platforms/powernv/opal-psr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void __init opal_psr_init(void)
136136
return;
137137
}
138138

139-
psr_attrs = kcalloc(of_get_child_count(psr), sizeof(struct psr_attr),
139+
psr_attrs = kcalloc(of_get_child_count(psr), sizeof(*psr_attrs),
140140
GFP_KERNEL);
141141
if (!psr_attrs)
142142
return;

arch/powerpc/platforms/powernv/opal-sensor-groups.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,13 @@ void __init opal_sensor_groups_init(void)
166166
if (!nr_attrs)
167167
continue;
168168

169-
sgs[i].sgattrs = kcalloc(nr_attrs, sizeof(struct sg_attr),
169+
sgs[i].sgattrs = kcalloc(nr_attrs, sizeof(*sgs[i].sgattrs),
170170
GFP_KERNEL);
171171
if (!sgs[i].sgattrs)
172172
goto out_sgs_sgattrs;
173173

174174
sgs[i].sg.attrs = kcalloc(nr_attrs + 1,
175-
sizeof(struct attribute *),
175+
sizeof(*sgs[i].sg.attrs),
176176
GFP_KERNEL);
177177

178178
if (!sgs[i].sg.attrs) {

arch/powerpc/platforms/powernv/opal-xscom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static scom_map_t opal_scom_map(struct device_node *dev, u64 reg, u64 count)
4646
__func__, dev);
4747
return SCOM_MAP_INVALID;
4848
}
49-
m = kmalloc(sizeof(struct opal_scom_map), GFP_KERNEL);
49+
m = kmalloc(sizeof(*m), GFP_KERNEL);
5050
if (!m)
5151
return NULL;
5252
m->chip = be32_to_cpup(gcid);

arch/powerpc/platforms/powernv/pci-ioda.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3843,7 +3843,7 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,
38433843
phb_id = be64_to_cpup(prop64);
38443844
pr_debug(" PHB-ID : 0x%016llx\n", phb_id);
38453845

3846-
phb = memblock_virt_alloc(sizeof(struct pnv_phb), 0);
3846+
phb = memblock_virt_alloc(sizeof(*phb), 0);
38473847

38483848
/* Allocate PCI controller */
38493849
phb->hose = hose = pcibios_alloc_controller(np);

arch/powerpc/platforms/ps3/mm.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,7 @@ static int dma_sb_map_pages(struct ps3_dma_region *r, unsigned long phys_addr,
524524
int result;
525525
struct dma_chunk *c;
526526

527-
c = kzalloc(sizeof(struct dma_chunk), GFP_ATOMIC);
528-
527+
c = kzalloc(sizeof(*c), GFP_ATOMIC);
529528
if (!c) {
530529
result = -ENOMEM;
531530
goto fail_alloc;
@@ -570,8 +569,7 @@ static int dma_ioc0_map_pages(struct ps3_dma_region *r, unsigned long phys_addr,
570569

571570
DBG(KERN_ERR "%s: phy=%#lx, lpar%#lx, len=%#lx\n", __func__,
572571
phys_addr, ps3_mm_phys_to_lpar(phys_addr), len);
573-
c = kzalloc(sizeof(struct dma_chunk), GFP_ATOMIC);
574-
572+
c = kzalloc(sizeof(*c), GFP_ATOMIC);
575573
if (!c) {
576574
result = -ENOMEM;
577575
goto fail_alloc;

drivers/macintosh/rack-meter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ static int rackmeter_probe(struct macio_dev* mdev,
397397
}
398398

399399
/* Create and initialize our instance data */
400-
rm = kzalloc(sizeof(struct rackmeter), GFP_KERNEL);
400+
rm = kzalloc(sizeof(*rm), GFP_KERNEL);
401401
if (rm == NULL) {
402402
printk(KERN_ERR "rackmeter: failed to allocate memory !\n");
403403
rc = -ENOMEM;

0 commit comments

Comments
 (0)