Commit 6396bb22 authored by Kees Cook's avatar Kees Cook

treewide: kzalloc() -> kcalloc()

The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:

        kzalloc(a * b, gfp)

with:
        kcalloc(a * b, gfp)

as well as handling cases of:

        kzalloc(a * b * c, gfp)

with:

        kzalloc(array3_size(a, b, c), gfp)

as it's slightly less ugly than:

        kzalloc_array(array_size(a, b), c, gfp)

This does, however, attempt to ignore constant size factors like:

        kzalloc(4 * 1024, gfp)

though any constants defined via macros get caught up in the conversion.

Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.

The Coccinelle script used for this was:

// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@

(
  kzalloc(
-	(sizeof(TYPE)) * E
+	sizeof(TYPE) * E
  , ...)
|
  kzalloc(
-	(sizeof(THING)) * E
+	sizeof(THING) * E
  , ...)
)

// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@

(
  kzalloc(
-	sizeof(u8) * (COUNT)
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(__u8) * (COUNT)
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(char) * (COUNT)
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(unsigned char) * (COUNT)
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(u8) * COUNT
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(__u8) * COUNT
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(char) * COUNT
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(unsigned char) * COUNT
+	COUNT
  , ...)
)

// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@

(
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * (COUNT_ID)
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * COUNT_ID
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * (COUNT_CONST)
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * COUNT_CONST
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * (COUNT_ID)
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * COUNT_ID
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * (COUNT_CONST)
+	COUNT_CONST, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * COUNT_CONST
+	COUNT_CONST, sizeof(THING)
  , ...)
)

// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@

- kzalloc
+ kcalloc
  (
-	SIZE * COUNT
+	COUNT, SIZE
  , ...)

// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@

(
  kzalloc(
-	sizeof(TYPE) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kzalloc(
-	sizeof(TYPE) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kzalloc(
-	sizeof(TYPE) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kzalloc(
-	sizeof(TYPE) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kzalloc(
-	sizeof(THING) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kzalloc(
-	sizeof(THING) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kzalloc(
-	sizeof(THING) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kzalloc(
-	sizeof(THING) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
)

// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@

(
  kzalloc(
-	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  kzalloc(
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  kzalloc(
-	sizeof(THING1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  kzalloc(
-	sizeof(THING1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  kzalloc(
-	sizeof(TYPE1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
|
  kzalloc(
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
)

// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@

(
  kzalloc(
-	(COUNT) * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	COUNT * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	COUNT * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	(COUNT) * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	COUNT * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	(COUNT) * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	(COUNT) * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	COUNT * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
)

// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@

(
  kzalloc(C1 * C2 * C3, ...)
|
  kzalloc(
-	(E1) * E2 * E3
+	array3_size(E1, E2, E3)
  , ...)
|
  kzalloc(
-	(E1) * (E2) * E3
+	array3_size(E1, E2, E3)
  , ...)
|
  kzalloc(
-	(E1) * (E2) * (E3)
+	array3_size(E1, E2, E3)
  , ...)
|
  kzalloc(
-	E1 * E2 * E3
+	array3_size(E1, E2, E3)
  , ...)
)

// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@

(
  kzalloc(sizeof(THING) * C2, ...)
|
  kzalloc(sizeof(TYPE) * C2, ...)
|
  kzalloc(C1 * C2 * C3, ...)
|
  kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * (E2)
+	E2, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * E2
+	E2, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * (E2)
+	E2, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * E2
+	E2, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	(E1) * E2
+	E1, E2
  , ...)
|
- kzalloc
+ kcalloc
  (
-	(E1) * (E2)
+	E1, E2
  , ...)
|
- kzalloc
+ kcalloc
  (
-	E1 * E2
+	E1, E2
  , ...)
)
Signed-off-by: 's avatarKees Cook <keescook@chromium.org>
parent 6da2ec56
...@@ -252,7 +252,7 @@ int __init dc21285_setup(int nr, struct pci_sys_data *sys) ...@@ -252,7 +252,7 @@ int __init dc21285_setup(int nr, struct pci_sys_data *sys)
if (nr || !footbridge_cfn_mode()) if (nr || !footbridge_cfn_mode())
return 0; return 0;
res = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL); res = kcalloc(2, sizeof(struct resource), GFP_KERNEL);
if (!res) { if (!res) {
printk("out of memory for root bus resources"); printk("out of memory for root bus resources");
return 0; return 0;
......
...@@ -421,7 +421,7 @@ int ixp4xx_setup(int nr, struct pci_sys_data *sys) ...@@ -421,7 +421,7 @@ int ixp4xx_setup(int nr, struct pci_sys_data *sys)
if (nr >= 1) if (nr >= 1)
return 0; return 0;
res = kzalloc(sizeof(*res) * 2, GFP_KERNEL); res = kcalloc(2, sizeof(*res), GFP_KERNEL);
if (res == NULL) { if (res == NULL) {
/* /*
* If we're out of memory this early, something is wrong, * If we're out of memory this early, something is wrong,
......
...@@ -389,7 +389,7 @@ static void omap_mcbsp_register_board_cfg(struct resource *res, int res_count, ...@@ -389,7 +389,7 @@ static void omap_mcbsp_register_board_cfg(struct resource *res, int res_count,
{ {
int i; int i;
omap_mcbsp_devices = kzalloc(size * sizeof(struct platform_device *), omap_mcbsp_devices = kcalloc(size, sizeof(struct platform_device *),
GFP_KERNEL); GFP_KERNEL);
if (!omap_mcbsp_devices) { if (!omap_mcbsp_devices) {
printk(KERN_ERR "Could not register McBSP devices\n"); printk(KERN_ERR "Could not register McBSP devices\n");
......
...@@ -35,7 +35,7 @@ static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c, ...@@ -35,7 +35,7 @@ static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c,
{ {
char *hc_name; char *hc_name;
hc_name = kzalloc(sizeof(char) * (HSMMC_NAME_LEN + 1), GFP_KERNEL); hc_name = kzalloc(HSMMC_NAME_LEN + 1, GFP_KERNEL);
if (!hc_name) { if (!hc_name) {
kfree(hc_name); kfree(hc_name);
return -ENOMEM; return -ENOMEM;
......
...@@ -155,7 +155,7 @@ static int omap_device_build_from_dt(struct platform_device *pdev) ...@@ -155,7 +155,7 @@ static int omap_device_build_from_dt(struct platform_device *pdev)
if (!omap_hwmod_parse_module_range(NULL, node, &res)) if (!omap_hwmod_parse_module_range(NULL, node, &res))
return -ENODEV; return -ENODEV;
hwmods = kzalloc(sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL); hwmods = kcalloc(oh_cnt, sizeof(struct omap_hwmod *), GFP_KERNEL);
if (!hwmods) { if (!hwmods) {
ret = -ENOMEM; ret = -ENOMEM;
goto odbfd_exit; goto odbfd_exit;
...@@ -405,7 +405,7 @@ omap_device_copy_resources(struct omap_hwmod *oh, ...@@ -405,7 +405,7 @@ omap_device_copy_resources(struct omap_hwmod *oh,
goto error; goto error;
} }
res = kzalloc(sizeof(*res) * 2, GFP_KERNEL); res = kcalloc(2, sizeof(*res), GFP_KERNEL);
if (!res) if (!res)
return -ENOMEM; return -ENOMEM;
......
...@@ -285,10 +285,11 @@ int omap_prcm_register_chain_handler(struct omap_prcm_irq_setup *irq_setup) ...@@ -285,10 +285,11 @@ int omap_prcm_register_chain_handler(struct omap_prcm_irq_setup *irq_setup)
prcm_irq_setup = irq_setup; prcm_irq_setup = irq_setup;
prcm_irq_chips = kzalloc(sizeof(void *) * nr_regs, GFP_KERNEL); prcm_irq_chips = kcalloc(nr_regs, sizeof(void *), GFP_KERNEL);
prcm_irq_setup->saved_mask = kzalloc(sizeof(u32) * nr_regs, GFP_KERNEL); prcm_irq_setup->saved_mask = kcalloc(nr_regs, sizeof(u32),
prcm_irq_setup->priority_mask = kzalloc(sizeof(u32) * nr_regs, GFP_KERNEL);
GFP_KERNEL); prcm_irq_setup->priority_mask = kcalloc(nr_regs, sizeof(u32),
GFP_KERNEL);
if (!prcm_irq_chips || !prcm_irq_setup->saved_mask || if (!prcm_irq_chips || !prcm_irq_setup->saved_mask ||
!prcm_irq_setup->priority_mask) !prcm_irq_setup->priority_mask)
......
...@@ -403,7 +403,7 @@ static int ve_spc_populate_opps(uint32_t cluster) ...@@ -403,7 +403,7 @@ static int ve_spc_populate_opps(uint32_t cluster)
uint32_t data = 0, off, ret, idx; uint32_t data = 0, off, ret, idx;
struct ve_spc_opp *opps; struct ve_spc_opp *opps;
opps = kzalloc(sizeof(*opps) * MAX_OPPS, GFP_KERNEL); opps = kcalloc(MAX_OPPS, sizeof(*opps), GFP_KERNEL);
if (!opps) if (!opps)
return -ENOMEM; return -ENOMEM;
......
...@@ -2162,8 +2162,8 @@ arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, u64 size) ...@@ -2162,8 +2162,8 @@ arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, u64 size)
goto err; goto err;
mapping->bitmap_size = bitmap_size; mapping->bitmap_size = bitmap_size;
mapping->bitmaps = kzalloc(extensions * sizeof(unsigned long *), mapping->bitmaps = kcalloc(extensions, sizeof(unsigned long *),
GFP_KERNEL); GFP_KERNEL);
if (!mapping->bitmaps) if (!mapping->bitmaps)
goto err2; goto err2;
......
...@@ -234,8 +234,8 @@ static void __init register_insn_emulation_sysctl(void) ...@@ -234,8 +234,8 @@ static void __init register_insn_emulation_sysctl(void)
struct insn_emulation *insn; struct insn_emulation *insn;
struct ctl_table *insns_sysctl, *sysctl; struct ctl_table *insns_sysctl, *sysctl;
insns_sysctl = kzalloc(sizeof(*sysctl) * (nr_insn_emulated + 1), insns_sysctl = kcalloc(nr_insn_emulated + 1, sizeof(*sysctl),
GFP_KERNEL); GFP_KERNEL);
raw_spin_lock_irqsave(&insn_emulation_lock, flags); raw_spin_lock_irqsave(&insn_emulation_lock, flags);
list_for_each_entry(insn, &insn_emulation, node) { list_for_each_entry(insn, &insn_emulation, node) {
......
...@@ -263,7 +263,7 @@ static int asids_init(void) ...@@ -263,7 +263,7 @@ static int asids_init(void)
*/ */
WARN_ON(NUM_USER_ASIDS - 1 <= num_possible_cpus()); WARN_ON(NUM_USER_ASIDS - 1 <= num_possible_cpus());
atomic64_set(&asid_generation, ASID_FIRST_VERSION); atomic64_set(&asid_generation, ASID_FIRST_VERSION);
asid_map = kzalloc(BITS_TO_LONGS(NUM_USER_ASIDS) * sizeof(*asid_map), asid_map = kcalloc(BITS_TO_LONGS(NUM_USER_ASIDS), sizeof(*asid_map),
GFP_KERNEL); GFP_KERNEL);
if (!asid_map) if (!asid_map)
panic("Failed to allocate bitmap for %lu ASIDs\n", panic("Failed to allocate bitmap for %lu ASIDs\n",
......
...@@ -85,7 +85,7 @@ static int __init topology_init(void) ...@@ -85,7 +85,7 @@ static int __init topology_init(void)
} }
#endif #endif
sysfs_cpus = kzalloc(sizeof(struct ia64_cpu) * NR_CPUS, GFP_KERNEL); sysfs_cpus = kcalloc(NR_CPUS, sizeof(struct ia64_cpu), GFP_KERNEL);
if (!sysfs_cpus) if (!sysfs_cpus)
panic("kzalloc in topology_init failed - NR_CPUS too big?"); panic("kzalloc in topology_init failed - NR_CPUS too big?");
...@@ -319,8 +319,8 @@ static int cpu_cache_sysfs_init(unsigned int cpu) ...@@ -319,8 +319,8 @@ static int cpu_cache_sysfs_init(unsigned int cpu)
return -1; return -1;
} }
this_cache=kzalloc(sizeof(struct cache_info)*unique_caches, this_cache=kcalloc(unique_caches, sizeof(struct cache_info),
GFP_KERNEL); GFP_KERNEL);
if (this_cache == NULL) if (this_cache == NULL)
return -ENOMEM; return -ENOMEM;
......
...@@ -132,7 +132,7 @@ static s64 sn_device_fixup_war(u64 nasid, u64 widget, int device, ...@@ -132,7 +132,7 @@ static s64 sn_device_fixup_war(u64 nasid, u64 widget, int device,
printk_once(KERN_WARNING printk_once(KERN_WARNING
"PROM version < 4.50 -- implementing old PROM flush WAR\n"); "PROM version < 4.50 -- implementing old PROM flush WAR\n");
war_list = kzalloc(DEV_PER_WIDGET * sizeof(*war_list), GFP_KERNEL); war_list = kcalloc(DEV_PER_WIDGET, sizeof(*war_list), GFP_KERNEL);
BUG_ON(!war_list); BUG_ON(!war_list);
SAL_CALL_NOLOCK(isrv, SN_SAL_IOIF_GET_WIDGET_DMAFLUSH_LIST, SAL_CALL_NOLOCK(isrv, SN_SAL_IOIF_GET_WIDGET_DMAFLUSH_LIST,
......
...@@ -184,7 +184,7 @@ pcibr_bus_fixup(struct pcibus_bussoft *prom_bussoft, struct pci_controller *cont ...@@ -184,7 +184,7 @@ pcibr_bus_fixup(struct pcibus_bussoft *prom_bussoft, struct pci_controller *cont
/* Setup the PMU ATE map */ /* Setup the PMU ATE map */
soft->pbi_int_ate_resource.lowest_free_index = 0; soft->pbi_int_ate_resource.lowest_free_index = 0;
soft->pbi_int_ate_resource.ate = soft->pbi_int_ate_resource.ate =
kzalloc(soft->pbi_int_ate_size * sizeof(u64), GFP_KERNEL); kcalloc(soft->pbi_int_ate_size, sizeof(u64), GFP_KERNEL);
if (!soft->pbi_int_ate_resource.ate) { if (!soft->pbi_int_ate_resource.ate) {
kfree(soft); kfree(soft);
......
...@@ -985,7 +985,7 @@ static int __init alchemy_clk_setup_imux(int ctype) ...@@ -985,7 +985,7 @@ static int __init alchemy_clk_setup_imux(int ctype)
return -ENODEV; return -ENODEV;
} }
a = kzalloc((sizeof(*a)) * 6, GFP_KERNEL); a = kcalloc(6, sizeof(*a), GFP_KERNEL);
if (!a) if (!a)
return -ENOMEM; return -ENOMEM;
......
...@@ -1050,7 +1050,7 @@ static int __init dbdma_setup(unsigned int irq, dbdev_tab_t *idtable) ...@@ -1050,7 +1050,7 @@ static int __init dbdma_setup(unsigned int irq, dbdev_tab_t *idtable)
{ {
int ret; int ret;
dbdev_tab = kzalloc(sizeof(dbdev_tab_t) * DBDEV_TAB_SIZE, GFP_KERNEL); dbdev_tab = kcalloc(DBDEV_TAB_SIZE, sizeof(dbdev_tab_t), GFP_KERNEL);
if (!dbdev_tab) if (!dbdev_tab)
return -ENOMEM; return -ENOMEM;
......
...@@ -115,7 +115,7 @@ static void __init alchemy_setup_uarts(int ctype) ...@@ -115,7 +115,7 @@ static void __init alchemy_setup_uarts(int ctype)
uartclk = clk_get_rate(clk); uartclk = clk_get_rate(clk);
clk_put(clk); clk_put(clk);
ports = kzalloc(s * (c + 1), GFP_KERNEL); ports = kcalloc(s, (c + 1), GFP_KERNEL);
if (!ports) { if (!ports) {
printk(KERN_INFO "Alchemy: no memory for UART data\n"); printk(KERN_INFO "Alchemy: no memory for UART data\n");
return; return;
...@@ -198,7 +198,7 @@ static unsigned long alchemy_ehci_data[][2] __initdata = { ...@@ -198,7 +198,7 @@ static unsigned long alchemy_ehci_data[][2] __initdata = {
static int __init _new_usbres(struct resource **r, struct platform_device **d) static int __init _new_usbres(struct resource **r, struct platform_device **d)
{ {
*r = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL); *r = kcalloc(2, sizeof(struct resource), GFP_KERNEL);
if (!*r) if (!*r)
return -ENOMEM; return -ENOMEM;
*d = kzalloc(sizeof(struct platform_device), GFP_KERNEL); *d = kzalloc(sizeof(struct platform_device), GFP_KERNEL);
......
...@@ -103,7 +103,7 @@ int __init db1x_register_pcmcia_socket(phys_addr_t pcmcia_attr_start, ...@@ -103,7 +103,7 @@ int __init db1x_register_pcmcia_socket(phys_addr_t pcmcia_attr_start,
if (stschg_irq) if (stschg_irq)
cnt++; cnt++;
sr = kzalloc(sizeof(struct resource) * cnt, GFP_KERNEL); sr = kcalloc(cnt, sizeof(struct resource), GFP_KERNEL);
if (!sr) if (!sr)
return -ENOMEM; return -ENOMEM;
...@@ -178,7 +178,7 @@ int __init db1x_register_norflash(unsigned long size, int width, ...@@ -178,7 +178,7 @@ int __init db1x_register_norflash(unsigned long size, int width,
return -EINVAL; return -EINVAL;
ret = -ENOMEM; ret = -ENOMEM;
parts = kzalloc(sizeof(struct mtd_partition) * 5, GFP_KERNEL); parts = kcalloc(5, sizeof(struct mtd_partition), GFP_KERNEL);
if (!parts) if (!parts)
goto out; goto out;
......
...@@ -94,7 +94,7 @@ static int __init bmips_init_dma_ranges(void) ...@@ -94,7 +94,7 @@ static int __init bmips_init_dma_ranges(void)
goto out_bad; goto out_bad;
/* add a dummy (zero) entry at the end as a sentinel */ /* add a dummy (zero) entry at the end as a sentinel */
bmips_dma_ranges = kzalloc(sizeof(struct bmips_dma_range) * (len + 1), bmips_dma_ranges = kcalloc(len + 1, sizeof(struct bmips_dma_range),
GFP_KERNEL); GFP_KERNEL);
if (!bmips_dma_ranges) if (!bmips_dma_ranges)
goto out_bad; goto out_bad;
......
...@@ -219,7 +219,7 @@ static int __init rbtx4939_led_probe(struct platform_device *pdev) ...@@ -219,7 +219,7 @@ static int __init rbtx4939_led_probe(struct platform_device *pdev)
"nand-disk", "nand-disk",
}; };
leds_data = kzalloc(sizeof(*leds_data) * RBTX4939_MAX_7SEGLEDS, leds_data = kcalloc(RBTX4939_MAX_7SEGLEDS, sizeof(*leds_data),
GFP_KERNEL); GFP_KERNEL);
if (!leds_data) if (!leds_data)
return -ENOMEM; return -ENOMEM;
......
...@@ -791,7 +791,7 @@ static int __init vdso_init(void) ...@@ -791,7 +791,7 @@ static int __init vdso_init(void)
#ifdef CONFIG_VDSO32 #ifdef CONFIG_VDSO32
/* Make sure pages are in the correct state */ /* Make sure pages are in the correct state */
vdso32_pagelist = kzalloc(sizeof(struct page *) * (vdso32_pages + 2), vdso32_pagelist = kcalloc(vdso32_pages + 2, sizeof(struct page *),
GFP_KERNEL); GFP_KERNEL);
BUG_ON(vdso32_pagelist == NULL); BUG_ON(vdso32_pagelist == NULL);
for (i = 0; i < vdso32_pages; i++) { for (i = 0; i < vdso32_pages; i++) {
...@@ -805,7 +805,7 @@ static int __init vdso_init(void) ...@@ -805,7 +805,7 @@ static int __init vdso_init(void)
#endif #endif
#ifdef CONFIG_PPC64 #ifdef CONFIG_PPC64
vdso64_pagelist = kzalloc(sizeof(struct page *) * (vdso64_pages + 2), vdso64_pagelist = kcalloc(vdso64_pages + 2, sizeof(struct page *),
GFP_KERNEL); GFP_KERNEL);
BUG_ON(vdso64_pagelist == NULL); BUG_ON(vdso64_pagelist == NULL);
for (i = 0; i < vdso64_pages; i++) { for (i = 0; i < vdso64_pages; i++) {
......
...@@ -1316,7 +1316,7 @@ int numa_update_cpu_topology(bool cpus_locked) ...@@ -1316,7 +1316,7 @@ int numa_update_cpu_topology(bool cpus_locked)
if (!weight) if (!weight)
return 0; return 0;
updates = kzalloc(weight * (sizeof(*updates)), GFP_KERNEL); updates = kcalloc(weight, sizeof(*updates), GFP_KERNEL);
if (!updates) if (!updates)
return 0; return 0;
......
...@@ -566,7 +566,7 @@ void bpf_jit_compile(struct bpf_prog *fp) ...@@ -566,7 +566,7 @@ void bpf_jit_compile(struct bpf_prog *fp)
if (!bpf_jit_enable) if (!bpf_jit_enable)
return; return;
addrs = kzalloc((flen+1) * sizeof(*addrs), GFP_KERNEL); addrs = kcalloc(flen + 1, sizeof(*addrs), GFP_KERNEL);
if (addrs == NULL) if (addrs == NULL)
return; return;
......
...@@ -949,7 +949,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp) ...@@ -949,7 +949,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
goto skip_init_ctx; goto skip_init_ctx;
} }
addrs = kzalloc((flen+1) * sizeof(*addrs), GFP_KERNEL); addrs = kcalloc(flen + 1, sizeof(*addrs), GFP_KERNEL);
if (addrs == NULL) { if (addrs == NULL) {
fp = org_fp; fp = org_fp;
goto out_addrs; goto out_addrs;
......
...@@ -210,8 +210,8 @@ int start_spu_profiling_cycles(unsigned int cycles_reset) ...@@ -210,8 +210,8 @@ int start_spu_profiling_cycles(unsigned int cycles_reset)
timer.function = profile_spus; timer.function = profile_spus;
/* Allocate arrays for collecting SPU PC samples */ /* Allocate arrays for collecting SPU PC samples */
samples = kzalloc(SPUS_PER_NODE * samples = kcalloc(SPUS_PER_NODE * TRACE_ARRAY_SIZE, sizeof(u32),
TRACE_ARRAY_SIZE * sizeof(u32), GFP_KERNEL); GFP_KERNEL);
if (!samples) if (!samples)
return -ENOMEM; return -ENOMEM;
......
...@@ -1449,7 +1449,7 @@ static int __init ppc4xx_pciex_check_core_init(struct device_node *np) ...@@ -1449,7 +1449,7 @@ static int __init ppc4xx_pciex_check_core_init(struct device_node *np)
count = ppc4xx_pciex_hwops->core_init(np); count = ppc4xx_pciex_hwops->core_init(np);
if (count > 0) { if (count > 0) {
ppc4xx_pciex_ports = ppc4xx_pciex_ports =
kzalloc(count * sizeof(struct ppc4xx_pciex_port), kcalloc(count, sizeof(struct ppc4xx_pciex_port),
GFP_KERNEL); GFP_KERNEL);
if (ppc4xx_pciex_ports) { if (ppc4xx_pciex_ports) {
ppc4xx_pciex_port_count = count; ppc4xx_pciex_port_count = count;
......
...@@ -198,21 +198,21 @@ void __init opal_sys_param_init(void) ...@@ -198,21 +198,21 @@ void __init opal_sys_param_init(void)
goto out_param_buf; goto out_param_buf;
} }
id = kzalloc(sizeof(*id) * count, GFP_KERNEL); id = kcalloc(count, sizeof(*id), GFP_KERNEL);
if (!id) { if (!id) {
pr_err("SYSPARAM: Failed to allocate memory to read parameter " pr_err("SYSPARAM: Failed to allocate memory to read parameter "
"id\n"); "id\n");
goto out_param_buf; goto out_param_buf;
} }
size = kzalloc(sizeof(*size) * count, GFP_KERNEL); size = kcalloc(count, sizeof(*size), GFP_KERNEL);
if (!size) { if (!size) {
pr_err("SYSPARAM: Failed to allocate memory to read parameter " pr_err("SYSPARAM: Failed to allocate memory to read parameter "
"size\n"); "size\n");
goto out_free_id; goto out_free_id;
} }
perm = kzalloc(sizeof(*perm) * count, GFP_KERNEL); perm = kcalloc(count, sizeof(*perm), GFP_KERNEL);
if (!perm) { if (!perm) {
pr_err("SYSPARAM: Failed to allocate memory to read supported " pr_err("SYSPARAM: Failed to allocate memory to read supported "