diff options
author | Kees Cook <keescook@chromium.org> | 2018-06-12 17:27:37 -0400 |
---|---|---|
committer | Kees Cook <keescook@chromium.org> | 2018-06-12 19:19:22 -0400 |
commit | fad953ce0b22cfd352a9a90b070c34b8791e6868 (patch) | |
tree | c1806e803783afe2e82cb205925b6725d67fa76a | |
parent | 42bc47b35320e0e587a88e437e18f80f9c5bcbb2 (diff) |
treewide: Use array_size() in vzalloc()
The vzalloc() function has no 2-factor argument form, so multiplication
factors need to be wrapped in array_size(). This patch replaces cases of:
vzalloc(a * b)
with:
vzalloc(array_size(a, b))
as well as handling cases of:
vzalloc(a * b * c)
with:
vzalloc(array3_size(a, b, c))
This does, however, attempt to ignore constant size factors like:
vzalloc(4 * 1024)
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;
@@
(
vzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
vzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
vzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
vzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
vzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
vzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
vzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
vzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
vzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
vzalloc(
- 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;
@@
(
vzalloc(
- sizeof(TYPE) * (COUNT_ID)
+ array_size(COUNT_ID, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(TYPE) * COUNT_ID
+ array_size(COUNT_ID, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(TYPE) * (COUNT_CONST)
+ array_size(COUNT_CONST, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(TYPE) * COUNT_CONST
+ array_size(COUNT_CONST, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(THING) * (COUNT_ID)
+ array_size(COUNT_ID, sizeof(THING))
, ...)
|
vzalloc(
- sizeof(THING) * COUNT_ID
+ array_size(COUNT_ID, sizeof(THING))
, ...)
|
vzalloc(
- sizeof(THING) * (COUNT_CONST)
+ array_size(COUNT_CONST, sizeof(THING))
, ...)
|
vzalloc(
- sizeof(THING) * COUNT_CONST
+ array_size(COUNT_CONST, sizeof(THING))
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
vzalloc(
- SIZE * COUNT
+ array_size(COUNT, SIZE)
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
vzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
vzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
vzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
vzalloc(
- 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;
@@
(
vzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
vzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
vzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
vzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
vzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
vzalloc(
- 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;
@@
(
vzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- 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;
@@
(
vzalloc(C1 * C2 * C3, ...)
|
vzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants.
@@
expression E1, E2;
constant C1, C2;
@@
(
vzalloc(C1 * C2, ...)
|
vzalloc(
- E1 * E2
+ array_size(E1, E2)
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
64 files changed, 164 insertions, 118 deletions
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index cb6d2313b19f..746645cd2ba7 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c | |||
@@ -3548,7 +3548,7 @@ static void kvmppc_core_free_memslot_hv(struct kvm_memory_slot *free, | |||
3548 | static int kvmppc_core_create_memslot_hv(struct kvm_memory_slot *slot, | 3548 | static int kvmppc_core_create_memslot_hv(struct kvm_memory_slot *slot, |
3549 | unsigned long npages) | 3549 | unsigned long npages) |
3550 | { | 3550 | { |
3551 | slot->arch.rmap = vzalloc(npages * sizeof(*slot->arch.rmap)); | 3551 | slot->arch.rmap = vzalloc(array_size(npages, sizeof(*slot->arch.rmap))); |
3552 | if (!slot->arch.rmap) | 3552 | if (!slot->arch.rmap) |
3553 | return -ENOMEM; | 3553 | return -ENOMEM; |
3554 | 3554 | ||
diff --git a/arch/powerpc/mm/mmu_context_iommu.c b/arch/powerpc/mm/mmu_context_iommu.c index 4c615fcb0cf0..abb43646927a 100644 --- a/arch/powerpc/mm/mmu_context_iommu.c +++ b/arch/powerpc/mm/mmu_context_iommu.c | |||
@@ -159,7 +159,7 @@ long mm_iommu_get(struct mm_struct *mm, unsigned long ua, unsigned long entries, | |||
159 | goto unlock_exit; | 159 | goto unlock_exit; |
160 | } | 160 | } |
161 | 161 | ||
162 | mem->hpas = vzalloc(entries * sizeof(mem->hpas[0])); | 162 | mem->hpas = vzalloc(array_size(entries, sizeof(mem->hpas[0]))); |
163 | if (!mem->hpas) { | 163 | if (!mem->hpas) { |
164 | kfree(mem); | 164 | kfree(mem); |
165 | ret = -ENOMEM; | 165 | ret = -ENOMEM; |
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 66fc27b92c59..812cada68e0f 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c | |||
@@ -785,7 +785,8 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid, | |||
785 | return -EINVAL; | 785 | return -EINVAL; |
786 | 786 | ||
787 | r = -ENOMEM; | 787 | r = -ENOMEM; |
788 | cpuid_entries = vzalloc(sizeof(struct kvm_cpuid_entry2) * cpuid->nent); | 788 | cpuid_entries = vzalloc(array_size(sizeof(struct kvm_cpuid_entry2), |
789 | cpuid->nent)); | ||
789 | if (!cpuid_entries) | 790 | if (!cpuid_entries) |
790 | goto out; | 791 | goto out; |
791 | 792 | ||
diff --git a/block/partitions/check.c b/block/partitions/check.c index 720145c49066..ffe408fead0c 100644 --- a/block/partitions/check.c +++ b/block/partitions/check.c | |||
@@ -122,7 +122,7 @@ static struct parsed_partitions *allocate_partitions(struct gendisk *hd) | |||
122 | return NULL; | 122 | return NULL; |
123 | 123 | ||
124 | nr = disk_max_parts(hd); | 124 | nr = disk_max_parts(hd); |
125 | state->parts = vzalloc(nr * sizeof(state->parts[0])); | 125 | state->parts = vzalloc(array_size(nr, sizeof(state->parts[0]))); |
126 | if (!state->parts) { | 126 | if (!state->parts) { |
127 | kfree(state); | 127 | kfree(state); |
128 | return NULL; | 128 | return NULL; |
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index da51293e7c03..7436b2d27fa3 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c | |||
@@ -898,7 +898,7 @@ static bool zram_meta_alloc(struct zram *zram, u64 disksize) | |||
898 | size_t num_pages; | 898 | size_t num_pages; |
899 | 899 | ||
900 | num_pages = disksize >> PAGE_SHIFT; | 900 | num_pages = disksize >> PAGE_SHIFT; |
901 | zram->table = vzalloc(num_pages * sizeof(*zram->table)); | 901 | zram->table = vzalloc(array_size(num_pages, sizeof(*zram->table))); |
902 | if (!zram->table) | 902 | if (!zram->table) |
903 | return false; | 903 | return false; |
904 | 904 | ||
diff --git a/drivers/char/raw.c b/drivers/char/raw.c index 293167c6e254..fd6eec8085b4 100644 --- a/drivers/char/raw.c +++ b/drivers/char/raw.c | |||
@@ -321,7 +321,8 @@ static int __init raw_init(void) | |||
321 | max_raw_minors = MAX_RAW_MINORS; | 321 | max_raw_minors = MAX_RAW_MINORS; |
322 | } | 322 | } |
323 | 323 | ||
324 | raw_devices = vzalloc(sizeof(struct raw_device_data) * max_raw_minors); | 324 | raw_devices = vzalloc(array_size(max_raw_minors, |
325 | sizeof(struct raw_device_data))); | ||
325 | if (!raw_devices) { | 326 | if (!raw_devices) { |
326 | printk(KERN_ERR "Not enough memory for raw device structures\n"); | 327 | printk(KERN_ERR "Not enough memory for raw device structures\n"); |
327 | ret = -ENOMEM; | 328 | ret = -ENOMEM; |
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index 08960a55eb27..b6575408f279 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c | |||
@@ -2339,7 +2339,7 @@ hwp_cpu_matched: | |||
2339 | 2339 | ||
2340 | pr_info("Intel P-state driver initializing\n"); | 2340 | pr_info("Intel P-state driver initializing\n"); |
2341 | 2341 | ||
2342 | all_cpu_data = vzalloc(sizeof(void *) * num_possible_cpus()); | 2342 | all_cpu_data = vzalloc(array_size(sizeof(void *), num_possible_cpus())); |
2343 | if (!all_cpu_data) | 2343 | if (!all_cpu_data) |
2344 | return -ENOMEM; | 2344 | return -ENOMEM; |
2345 | 2345 | ||
diff --git a/drivers/dma/mic_x100_dma.c b/drivers/dma/mic_x100_dma.c index 94d7bd7d2880..68dd79783b54 100644 --- a/drivers/dma/mic_x100_dma.c +++ b/drivers/dma/mic_x100_dma.c | |||
@@ -385,7 +385,8 @@ static int mic_dma_alloc_desc_ring(struct mic_dma_chan *ch) | |||
385 | if (dma_mapping_error(dev, ch->desc_ring_micpa)) | 385 | if (dma_mapping_error(dev, ch->desc_ring_micpa)) |
386 | goto map_error; | 386 | goto map_error; |
387 | 387 | ||
388 | ch->tx_array = vzalloc(MIC_DMA_DESC_RX_SIZE * sizeof(*ch->tx_array)); | 388 | ch->tx_array = vzalloc(array_size(MIC_DMA_DESC_RX_SIZE, |
389 | sizeof(*ch->tx_array))); | ||
389 | if (!ch->tx_array) | 390 | if (!ch->tx_array) |
390 | goto tx_error; | 391 | goto tx_error; |
391 | return 0; | 392 | return 0; |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c index 17d6b9fb6d77..dd11b7313ca0 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c | |||
@@ -369,7 +369,8 @@ int amdgpu_gart_init(struct amdgpu_device *adev) | |||
369 | 369 | ||
370 | #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS | 370 | #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS |
371 | /* Allocate pages table */ | 371 | /* Allocate pages table */ |
372 | adev->gart.pages = vzalloc(sizeof(void *) * adev->gart.num_cpu_pages); | 372 | adev->gart.pages = vzalloc(array_size(sizeof(void *), |
373 | adev->gart.num_cpu_pages)); | ||
373 | if (adev->gart.pages == NULL) | 374 | if (adev->gart.pages == NULL) |
374 | return -ENOMEM; | 375 | return -ENOMEM; |
375 | #endif | 376 | #endif |
diff --git a/drivers/gpu/drm/drm_hashtab.c b/drivers/gpu/drm/drm_hashtab.c index dae18e58e79b..c92b00d42ece 100644 --- a/drivers/gpu/drm/drm_hashtab.c +++ b/drivers/gpu/drm/drm_hashtab.c | |||
@@ -47,7 +47,7 @@ int drm_ht_create(struct drm_open_hash *ht, unsigned int order) | |||
47 | if (size <= PAGE_SIZE / sizeof(*ht->table)) | 47 | if (size <= PAGE_SIZE / sizeof(*ht->table)) |
48 | ht->table = kcalloc(size, sizeof(*ht->table), GFP_KERNEL); | 48 | ht->table = kcalloc(size, sizeof(*ht->table), GFP_KERNEL); |
49 | else | 49 | else |
50 | ht->table = vzalloc(size*sizeof(*ht->table)); | 50 | ht->table = vzalloc(array_size(size, sizeof(*ht->table))); |
51 | if (!ht->table) { | 51 | if (!ht->table) { |
52 | DRM_ERROR("Out of memory for hash table\n"); | 52 | DRM_ERROR("Out of memory for hash table\n"); |
53 | return -ENOMEM; | 53 | return -ENOMEM; |
diff --git a/drivers/gpu/drm/i915/gvt/gtt.c b/drivers/gpu/drm/i915/gvt/gtt.c index 78e55aafc8bc..23296547da95 100644 --- a/drivers/gpu/drm/i915/gvt/gtt.c +++ b/drivers/gpu/drm/i915/gvt/gtt.c | |||
@@ -1585,8 +1585,9 @@ static struct intel_vgpu_mm *intel_vgpu_create_ggtt_mm(struct intel_vgpu *vgpu) | |||
1585 | mm->type = INTEL_GVT_MM_GGTT; | 1585 | mm->type = INTEL_GVT_MM_GGTT; |
1586 | 1586 | ||
1587 | nr_entries = gvt_ggtt_gm_sz(vgpu->gvt) >> I915_GTT_PAGE_SHIFT; | 1587 | nr_entries = gvt_ggtt_gm_sz(vgpu->gvt) >> I915_GTT_PAGE_SHIFT; |
1588 | mm->ggtt_mm.virtual_ggtt = vzalloc(nr_entries * | 1588 | mm->ggtt_mm.virtual_ggtt = |
1589 | vgpu->gvt->device_info.gtt_entry_size); | 1589 | vzalloc(array_size(nr_entries, |
1590 | vgpu->gvt->device_info.gtt_entry_size)); | ||
1590 | if (!mm->ggtt_mm.virtual_ggtt) { | 1591 | if (!mm->ggtt_mm.virtual_ggtt) { |
1591 | vgpu_free_mm(mm); | 1592 | vgpu_free_mm(mm); |
1592 | return ERR_PTR(-ENOMEM); | 1593 | return ERR_PTR(-ENOMEM); |
diff --git a/drivers/gpu/drm/i915/gvt/mmio.c b/drivers/gpu/drm/i915/gvt/mmio.c index e4960aff68bd..b31eb36fc102 100644 --- a/drivers/gpu/drm/i915/gvt/mmio.c +++ b/drivers/gpu/drm/i915/gvt/mmio.c | |||
@@ -267,7 +267,7 @@ int intel_vgpu_init_mmio(struct intel_vgpu *vgpu) | |||
267 | { | 267 | { |
268 | const struct intel_gvt_device_info *info = &vgpu->gvt->device_info; | 268 | const struct intel_gvt_device_info *info = &vgpu->gvt->device_info; |
269 | 269 | ||
270 | vgpu->mmio.vreg = vzalloc(info->mmio_size * 2); | 270 | vgpu->mmio.vreg = vzalloc(array_size(info->mmio_size, 2)); |
271 | if (!vgpu->mmio.vreg) | 271 | if (!vgpu->mmio.vreg) |
272 | return -ENOMEM; | 272 | return -ENOMEM; |
273 | 273 | ||
diff --git a/drivers/gpu/drm/radeon/radeon_gart.c b/drivers/gpu/drm/radeon/radeon_gart.c index 66149eaba78c..1cef155cc933 100644 --- a/drivers/gpu/drm/radeon/radeon_gart.c +++ b/drivers/gpu/drm/radeon/radeon_gart.c | |||
@@ -347,7 +347,8 @@ int radeon_gart_init(struct radeon_device *rdev) | |||
347 | DRM_INFO("GART: num cpu pages %u, num gpu pages %u\n", | 347 | DRM_INFO("GART: num cpu pages %u, num gpu pages %u\n", |
348 | rdev->gart.num_cpu_pages, rdev->gart.num_gpu_pages); | 348 | rdev->gart.num_cpu_pages, rdev->gart.num_gpu_pages); |
349 | /* Allocate pages table */ | 349 | /* Allocate pages table */ |
350 | rdev->gart.pages = vzalloc(sizeof(void *) * rdev->gart.num_cpu_pages); | 350 | rdev->gart.pages = vzalloc(array_size(sizeof(void *), |
351 | rdev->gart.num_cpu_pages)); | ||
351 | if (rdev->gart.pages == NULL) { | 352 | if (rdev->gart.pages == NULL) { |
352 | radeon_gart_fini(rdev); | 353 | radeon_gart_fini(rdev); |
353 | return -ENOMEM; | 354 | return -ENOMEM; |
diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c index 7027a6739845..933af1c25387 100644 --- a/drivers/gpu/drm/selftests/test-drm_mm.c +++ b/drivers/gpu/drm/selftests/test-drm_mm.c | |||
@@ -389,7 +389,7 @@ static int __igt_reserve(unsigned int count, u64 size) | |||
389 | if (!order) | 389 | if (!order) |
390 | goto err; | 390 | goto err; |
391 | 391 | ||
392 | nodes = vzalloc(sizeof(*nodes) * count); | 392 | nodes = vzalloc(array_size(count, sizeof(*nodes))); |
393 | if (!nodes) | 393 | if (!nodes) |
394 | goto err_order; | 394 | goto err_order; |
395 | 395 | ||
@@ -889,7 +889,7 @@ static int __igt_insert_range(unsigned int count, u64 size, u64 start, u64 end) | |||
889 | */ | 889 | */ |
890 | 890 | ||
891 | ret = -ENOMEM; | 891 | ret = -ENOMEM; |
892 | nodes = vzalloc(count * sizeof(*nodes)); | 892 | nodes = vzalloc(array_size(count, sizeof(*nodes))); |
893 | if (!nodes) | 893 | if (!nodes) |
894 | goto err; | 894 | goto err; |
895 | 895 | ||
@@ -1046,7 +1046,7 @@ static int igt_align(void *ignored) | |||
1046 | * meets our requirements. | 1046 | * meets our requirements. |
1047 | */ | 1047 | */ |
1048 | 1048 | ||
1049 | nodes = vzalloc(max_count * sizeof(*nodes)); | 1049 | nodes = vzalloc(array_size(max_count, sizeof(*nodes))); |
1050 | if (!nodes) | 1050 | if (!nodes) |
1051 | goto err; | 1051 | goto err; |
1052 | 1052 | ||
@@ -1416,7 +1416,7 @@ static int igt_evict(void *ignored) | |||
1416 | */ | 1416 | */ |
1417 | 1417 | ||
1418 | ret = -ENOMEM; | 1418 | ret = -ENOMEM; |
1419 | nodes = vzalloc(size * sizeof(*nodes)); | 1419 | nodes = vzalloc(array_size(size, sizeof(*nodes))); |
1420 | if (!nodes) | 1420 | if (!nodes) |
1421 | goto err; | 1421 | goto err; |
1422 | 1422 | ||
@@ -1526,7 +1526,7 @@ static int igt_evict_range(void *ignored) | |||
1526 | */ | 1526 | */ |
1527 | 1527 | ||
1528 | ret = -ENOMEM; | 1528 | ret = -ENOMEM; |
1529 | nodes = vzalloc(size * sizeof(*nodes)); | 1529 | nodes = vzalloc(array_size(size, sizeof(*nodes))); |
1530 | if (!nodes) | 1530 | if (!nodes) |
1531 | goto err; | 1531 | goto err; |
1532 | 1532 | ||
@@ -1627,7 +1627,7 @@ static int igt_topdown(void *ignored) | |||
1627 | */ | 1627 | */ |
1628 | 1628 | ||
1629 | ret = -ENOMEM; | 1629 | ret = -ENOMEM; |
1630 | nodes = vzalloc(count * sizeof(*nodes)); | 1630 | nodes = vzalloc(array_size(count, sizeof(*nodes))); |
1631 | if (!nodes) | 1631 | if (!nodes) |
1632 | goto err; | 1632 | goto err; |
1633 | 1633 | ||
@@ -1741,7 +1741,7 @@ static int igt_bottomup(void *ignored) | |||
1741 | */ | 1741 | */ |
1742 | 1742 | ||
1743 | ret = -ENOMEM; | 1743 | ret = -ENOMEM; |
1744 | nodes = vzalloc(count * sizeof(*nodes)); | 1744 | nodes = vzalloc(array_size(count, sizeof(*nodes))); |
1745 | if (!nodes) | 1745 | if (!nodes) |
1746 | goto err; | 1746 | goto err; |
1747 | 1747 | ||
@@ -2098,7 +2098,7 @@ static int igt_color_evict(void *ignored) | |||
2098 | */ | 2098 | */ |
2099 | 2099 | ||
2100 | ret = -ENOMEM; | 2100 | ret = -ENOMEM; |
2101 | nodes = vzalloc(total_size * sizeof(*nodes)); | 2101 | nodes = vzalloc(array_size(total_size, sizeof(*nodes))); |
2102 | if (!nodes) | 2102 | if (!nodes) |
2103 | goto err; | 2103 | goto err; |
2104 | 2104 | ||
@@ -2199,7 +2199,7 @@ static int igt_color_evict_range(void *ignored) | |||
2199 | */ | 2199 | */ |
2200 | 2200 | ||
2201 | ret = -ENOMEM; | 2201 | ret = -ENOMEM; |
2202 | nodes = vzalloc(total_size * sizeof(*nodes)); | 2202 | nodes = vzalloc(array_size(total_size, sizeof(*nodes))); |
2203 | if (!nodes) | 2203 | if (!nodes) |
2204 | goto err; | 2204 | goto err; |
2205 | 2205 | ||
diff --git a/drivers/gpu/drm/via/via_dmablit.c b/drivers/gpu/drm/via/via_dmablit.c index d6e84a589ef1..345bda4494e1 100644 --- a/drivers/gpu/drm/via/via_dmablit.c +++ b/drivers/gpu/drm/via/via_dmablit.c | |||
@@ -235,7 +235,7 @@ via_lock_all_dma_pages(drm_via_sg_info_t *vsg, drm_via_dmablit_t *xfer) | |||
235 | vsg->num_pages = VIA_PFN(xfer->mem_addr + (xfer->num_lines * xfer->mem_stride - 1)) - | 235 | vsg->num_pages = VIA_PFN(xfer->mem_addr + (xfer->num_lines * xfer->mem_stride - 1)) - |
236 | first_pfn + 1; | 236 | first_pfn + 1; |
237 | 237 | ||
238 | vsg->pages = vzalloc(sizeof(struct page *) * vsg->num_pages); | 238 | vsg->pages = vzalloc(array_size(sizeof(struct page *), vsg->num_pages)); |
239 | if (NULL == vsg->pages) | 239 | if (NULL == vsg->pages) |
240 | return -ENOMEM; | 240 | return -ENOMEM; |
241 | ret = get_user_pages_fast((unsigned long)xfer->mem_addr, | 241 | ret = get_user_pages_fast((unsigned long)xfer->mem_addr, |
diff --git a/drivers/infiniband/core/umem_odp.c b/drivers/infiniband/core/umem_odp.c index 2aadf5813a40..182436b92ba9 100644 --- a/drivers/infiniband/core/umem_odp.c +++ b/drivers/infiniband/core/umem_odp.c | |||
@@ -285,13 +285,15 @@ struct ib_umem *ib_alloc_odp_umem(struct ib_ucontext *context, | |||
285 | mutex_init(&odp_data->umem_mutex); | 285 | mutex_init(&odp_data->umem_mutex); |
286 | init_completion(&odp_data->notifier_completion); | 286 | init_completion(&odp_data->notifier_completion); |
287 | 287 | ||
288 | odp_data->page_list = vzalloc(pages * sizeof(*odp_data->page_list)); | 288 | odp_data->page_list = |
289 | vzalloc(array_size(pages, sizeof(*odp_data->page_list))); | ||
289 | if (!odp_data->page_list) { | 290 | if (!odp_data->page_list) { |
290 | ret = -ENOMEM; | 291 | ret = -ENOMEM; |
291 | goto out_odp_data; | 292 | goto out_odp_data; |
292 | } | 293 | } |
293 | 294 | ||
294 | odp_data->dma_list = vzalloc(pages * sizeof(*odp_data->dma_list)); | 295 | odp_data->dma_list = |
296 | vzalloc(array_size(pages, sizeof(*odp_data->dma_list))); | ||
295 | if (!odp_data->dma_list) { | 297 | if (!odp_data->dma_list) { |
296 | ret = -ENOMEM; | 298 | ret = -ENOMEM; |
297 | goto out_page_list; | 299 | goto out_page_list; |
@@ -371,15 +373,17 @@ int ib_umem_odp_get(struct ib_ucontext *context, struct ib_umem *umem, | |||
371 | init_completion(&umem->odp_data->notifier_completion); | 373 | init_completion(&umem->odp_data->notifier_completion); |
372 | 374 | ||
373 | if (ib_umem_num_pages(umem)) { | 375 | if (ib_umem_num_pages(umem)) { |
374 | umem->odp_data->page_list = vzalloc(ib_umem_num_pages(umem) * | 376 | umem->odp_data->page_list = |
375 | sizeof(*umem->odp_data->page_list)); | 377 | vzalloc(array_size(sizeof(*umem->odp_data->page_list), |
378 | ib_umem_num_pages(umem))); | ||
376 | if (!umem->odp_data->page_list) { | 379 | if (!umem->odp_data->page_list) { |
377 | ret_val = -ENOMEM; | 380 | ret_val = -ENOMEM; |
378 | goto out_odp_data; | 381 | goto out_odp_data; |
379 | } | 382 | } |
380 | 383 | ||
381 | umem->odp_data->dma_list = vzalloc(ib_umem_num_pages(umem) * | 384 | umem->odp_data->dma_list = |
382 | sizeof(*umem->odp_data->dma_list)); | 385 | vzalloc(array_size(sizeof(*umem->odp_data->dma_list), |
386 | ib_umem_num_pages(umem))); | ||
383 | if (!umem->odp_data->dma_list) { | 387 | if (!umem->odp_data->dma_list) { |
384 | ret_val = -ENOMEM; | 388 | ret_val = -ENOMEM; |
385 | goto out_page_list; | 389 | goto out_page_list; |
diff --git a/drivers/infiniband/hw/hns/hns_roce_mr.c b/drivers/infiniband/hw/hns/hns_roce_mr.c index d1fe0e7957e3..eb26a5f6fc58 100644 --- a/drivers/infiniband/hw/hns/hns_roce_mr.c +++ b/drivers/infiniband/hw/hns/hns_roce_mr.c | |||
@@ -144,7 +144,7 @@ static int hns_roce_buddy_init(struct hns_roce_buddy *buddy, int max_order) | |||
144 | buddy->bits[i] = kcalloc(s, sizeof(long), GFP_KERNEL | | 144 | buddy->bits[i] = kcalloc(s, sizeof(long), GFP_KERNEL | |
145 | __GFP_NOWARN); | 145 | __GFP_NOWARN); |
146 | if (!buddy->bits[i]) { | 146 | if (!buddy->bits[i]) { |
147 | buddy->bits[i] = vzalloc(s * sizeof(long)); | 147 | buddy->bits[i] = vzalloc(array_size(s, sizeof(long))); |
148 | if (!buddy->bits[i]) | 148 | if (!buddy->bits[i]) |
149 | goto err_out_free; | 149 | goto err_out_free; |
150 | } | 150 | } |
diff --git a/drivers/infiniband/hw/qib/qib_init.c b/drivers/infiniband/hw/qib/qib_init.c index 704505618909..d7cdc77d6306 100644 --- a/drivers/infiniband/hw/qib/qib_init.c +++ b/drivers/infiniband/hw/qib/qib_init.c | |||
@@ -369,11 +369,13 @@ static void init_shadow_tids(struct qib_devdata *dd) | |||
369 | struct page **pages; | 369 | struct page **pages; |
370 | dma_addr_t *addrs; | 370 | dma_addr_t *addrs; |
371 | 371 | ||
372 | pages = vzalloc(dd->cfgctxts * dd->rcvtidcnt * sizeof(struct page *)); | 372 | pages = vzalloc(array_size(sizeof(struct page *), |
373 | dd->cfgctxts * dd->rcvtidcnt)); | ||
373 | if (!pages) | 374 | if (!pages) |
374 | goto bail; | 375 | goto bail; |
375 | 376 | ||
376 | addrs = vzalloc(dd->cfgctxts * dd->rcvtidcnt * sizeof(dma_addr_t)); | 377 | addrs = vzalloc(array_size(sizeof(dma_addr_t), |
378 | dd->cfgctxts * dd->rcvtidcnt)); | ||
377 | if (!addrs) | 379 | if (!addrs) |
378 | goto bail_free; | 380 | goto bail_free; |
379 | 381 | ||
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_cm.c b/drivers/infiniband/ulp/ipoib/ipoib_cm.c index 962fbcb57dc7..6535d9beb24d 100644 --- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c +++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c | |||
@@ -358,7 +358,8 @@ static int ipoib_cm_nonsrq_init_rx(struct net_device *dev, struct ib_cm_id *cm_i | |||
358 | int ret; | 358 | int ret; |
359 | int i; | 359 | int i; |
360 | 360 | ||
361 | rx->rx_ring = vzalloc(ipoib_recvq_size * sizeof *rx->rx_ring); | 361 | rx->rx_ring = vzalloc(array_size(ipoib_recvq_size, |
362 | sizeof(*rx->rx_ring))); | ||
362 | if (!rx->rx_ring) | 363 | if (!rx->rx_ring) |
363 | return -ENOMEM; | 364 | return -ENOMEM; |
364 | 365 | ||
@@ -1145,7 +1146,7 @@ static int ipoib_cm_tx_init(struct ipoib_cm_tx *p, u32 qpn, | |||
1145 | int ret; | 1146 | int ret; |
1146 | 1147 | ||
1147 | noio_flag = memalloc_noio_save(); | 1148 | noio_flag = memalloc_noio_save(); |
1148 | p->tx_ring = vzalloc(ipoib_sendq_size * sizeof(*p->tx_ring)); | 1149 | p->tx_ring = vzalloc(array_size(ipoib_sendq_size, sizeof(*p->tx_ring))); |
1149 | if (!p->tx_ring) { | 1150 | if (!p->tx_ring) { |
1150 | memalloc_noio_restore(noio_flag); | 1151 | memalloc_noio_restore(noio_flag); |
1151 | ret = -ENOMEM; | 1152 | ret = -ENOMEM; |
@@ -1570,7 +1571,8 @@ static void ipoib_cm_create_srq(struct net_device *dev, int max_sge) | |||
1570 | return; | 1571 | return; |
1571 | } | 1572 | } |
1572 | 1573 | ||
1573 | priv->cm.srq_ring = vzalloc(ipoib_recvq_size * sizeof *priv->cm.srq_ring); | 1574 | priv->cm.srq_ring = vzalloc(array_size(ipoib_recvq_size, |
1575 | sizeof(*priv->cm.srq_ring))); | ||
1574 | if (!priv->cm.srq_ring) { | 1576 | if (!priv->cm.srq_ring) { |
1575 | ib_destroy_srq(priv->cm.srq); | 1577 | ib_destroy_srq(priv->cm.srq); |
1576 | priv->cm.srq = NULL; | 1578 | priv->cm.srq = NULL; |
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c index 0d74c807110e..26cde95bc0f3 100644 --- a/drivers/infiniband/ulp/ipoib/ipoib_main.c +++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c | |||
@@ -1710,7 +1710,8 @@ static int ipoib_dev_init_default(struct net_device *dev) | |||
1710 | if (!priv->rx_ring) | 1710 | if (!priv->rx_ring) |
1711 | goto out; | 1711 | goto out; |
1712 | 1712 | ||
1713 | priv->tx_ring = vzalloc(ipoib_sendq_size * sizeof *priv->tx_ring); | 1713 | priv->tx_ring = vzalloc(array_size(ipoib_sendq_size, |
1714 | sizeof(*priv->tx_ring))); | ||
1714 | if (!priv->tx_ring) { | 1715 | if (!priv->tx_ring) { |
1715 | pr_warn("%s: failed to allocate TX ring (%d entries)\n", | 1716 | pr_warn("%s: failed to allocate TX ring (%d entries)\n", |
1716 | priv->ca->name, ipoib_sendq_size); | 1717 | priv->ca->name, ipoib_sendq_size); |
diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c index c7a7c2de0672..b57f764d6a16 100644 --- a/drivers/lightnvm/pblk-init.c +++ b/drivers/lightnvm/pblk-init.c | |||
@@ -187,7 +187,7 @@ static int pblk_rwb_init(struct pblk *pblk) | |||
187 | 187 | ||
188 | nr_entries = pblk_rb_calculate_size(buffer_size); | 188 | nr_entries = pblk_rb_calculate_size(buffer_size); |
189 | 189 | ||
190 | entries = vzalloc(nr_entries * sizeof(struct pblk_rb_entry)); | 190 | entries = vzalloc(array_size(nr_entries, sizeof(struct pblk_rb_entry))); |
191 | if (!entries) | 191 | if (!entries) |
192 | return -ENOMEM; | 192 | return -ENOMEM; |
193 | 193 | ||
diff --git a/drivers/lightnvm/pblk-recovery.c b/drivers/lightnvm/pblk-recovery.c index 598342833d0d..3a5069183859 100644 --- a/drivers/lightnvm/pblk-recovery.c +++ b/drivers/lightnvm/pblk-recovery.c | |||
@@ -260,7 +260,7 @@ static int pblk_recov_pad_oob(struct pblk *pblk, struct pblk_line *line, | |||
260 | if (!pad_rq) | 260 | if (!pad_rq) |
261 | return -ENOMEM; | 261 | return -ENOMEM; |
262 | 262 | ||
263 | data = vzalloc(pblk->max_write_pgs * geo->csecs); | 263 | data = vzalloc(array_size(pblk->max_write_pgs, geo->csecs)); |
264 | if (!data) { | 264 | if (!data) { |
265 | ret = -ENOMEM; | 265 | ret = -ENOMEM; |
266 | goto free_rq; | 266 | goto free_rq; |
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index ec5f70d021de..fa4058e43202 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c | |||
@@ -2041,8 +2041,8 @@ static int cache_alloc(struct cache *ca) | |||
2041 | !init_fifo(&ca->free[RESERVE_NONE], free, GFP_KERNEL) || | 2041 | !init_fifo(&ca->free[RESERVE_NONE], free, GFP_KERNEL) || |
2042 | !init_fifo(&ca->free_inc, free << 2, GFP_KERNEL) || | 2042 | !init_fifo(&ca->free_inc, free << 2, GFP_KERNEL) || |
2043 | !init_heap(&ca->heap, free << 3, GFP_KERNEL) || | 2043 | !init_heap(&ca->heap, free << 3, GFP_KERNEL) || |
2044 | !(ca->buckets = vzalloc(sizeof(struct bucket) * | 2044 | !(ca->buckets = vzalloc(array_size(sizeof(struct bucket), |
2045 | ca->sb.nbuckets)) || | 2045 | ca->sb.nbuckets))) || |
2046 | !(ca->prio_buckets = kzalloc(array3_size(sizeof(uint64_t), | 2046 | !(ca->prio_buckets = kzalloc(array3_size(sizeof(uint64_t), |
2047 | prio_buckets(ca), 2), | 2047 | prio_buckets(ca), 2), |
2048 | GFP_KERNEL)) || | 2048 | GFP_KERNEL)) || |
diff --git a/drivers/md/dm-cache-policy-smq.c b/drivers/md/dm-cache-policy-smq.c index 4d69b6f4129e..1b5b9ad9e492 100644 --- a/drivers/md/dm-cache-policy-smq.c +++ b/drivers/md/dm-cache-policy-smq.c | |||
@@ -69,7 +69,7 @@ static int space_init(struct entry_space *es, unsigned nr_entries) | |||
69 | return 0; | 69 | return 0; |
70 | } | 70 | } |
71 | 71 | ||
72 | es->begin = vzalloc(sizeof(struct entry) * nr_entries); | 72 | es->begin = vzalloc(array_size(nr_entries, sizeof(struct entry))); |
73 | if (!es->begin) | 73 | if (!es->begin) |
74 | return -ENOMEM; | 74 | return -ENOMEM; |
75 | 75 | ||
diff --git a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c index 9b64f4f354bf..abd4c788dffd 100644 --- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c +++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c | |||
@@ -119,12 +119,14 @@ int tpg_alloc(struct tpg_data *tpg, unsigned max_w) | |||
119 | for (plane = 0; plane < TPG_MAX_PLANES; plane++) { | 119 | for (plane = 0; plane < TPG_MAX_PLANES; plane++) { |
120 | unsigned pixelsz = plane ? 2 : 4; | 120 | unsigned pixelsz = plane ? 2 : 4; |
121 | 121 | ||
122 | tpg->lines[pat][plane] = vzalloc(max_w * 2 * pixelsz); | 122 | tpg->lines[pat][plane] = |
123 | vzalloc(array3_size(max_w, 2, pixelsz)); | ||
123 | if (!tpg->lines[pat][plane]) | 124 | if (!tpg->lines[pat][plane]) |
124 | return -ENOMEM; | 125 | return -ENOMEM; |
125 | if (plane == 0) | 126 | if (plane == 0) |
126 | continue; | 127 | continue; |
127 | tpg->downsampled_lines[pat][plane] = vzalloc(max_w * 2 * pixelsz); | 128 | tpg->downsampled_lines[pat][plane] = |
129 | vzalloc(array3_size(max_w, 2, pixelsz)); | ||
128 | if (!tpg->downsampled_lines[pat][plane]) | 130 | if (!tpg->downsampled_lines[pat][plane]) |
129 | return -ENOMEM; | 131 | return -ENOMEM; |
130 | } | 132 | } |
@@ -132,13 +134,16 @@ int tpg_alloc(struct tpg_data *tpg, unsigned max_w) | |||
132 | for (plane = 0; plane < TPG_MAX_PLANES; plane++) { | 134 | for (plane = 0; plane < TPG_MAX_PLANES; plane++) { |
133 | unsigned pixelsz = plane ? 2 : 4; | 135 | unsigned pixelsz = plane ? 2 : 4; |
134 | 136 | ||
135 | tpg->contrast_line[plane] = vzalloc(max_w * pixelsz); | 137 | tpg->contrast_line[plane] = |
138 | vzalloc(array_size(pixelsz, max_w)); | ||
136 | if (!tpg->contrast_line[plane]) | 139 | if (!tpg->contrast_line[plane]) |
137 | return -ENOMEM; | 140 | return -ENOMEM; |
138 | tpg->black_line[plane] = vzalloc(max_w * pixelsz); | 141 | tpg->black_line[plane] = |
142 | vzalloc(array_size(pixelsz, max_w)); | ||
139 | if (!tpg->black_line[plane]) | 143 | if (!tpg->black_line[plane]) |
140 | return -ENOMEM; | 144 | return -ENOMEM; |
141 | tpg->random_line[plane] = vzalloc(max_w * 2 * pixelsz); | 145 | tpg->random_line[plane] = |
146 | vzalloc(array3_size(max_w, 2, pixelsz)); | ||
142 | if (!tpg->random_line[plane]) | 147 | if (!tpg->random_line[plane]) |
143 | return -ENOMEM; | 148 | return -ENOMEM; |
144 | } | 149 | } |
diff --git a/drivers/media/pci/cx23885/cx23885-alsa.c b/drivers/media/pci/cx23885/cx23885-alsa.c index 20b3cb17f97f..db1e8ff35474 100644 --- a/drivers/media/pci/cx23885/cx23885-alsa.c +++ b/drivers/media/pci/cx23885/cx23885-alsa.c | |||
@@ -95,7 +95,7 @@ static int cx23885_alsa_dma_init(struct cx23885_audio_dev *chip, int nr_pages) | |||
95 | memset(buf->vaddr, 0, nr_pages << PAGE_SHIFT); | 95 | memset(buf->vaddr, 0, nr_pages << PAGE_SHIFT); |
96 | buf->nr_pages = nr_pages; | 96 | buf->nr_pages = nr_pages; |
97 | 97 | ||
98 | buf->sglist = vzalloc(buf->nr_pages * sizeof(*buf->sglist)); | 98 | buf->sglist = vzalloc(array_size(sizeof(*buf->sglist), buf->nr_pages)); |
99 | if (NULL == buf->sglist) | 99 | if (NULL == buf->sglist) |
100 | goto vzalloc_err; | 100 | goto vzalloc_err; |
101 | 101 | ||
diff --git a/drivers/media/pci/cx25821/cx25821-alsa.c b/drivers/media/pci/cx25821/cx25821-alsa.c index a45bf0331eeb..ef6380651c10 100644 --- a/drivers/media/pci/cx25821/cx25821-alsa.c +++ b/drivers/media/pci/cx25821/cx25821-alsa.c | |||
@@ -159,7 +159,7 @@ static int cx25821_alsa_dma_init(struct cx25821_audio_dev *chip, int nr_pages) | |||
159 | memset(buf->vaddr, 0, nr_pages << PAGE_SHIFT); | 159 | memset(buf->vaddr, 0, nr_pages << PAGE_SHIFT); |
160 | buf->nr_pages = nr_pages; | 160 | buf->nr_pages = nr_pages; |
161 | 161 | ||
162 | buf->sglist = vzalloc(buf->nr_pages * sizeof(*buf->sglist)); | 162 | buf->sglist = vzalloc(array_size(sizeof(*buf->sglist), buf->nr_pages)); |
163 | if (NULL == buf->sglist) | 163 | if (NULL == buf->sglist) |
164 | goto vzalloc_err; | 164 | goto vzalloc_err; |
165 | 165 | ||
diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c index 8a28fda703a2..e5c3387cd1e8 100644 --- a/drivers/media/pci/cx88/cx88-alsa.c +++ b/drivers/media/pci/cx88/cx88-alsa.c | |||
@@ -298,7 +298,7 @@ static int cx88_alsa_dma_init(struct cx88_audio_dev *chip, int nr_pages) | |||
298 | memset(buf->vaddr, 0, nr_pages << PAGE_SHIFT); | 298 | memset(buf->vaddr, 0, nr_pages << PAGE_SHIFT); |
299 | buf->nr_pages = nr_pages; | 299 | buf->nr_pages = nr_pages; |
300 | 300 | ||
301 | buf->sglist = vzalloc(buf->nr_pages * sizeof(*buf->sglist)); | 301 | buf->sglist = vzalloc(array_size(sizeof(*buf->sglist), buf->nr_pages)); |
302 | if (!buf->sglist) | 302 | if (!buf->sglist) |
303 | goto vzalloc_err; | 303 | goto vzalloc_err; |
304 | 304 | ||
diff --git a/drivers/media/pci/saa7134/saa7134-alsa.c b/drivers/media/pci/saa7134/saa7134-alsa.c index 72311445d13d..b90cfde6e301 100644 --- a/drivers/media/pci/saa7134/saa7134-alsa.c +++ b/drivers/media/pci/saa7134/saa7134-alsa.c | |||
@@ -279,7 +279,7 @@ static int saa7134_alsa_dma_init(struct saa7134_dev *dev, int nr_pages) | |||
279 | memset(dma->vaddr, 0, nr_pages << PAGE_SHIFT); | 279 | memset(dma->vaddr, 0, nr_pages << PAGE_SHIFT); |
280 | dma->nr_pages = nr_pages; | 280 | dma->nr_pages = nr_pages; |
281 | 281 | ||
282 | dma->sglist = vzalloc(dma->nr_pages * sizeof(*dma->sglist)); | 282 | dma->sglist = vzalloc(array_size(sizeof(*dma->sglist), dma->nr_pages)); |
283 | if (NULL == dma->sglist) | 283 | if (NULL == dma->sglist) |
284 | goto vzalloc_err; | 284 | goto vzalloc_err; |
285 | 285 | ||
diff --git a/drivers/media/platform/vivid/vivid-core.c b/drivers/media/platform/vivid/vivid-core.c index 59031018985e..31db363602e5 100644 --- a/drivers/media/platform/vivid/vivid-core.c +++ b/drivers/media/platform/vivid/vivid-core.c | |||
@@ -844,10 +844,10 @@ static int vivid_create_instance(struct platform_device *pdev, int inst) | |||
844 | tpg_init(&dev->tpg, 640, 360); | 844 | tpg_init(&dev->tpg, 640, 360); |
845 | if (tpg_alloc(&dev->tpg, MAX_ZOOM * MAX_WIDTH)) | 845 | if (tpg_alloc(&dev->tpg, MAX_ZOOM * MAX_WIDTH)) |
846 | goto free_dev; | 846 | goto free_dev; |
847 | dev->scaled_line = vzalloc(MAX_ZOOM * MAX_WIDTH); | 847 | dev->scaled_line = vzalloc(array_size(MAX_WIDTH, MAX_ZOOM)); |
848 | if (!dev->scaled_line) | 848 | if (!dev->scaled_line) |
849 | goto free_dev; | 849 | goto free_dev; |
850 | dev->blended_line = vzalloc(MAX_ZOOM * MAX_WIDTH); | 850 | dev->blended_line = vzalloc(array_size(MAX_WIDTH, MAX_ZOOM)); |
851 | if (!dev->blended_line) | 851 | if (!dev->blended_line) |
852 | goto free_dev; | 852 | goto free_dev; |
853 | 853 | ||
diff --git a/drivers/media/v4l2-core/videobuf-dma-sg.c b/drivers/media/v4l2-core/videobuf-dma-sg.c index 314abde9a922..08929c087e27 100644 --- a/drivers/media/v4l2-core/videobuf-dma-sg.c +++ b/drivers/media/v4l2-core/videobuf-dma-sg.c | |||
@@ -69,7 +69,7 @@ static struct scatterlist *videobuf_vmalloc_to_sg(unsigned char *virt, | |||
69 | struct page *pg; | 69 | struct page *pg; |
70 | int i; | 70 | int i; |
71 | 71 | ||
72 | sglist = vzalloc(nr_pages * sizeof(*sglist)); | 72 | sglist = vzalloc(array_size(nr_pages, sizeof(*sglist))); |
73 | if (NULL == sglist) | 73 | if (NULL == sglist) |
74 | return NULL; | 74 | return NULL; |
75 | sg_init_table(sglist, nr_pages); | 75 | sg_init_table(sglist, nr_pages); |
diff --git a/drivers/mtd/nand/raw/nandsim.c b/drivers/mtd/nand/raw/nandsim.c index 9dc29d4389f7..f8edacde49ab 100644 --- a/drivers/mtd/nand/raw/nandsim.c +++ b/drivers/mtd/nand/raw/nandsim.c | |||
@@ -565,8 +565,9 @@ static int __init alloc_device(struct nandsim *ns) | |||
565 | err = -EINVAL; | 565 | err = -EINVAL; |
566 | goto err_close; | 566 | goto err_close; |
567 | } | 567 | } |
568 | ns->pages_written = vzalloc(BITS_TO_LONGS(ns->geom.pgnum) * | 568 | ns->pages_written = |
569 | sizeof(unsigned long)); | 569 | vzalloc(array_size(sizeof(unsigned long), |
570 | BITS_TO_LONGS(ns->geom.pgnum))); | ||
570 | if (!ns->pages_written) { | 571 | if (!ns->pages_written) { |
571 | NS_ERR("alloc_device: unable to allocate pages written array\n"); | 572 | NS_ERR("alloc_device: unable to allocate pages written array\n"); |
572 | err = -ENOMEM; | 573 | err = -ENOMEM; |
diff --git a/drivers/net/ethernet/broadcom/bnx2.c b/drivers/net/ethernet/broadcom/bnx2.c index e13bf3b4636d..122fdb80a789 100644 --- a/drivers/net/ethernet/broadcom/bnx2.c +++ b/drivers/net/ethernet/broadcom/bnx2.c | |||
@@ -778,7 +778,7 @@ bnx2_alloc_rx_mem(struct bnx2 *bp) | |||
778 | int j; | 778 | int j; |
779 | 779 | ||
780 | rxr->rx_buf_ring = | 780 | rxr->rx_buf_ring = |
781 | vzalloc(SW_RXBD_RING_SIZE * bp->rx_max_ring); | 781 | vzalloc(array_size(SW_RXBD_RING_SIZE, bp->rx_max_ring)); |
782 | if (!rxr->rx_buf_ring) | 782 | if (!rxr->rx_buf_ring) |
783 | return -ENOMEM; | 783 | return -ENOMEM; |
784 | 784 | ||
@@ -794,8 +794,9 @@ bnx2_alloc_rx_mem(struct bnx2 *bp) | |||
794 | } | 794 | } |
795 | 795 | ||
796 | if (bp->rx_pg_ring_size) { | 796 | if (bp->rx_pg_ring_size) { |
797 | rxr->rx_pg_ring = vzalloc(SW_RXPG_RING_SIZE * | 797 | rxr->rx_pg_ring = |
798 | bp->rx_max_pg_ring); | 798 | vzalloc(array_size(SW_RXPG_RING_SIZE, |
799 | bp->rx_max_pg_ring)); | ||
799 | if (!rxr->rx_pg_ring) | 800 | if (!rxr->rx_pg_ring) |
800 | return -ENOMEM; | 801 | return -ENOMEM; |
801 | 802 | ||
diff --git a/drivers/net/ethernet/cavium/liquidio/octeon_droq.c b/drivers/net/ethernet/cavium/liquidio/octeon_droq.c index f044718cea52..5b5b6228d495 100644 --- a/drivers/net/ethernet/cavium/liquidio/octeon_droq.c +++ b/drivers/net/ethernet/cavium/liquidio/octeon_droq.c | |||
@@ -286,8 +286,8 @@ int octeon_init_droq(struct octeon_device *oct, | |||
286 | numa_node); | 286 | numa_node); |
287 | if (!droq->recv_buf_list) | 287 | if (!droq->recv_buf_list) |
288 | droq->recv_buf_list = (struct octeon_recv_buffer *) | 288 | droq->recv_buf_list = (struct octeon_recv_buffer *) |
289 | vzalloc(droq->max_count * | 289 | vzalloc(array_size(droq->max_count, |
290 | OCT_DROQ_RECVBUF_SIZE); | 290 | OCT_DROQ_RECVBUF_SIZE)); |
291 | if (!droq->recv_buf_list) { | 291 | if (!droq->recv_buf_list) { |
292 | dev_err(&oct->pci_dev->dev, "Output queue recv buf list alloc failed\n"); | 292 | dev_err(&oct->pci_dev->dev, "Output queue recv buf list alloc failed\n"); |
293 | goto init_droq_fail; | 293 | goto init_droq_fail; |
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c index 85e1d14514fc..0ce07f6eb1e6 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | |||
@@ -1406,8 +1406,8 @@ static int hns_dsaf_init(struct dsaf_device *dsaf_dev) | |||
1406 | return ret; | 1406 | return ret; |
1407 | 1407 | ||
1408 | /* malloc mem for tcam mac key(vlan+mac) */ | 1408 | /* malloc mem for tcam mac key(vlan+mac) */ |
1409 | priv->soft_mac_tbl = vzalloc(sizeof(*priv->soft_mac_tbl) | 1409 | priv->soft_mac_tbl = vzalloc(array_size(DSAF_TCAM_SUM, |
1410 | * DSAF_TCAM_SUM); | 1410 | sizeof(*priv->soft_mac_tbl))); |
1411 | if (!priv->soft_mac_tbl) { | 1411 | if (!priv->soft_mac_tbl) { |
1412 | ret = -ENOMEM; | 1412 | ret = -ENOMEM; |
1413 | goto remove_hw; | 1413 | goto remove_hw; |
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_hw_cmdq.c b/drivers/net/ethernet/huawei/hinic/hinic_hw_cmdq.c index 28a81ac97af5..4d09ea786b35 100644 --- a/drivers/net/ethernet/huawei/hinic/hinic_hw_cmdq.c +++ b/drivers/net/ethernet/huawei/hinic/hinic_hw_cmdq.c | |||
@@ -753,11 +753,12 @@ static int init_cmdq(struct hinic_cmdq *cmdq, struct hinic_wq *wq, | |||
753 | 753 | ||
754 | spin_lock_init(&cmdq->cmdq_lock); | 754 | spin_lock_init(&cmdq->cmdq_lock); |
755 | 755 | ||
756 | cmdq->done = vzalloc(wq->q_depth * sizeof(*cmdq->done)); | 756 | cmdq->done = vzalloc(array_size(sizeof(*cmdq->done), wq->q_depth)); |
757 | if (!cmdq->done) | 757 | if (!cmdq->done) |
758 | return -ENOMEM; | 758 | return -ENOMEM; |
759 | 759 | ||
760 | cmdq->errcode = vzalloc(wq->q_depth * sizeof(*cmdq->errcode)); | 760 | cmdq->errcode = vzalloc(array_size(sizeof(*cmdq->errcode), |
761 | wq->q_depth)); | ||
761 | if (!cmdq->errcode) { | 762 | if (!cmdq->errcode) { |
762 | err = -ENOMEM; | 763 | err = -ENOMEM; |
763 | goto err_errcode; | 764 | goto err_errcode; |
diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c index 8d0295655933..358ed6118881 100644 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c | |||
@@ -2565,7 +2565,7 @@ __vxge_hw_mempool_grow(struct vxge_hw_mempool *mempool, u32 num_allocate, | |||
2565 | * allocate new memblock and its private part at once. | 2565 | * allocate new memblock and its private part at once. |
2566 | * This helps to minimize memory usage a lot. */ | 2566 | * This helps to minimize memory usage a lot. */ |
2567 | mempool->memblocks_priv_arr[i] = | 2567 | mempool->memblocks_priv_arr[i] = |
2568 | vzalloc(mempool->items_priv_size * n_items); | 2568 | vzalloc(array_size(mempool->items_priv_size, n_items)); |
2569 | if (mempool->memblocks_priv_arr[i] == NULL) { | 2569 | if (mempool->memblocks_priv_arr[i] == NULL) { |
2570 | status = VXGE_HW_ERR_OUT_OF_MEMORY; | 2570 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
2571 | goto exit; | 2571 | goto exit; |
@@ -2665,7 +2665,7 @@ __vxge_hw_mempool_create(struct __vxge_hw_device *devh, | |||
2665 | 2665 | ||
2666 | /* allocate array of memblocks */ | 2666 | /* allocate array of memblocks */ |
2667 | mempool->memblocks_arr = | 2667 | mempool->memblocks_arr = |
2668 | vzalloc(sizeof(void *) * mempool->memblocks_max); | 2668 | vzalloc(array_size(sizeof(void *), mempool->memblocks_max)); |
2669 | if (mempool->memblocks_arr == NULL) { | 2669 | if (mempool->memblocks_arr == NULL) { |
2670 | __vxge_hw_mempool_destroy(mempool); | 2670 | __vxge_hw_mempool_destroy(mempool); |
2671 | status = VXGE_HW_ERR_OUT_OF_MEMORY; | 2671 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
@@ -2675,7 +2675,7 @@ __vxge_hw_mempool_create(struct __vxge_hw_device *devh, | |||
2675 | 2675 | ||
2676 | /* allocate array of private parts of items per memblocks */ | 2676 | /* allocate array of private parts of items per memblocks */ |
2677 | mempool->memblocks_priv_arr = | 2677 | mempool->memblocks_priv_arr = |
2678 | vzalloc(sizeof(void *) * mempool->memblocks_max); | 2678 | vzalloc(array_size(sizeof(void *), mempool->memblocks_max)); |
2679 | if (mempool->memblocks_priv_arr == NULL) { | 2679 | if (mempool->memblocks_priv_arr == NULL) { |
2680 | __vxge_hw_mempool_destroy(mempool); | 2680 | __vxge_hw_mempool_destroy(mempool); |
2681 | status = VXGE_HW_ERR_OUT_OF_MEMORY; | 2681 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
@@ -2685,8 +2685,8 @@ __vxge_hw_mempool_create(struct __vxge_hw_device *devh, | |||
2685 | 2685 | ||
2686 | /* allocate array of memblocks DMA objects */ | 2686 | /* allocate array of memblocks DMA objects */ |
2687 | mempool->memblocks_dma_arr = | 2687 | mempool->memblocks_dma_arr = |
2688 | vzalloc(sizeof(struct vxge_hw_mempool_dma) * | 2688 | vzalloc(array_size(sizeof(struct vxge_hw_mempool_dma), |
2689 | mempool->memblocks_max); | 2689 | mempool->memblocks_max)); |
2690 | if (mempool->memblocks_dma_arr == NULL) { | 2690 | if (mempool->memblocks_dma_arr == NULL) { |
2691 | __vxge_hw_mempool_destroy(mempool); | 2691 | __vxge_hw_mempool_destroy(mempool); |
2692 | status = VXGE_HW_ERR_OUT_OF_MEMORY; | 2692 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
@@ -2695,7 +2695,8 @@ __vxge_hw_mempool_create(struct __vxge_hw_device *devh, | |||
2695 | } | 2695 | } |
2696 | 2696 | ||
2697 | /* allocate hash array of items */ | 2697 | /* allocate hash array of items */ |
2698 | mempool->items_arr = vzalloc(sizeof(void *) * mempool->items_max); | 2698 | mempool->items_arr = vzalloc(array_size(sizeof(void *), |
2699 | mempool->items_max)); | ||
2699 | if (mempool->items_arr == NULL) { | 2700 | if (mempool->items_arr == NULL) { |
2700 | __vxge_hw_mempool_destroy(mempool); | 2701 | __vxge_hw_mempool_destroy(mempool); |
2701 | status = VXGE_HW_ERR_OUT_OF_MEMORY; | 2702 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
diff --git a/drivers/net/ethernet/qlogic/qed/qed_l2.c b/drivers/net/ethernet/qlogic/qed/qed_l2.c index de1c70843efd..99973e10b179 100644 --- a/drivers/net/ethernet/qlogic/qed/qed_l2.c +++ b/drivers/net/ethernet/qlogic/qed/qed_l2.c | |||
@@ -2435,7 +2435,7 @@ static int qed_update_vport(struct qed_dev *cdev, | |||
2435 | if (!cdev) | 2435 | if (!cdev) |
2436 | return -ENODEV; | 2436 | return -ENODEV; |
2437 | 2437 | ||
2438 | rss = vzalloc(sizeof(*rss) * cdev->num_hwfns); | 2438 | rss = vzalloc(array_size(sizeof(*rss), cdev->num_hwfns)); |
2439 | if (!rss) | 2439 | if (!rss) |
2440 | return -ENOMEM; | 2440 | return -ENOMEM; |
2441 | 2441 | ||
diff --git a/drivers/net/ethernet/qlogic/qede/qede_filter.c b/drivers/net/ethernet/qlogic/qede/qede_filter.c index e9e088d9c815..b823bfe2ea4d 100644 --- a/drivers/net/ethernet/qlogic/qede/qede_filter.c +++ b/drivers/net/ethernet/qlogic/qede/qede_filter.c | |||
@@ -342,8 +342,9 @@ int qede_alloc_arfs(struct qede_dev *edev) | |||
342 | for (i = 0; i <= QEDE_RFS_FLW_MASK; i++) | 342 | for (i = 0; i <= QEDE_RFS_FLW_MASK; i++) |
343 | INIT_HLIST_HEAD(QEDE_ARFS_BUCKET_HEAD(edev, i)); | 343 | INIT_HLIST_HEAD(QEDE_ARFS_BUCKET_HEAD(edev, i)); |
344 | 344 | ||
345 | edev->arfs->arfs_fltr_bmap = vzalloc(BITS_TO_LONGS(QEDE_RFS_MAX_FLTR) * | 345 | edev->arfs->arfs_fltr_bmap = |
346 | sizeof(long)); | 346 | vzalloc(array_size(sizeof(long), |
347 | BITS_TO_LONGS(QEDE_RFS_MAX_FLTR))); | ||
347 | if (!edev->arfs->arfs_fltr_bmap) { | 348 | if (!edev->arfs->arfs_fltr_bmap) { |
348 | vfree(edev->arfs); | 349 | vfree(edev->arfs); |
349 | edev->arfs = NULL; | 350 | edev->arfs = NULL; |
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c index 97c146e7698a..569d54ededec 100644 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c | |||
@@ -386,8 +386,9 @@ int qlcnic_83xx_setup_intr(struct qlcnic_adapter *adapter) | |||
386 | } | 386 | } |
387 | 387 | ||
388 | /* setup interrupt mapping table for fw */ | 388 | /* setup interrupt mapping table for fw */ |
389 | ahw->intr_tbl = vzalloc(num_msix * | 389 | ahw->intr_tbl = |
390 | sizeof(struct qlcnic_intrpt_config)); | 390 | vzalloc(array_size(num_msix, |
391 | sizeof(struct qlcnic_intrpt_config))); | ||
391 | if (!ahw->intr_tbl) | 392 | if (!ahw->intr_tbl) |
392 | return -ENOMEM; | 393 | return -ENOMEM; |
393 | 394 | ||
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c index 8c6724063231..2d38d1ac2aae 100644 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c | |||
@@ -916,8 +916,9 @@ int qlcnic_82xx_mq_intrpt(struct qlcnic_adapter *adapter, int op_type) | |||
916 | if (qlcnic_check_multi_tx(adapter) && | 916 | if (qlcnic_check_multi_tx(adapter) && |
917 | !ahw->diag_test && | 917 | !ahw->diag_test && |
918 | (adapter->flags & QLCNIC_MSIX_ENABLED)) { | 918 | (adapter->flags & QLCNIC_MSIX_ENABLED)) { |
919 | ahw->intr_tbl = vzalloc(ahw->num_msix * | 919 | ahw->intr_tbl = |
920 | sizeof(struct qlcnic_intrpt_config)); | 920 | vzalloc(array_size(sizeof(struct qlcnic_intrpt_config), |
921 | ahw->num_msix)); | ||
921 | if (!ahw->intr_tbl) | 922 | if (!ahw->intr_tbl) |
922 | return -ENOMEM; | 923 | return -ENOMEM; |
923 | 924 | ||
diff --git a/drivers/net/ethernet/sfc/ef10.c b/drivers/net/ethernet/sfc/ef10.c index d90a7b1f4088..23f0785c0573 100644 --- a/drivers/net/ethernet/sfc/ef10.c +++ b/drivers/net/ethernet/sfc/ef10.c | |||
@@ -4984,7 +4984,8 @@ static int efx_ef10_filter_table_probe(struct efx_nic *efx) | |||
4984 | net_dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; | 4984 | net_dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; |
4985 | } | 4985 | } |
4986 | 4986 | ||
4987 | table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry)); | 4987 | table->entry = vzalloc(array_size(HUNT_FILTER_TBL_ROWS, |
4988 | sizeof(*table->entry))); | ||
4988 | if (!table->entry) { | 4989 | if (!table->entry) { |
4989 | rc = -ENOMEM; | 4990 | rc = -ENOMEM; |
4990 | goto fail; | 4991 | goto fail; |
diff --git a/drivers/net/ethernet/sfc/falcon/farch.c b/drivers/net/ethernet/sfc/falcon/farch.c index 494884f6af4a..411a2f419447 100644 --- a/drivers/net/ethernet/sfc/falcon/farch.c +++ b/drivers/net/ethernet/sfc/falcon/farch.c | |||
@@ -2755,7 +2755,8 @@ int ef4_farch_filter_table_probe(struct ef4_nic *efx) | |||
2755 | GFP_KERNEL); | 2755 | GFP_KERNEL); |
2756 | if (!table->used_bitmap) | 2756 | if (!table->used_bitmap) |
2757 | goto fail; | 2757 | goto fail; |
2758 | table->spec = vzalloc(table->size * sizeof(*table->spec)); | 2758 | table->spec = vzalloc(array_size(sizeof(*table->spec), |
2759 | table->size)); | ||
2759 | if (!table->spec) | 2760 | if (!table->spec) |
2760 | goto fail; | 2761 | goto fail; |
2761 | } | 2762 | } |
diff --git a/drivers/net/ethernet/sfc/farch.c b/drivers/net/ethernet/sfc/farch.c index c72adf8b52ea..8edf20967c82 100644 --- a/drivers/net/ethernet/sfc/farch.c +++ b/drivers/net/ethernet/sfc/farch.c | |||
@@ -2826,7 +2826,8 @@ int efx_farch_filter_table_probe(struct efx_nic *efx) | |||
2826 | GFP_KERNEL); | 2826 | GFP_KERNEL); |
2827 | if (!table->used_bitmap) | 2827 | if (!table->used_bitmap) |
2828 | goto fail; | 2828 | goto fail; |
2829 | table->spec = vzalloc(table->size * sizeof(*table->spec)); | 2829 | table->spec = vzalloc(array_size(sizeof(*table->spec), |
2830 | table->size)); | ||
2830 | if (!table->spec) | 2831 | if (!table->spec) |
2831 | goto fail; | 2832 | goto fail; |
2832 | } | 2833 | } |
diff --git a/drivers/net/ppp/pptp.c b/drivers/net/ppp/pptp.c index 157b67c1bf8e..67ffe74747a1 100644 --- a/drivers/net/ppp/pptp.c +++ b/drivers/net/ppp/pptp.c | |||
@@ -648,7 +648,7 @@ static int __init pptp_init_module(void) | |||
648 | int err = 0; | 648 | int err = 0; |
649 | pr_info("PPTP driver version " PPTP_DRIVER_VERSION "\n"); | 649 | pr_info("PPTP driver version " PPTP_DRIVER_VERSION "\n"); |
650 | 650 | ||
651 | callid_sock = vzalloc((MAX_CALLID + 1) * sizeof(void *)); | 651 | callid_sock = vzalloc(array_size(sizeof(void *), (MAX_CALLID + 1))); |
652 | if (!callid_sock) | 652 | if (!callid_sock) |
653 | return -ENOMEM; | 653 | return -ENOMEM; |
654 | 654 | ||
diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c index e1aef253601e..cd51492ae6c2 100644 --- a/drivers/net/xen-netback/xenbus.c +++ b/drivers/net/xen-netback/xenbus.c | |||
@@ -977,8 +977,8 @@ static void connect(struct backend_info *be) | |||
977 | } | 977 | } |
978 | 978 | ||
979 | /* Use the number of queues requested by the frontend */ | 979 | /* Use the number of queues requested by the frontend */ |
980 | be->vif->queues = vzalloc(requested_num_queues * | 980 | be->vif->queues = vzalloc(array_size(requested_num_queues, |
981 | sizeof(struct xenvif_queue)); | 981 | sizeof(struct xenvif_queue))); |
982 | if (!be->vif->queues) { | 982 | if (!be->vif->queues) { |
983 | xenbus_dev_fatal(dev, -ENOMEM, | 983 | xenbus_dev_fatal(dev, -ENOMEM, |
984 | "allocating queues"); | 984 | "allocating queues"); |
diff --git a/drivers/s390/char/sclp_sd.c b/drivers/s390/char/sclp_sd.c index 99f41db5123b..1e244f78f192 100644 --- a/drivers/s390/char/sclp_sd.c +++ b/drivers/s390/char/sclp_sd.c | |||
@@ -300,7 +300,7 @@ static int sclp_sd_store_data(struct sclp_sd_data *result, u8 di) | |||
300 | goto out_result; | 300 | goto out_result; |
301 | 301 | ||
302 | /* Allocate memory */ | 302 | /* Allocate memory */ |
303 | data = vzalloc((size_t) dsize * PAGE_SIZE); | 303 | data = vzalloc(array_size((size_t)dsize, PAGE_SIZE)); |
304 | if (!data) { | 304 | if (!data) { |
305 | rc = -ENOMEM; | 305 | rc = -ENOMEM; |
306 | goto out; | 306 | goto out; |
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c index b965d4fe18ef..94c23ad51179 100644 --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c | |||
@@ -4829,8 +4829,9 @@ megasas_alloc_fusion_context(struct megasas_instance *instance) | |||
4829 | (PLD_SPAN_INFO)__get_free_pages(GFP_KERNEL | __GFP_ZERO, | 4829 | (PLD_SPAN_INFO)__get_free_pages(GFP_KERNEL | __GFP_ZERO, |
4830 | fusion->log_to_span_pages); | 4830 | fusion->log_to_span_pages); |
4831 | if (!fusion->log_to_span) { | 4831 | if (!fusion->log_to_span) { |
4832 | fusion->log_to_span = vzalloc(MAX_LOGICAL_DRIVES_EXT * | 4832 | fusion->log_to_span = |
4833 | sizeof(LD_SPAN_INFO)); | 4833 | vzalloc(array_size(MAX_LOGICAL_DRIVES_EXT, |
4834 | sizeof(LD_SPAN_INFO))); | ||
4834 | if (!fusion->log_to_span) { | 4835 | if (!fusion->log_to_span) { |
4835 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", | 4836 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
4836 | __func__, __LINE__); | 4837 | __func__, __LINE__); |
@@ -4844,8 +4845,9 @@ megasas_alloc_fusion_context(struct megasas_instance *instance) | |||
4844 | (struct LD_LOAD_BALANCE_INFO *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, | 4845 | (struct LD_LOAD_BALANCE_INFO *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, |
4845 | fusion->load_balance_info_pages); | 4846 | fusion->load_balance_info_pages); |
4846 | if (!fusion->load_balance_info) { | 4847 | if (!fusion->load_balance_info) { |
4847 | fusion->load_balance_info = vzalloc(MAX_LOGICAL_DRIVES_EXT * | 4848 | fusion->load_balance_info = |
4848 | sizeof(struct LD_LOAD_BALANCE_INFO)); | 4849 | vzalloc(array_size(MAX_LOGICAL_DRIVES_EXT, |
4850 | sizeof(struct LD_LOAD_BALANCE_INFO))); | ||
4849 | if (!fusion->load_balance_info) | 4851 | if (!fusion->load_balance_info) |
4850 | dev_err(&instance->pdev->dev, "Failed to allocate load_balance_info, " | 4852 | dev_err(&instance->pdev->dev, "Failed to allocate load_balance_info, " |
4851 | "continuing without Load Balance support\n"); | 4853 | "continuing without Load Balance support\n"); |
diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c b/drivers/scsi/qla2xxx/tcm_qla2xxx.c index 0c2e82af9c0a..7732e9336d43 100644 --- a/drivers/scsi/qla2xxx/tcm_qla2xxx.c +++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.c | |||
@@ -1661,7 +1661,9 @@ static int tcm_qla2xxx_init_lport(struct tcm_qla2xxx_lport *lport) | |||
1661 | return rc; | 1661 | return rc; |
1662 | } | 1662 | } |
1663 | 1663 | ||
1664 | lport->lport_loopid_map = vzalloc(sizeof(struct tcm_qla2xxx_fc_loopid) * 65536); | 1664 | lport->lport_loopid_map = |
1665 | vzalloc(array_size(65536, | ||
1666 | sizeof(struct tcm_qla2xxx_fc_loopid))); | ||
1665 | if (!lport->lport_loopid_map) { | 1667 | if (!lport->lport_loopid_map) { |
1666 | pr_err("Unable to allocate lport->lport_loopid_map of %zu bytes\n", | 1668 | pr_err("Unable to allocate lport->lport_loopid_map of %zu bytes\n", |
1667 | sizeof(struct tcm_qla2xxx_fc_loopid) * 65536); | 1669 | sizeof(struct tcm_qla2xxx_fc_loopid) * 65536); |
diff --git a/drivers/soc/fsl/qbman/qman.c b/drivers/soc/fsl/qbman/qman.c index a7e94a3decf2..ecb22749df0b 100644 --- a/drivers/soc/fsl/qbman/qman.c +++ b/drivers/soc/fsl/qbman/qman.c | |||
@@ -1021,7 +1021,8 @@ int qman_alloc_fq_table(u32 _num_fqids) | |||
1021 | { | 1021 | { |
1022 | num_fqids = _num_fqids; | 1022 | num_fqids = _num_fqids; |
1023 | 1023 | ||
1024 | fq_table = vzalloc(num_fqids * 2 * sizeof(struct qman_fq *)); | 1024 | fq_table = vzalloc(array3_size(sizeof(struct qman_fq *), |
1025 | num_fqids, 2)); | ||
1025 | if (!fq_table) | 1026 | if (!fq_table) |
1026 | return -ENOMEM; | 1027 | return -ENOMEM; |
1027 | 1028 | ||
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c b/drivers/staging/rtl8188eu/core/rtw_mlme.c index 24e92998a30c..50e7cae32f75 100644 --- a/drivers/staging/rtl8188eu/core/rtw_mlme.c +++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c | |||
@@ -53,7 +53,7 @@ int rtw_init_mlme_priv(struct adapter *padapter) | |||
53 | 53 | ||
54 | memset(&pmlmepriv->assoc_ssid, 0, sizeof(struct ndis_802_11_ssid)); | 54 | memset(&pmlmepriv->assoc_ssid, 0, sizeof(struct ndis_802_11_ssid)); |
55 | 55 | ||
56 | pbuf = vzalloc(MAX_BSS_CNT * (sizeof(struct wlan_network))); | 56 | pbuf = vzalloc(array_size(MAX_BSS_CNT, sizeof(struct wlan_network))); |
57 | 57 | ||
58 | if (!pbuf) { | 58 | if (!pbuf) { |
59 | res = _FAIL; | 59 | res = _FAIL; |
diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme.c b/drivers/staging/rtl8723bs/core/rtw_mlme.c index cc4f115e082c..f9392b8db49b 100644 --- a/drivers/staging/rtl8723bs/core/rtw_mlme.c +++ b/drivers/staging/rtl8723bs/core/rtw_mlme.c | |||
@@ -37,7 +37,7 @@ sint _rtw_init_mlme_priv(struct adapter *padapter) | |||
37 | 37 | ||
38 | memset(&pmlmepriv->assoc_ssid, 0, sizeof(struct ndis_802_11_ssid)); | 38 | memset(&pmlmepriv->assoc_ssid, 0, sizeof(struct ndis_802_11_ssid)); |
39 | 39 | ||
40 | pbuf = vzalloc(MAX_BSS_CNT * (sizeof(struct wlan_network))); | 40 | pbuf = vzalloc(array_size(MAX_BSS_CNT, sizeof(struct wlan_network))); |
41 | 41 | ||
42 | if (pbuf == NULL) { | 42 | if (pbuf == NULL) { |
43 | res = _FAIL; | 43 | res = _FAIL; |
diff --git a/drivers/staging/rts5208/rtsx_chip.c b/drivers/staging/rts5208/rtsx_chip.c index f8f9579cc679..8a823466ca2b 100644 --- a/drivers/staging/rts5208/rtsx_chip.c +++ b/drivers/staging/rts5208/rtsx_chip.c | |||
@@ -1660,13 +1660,13 @@ int rtsx_write_cfg_seq(struct rtsx_chip *chip, u8 func, u16 addr, u8 *buf, | |||
1660 | 1660 | ||
1661 | dev_dbg(rtsx_dev(chip), "dw_len = %d\n", dw_len); | 1661 | dev_dbg(rtsx_dev(chip), "dw_len = %d\n", dw_len); |
1662 | 1662 | ||
1663 | data = vzalloc(dw_len * 4); | 1663 | data = vzalloc(array_size(dw_len, 4)); |
1664 | if (!data) { | 1664 | if (!data) { |
1665 | rtsx_trace(chip); | 1665 | rtsx_trace(chip); |
1666 | return STATUS_NOMEM; | 1666 | return STATUS_NOMEM; |
1667 | } | 1667 | } |
1668 | 1668 | ||
1669 | mask = vzalloc(dw_len * 4); | 1669 | mask = vzalloc(array_size(dw_len, 4)); |
1670 | if (!mask) { | 1670 | if (!mask) { |
1671 | vfree(data); | 1671 | vfree(data); |
1672 | rtsx_trace(chip); | 1672 | rtsx_trace(chip); |
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index efe8214f2df3..ee5081ba5313 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c | |||
@@ -253,7 +253,7 @@ int transport_alloc_session_tags(struct se_session *se_sess, | |||
253 | se_sess->sess_cmd_map = kcalloc(tag_size, tag_num, | 253 | se_sess->sess_cmd_map = kcalloc(tag_size, tag_num, |
254 | GFP_KERNEL | __GFP_NOWARN | __GFP_RETRY_MAYFAIL); | 254 | GFP_KERNEL | __GFP_NOWARN | __GFP_RETRY_MAYFAIL); |
255 | if (!se_sess->sess_cmd_map) { | 255 | if (!se_sess->sess_cmd_map) { |
256 | se_sess->sess_cmd_map = vzalloc(tag_num * tag_size); | 256 | se_sess->sess_cmd_map = vzalloc(array_size(tag_size, tag_num)); |
257 | if (!se_sess->sess_cmd_map) { | 257 | if (!se_sess->sess_cmd_map) { |
258 | pr_err("Unable to allocate se_sess->sess_cmd_map\n"); | 258 | pr_err("Unable to allocate se_sess->sess_cmd_map\n"); |
259 | return -ENOMEM; | 259 | return -ENOMEM; |
diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c index 334f2ad60704..223b3b2dff87 100644 --- a/fs/nfsd/nfscache.c +++ b/fs/nfsd/nfscache.c | |||
@@ -177,7 +177,8 @@ int nfsd_reply_cache_init(void) | |||
177 | 177 | ||
178 | drc_hashtbl = kcalloc(hashsize, sizeof(*drc_hashtbl), GFP_KERNEL); | 178 | drc_hashtbl = kcalloc(hashsize, sizeof(*drc_hashtbl), GFP_KERNEL); |
179 | if (!drc_hashtbl) { | 179 | if (!drc_hashtbl) { |
180 | drc_hashtbl = vzalloc(hashsize * sizeof(*drc_hashtbl)); | 180 | drc_hashtbl = vzalloc(array_size(hashsize, |
181 | sizeof(*drc_hashtbl))); | ||
181 | if (!drc_hashtbl) | 182 | if (!drc_hashtbl) |
182 | goto out_nomem; | 183 | goto out_nomem; |
183 | } | 184 | } |
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c index 358ee2a1ce1a..52eb5d293a34 100644 --- a/fs/reiserfs/journal.c +++ b/fs/reiserfs/journal.c | |||
@@ -350,7 +350,8 @@ static struct reiserfs_journal_cnode *allocate_cnodes(int num_cnodes) | |||
350 | if (num_cnodes <= 0) { | 350 | if (num_cnodes <= 0) { |
351 | return NULL; | 351 | return NULL; |
352 | } | 352 | } |
353 | head = vzalloc(num_cnodes * sizeof(struct reiserfs_journal_cnode)); | 353 | head = vzalloc(array_size(num_cnodes, |
354 | sizeof(struct reiserfs_journal_cnode))); | ||
354 | if (!head) { | 355 | if (!head) { |
355 | return NULL; | 356 | return NULL; |
356 | } | 357 | } |
diff --git a/fs/reiserfs/resize.c b/fs/reiserfs/resize.c index 6052d323bc9a..8096c74c38ac 100644 --- a/fs/reiserfs/resize.c +++ b/fs/reiserfs/resize.c | |||
@@ -120,7 +120,8 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new) | |||
120 | * array of bitmap block pointers | 120 | * array of bitmap block pointers |
121 | */ | 121 | */ |
122 | bitmap = | 122 | bitmap = |
123 | vzalloc(sizeof(struct reiserfs_bitmap_info) * bmap_nr_new); | 123 | vzalloc(array_size(bmap_nr_new, |
124 | sizeof(struct reiserfs_bitmap_info))); | ||
124 | if (!bitmap) { | 125 | if (!bitmap) { |
125 | /* | 126 | /* |
126 | * Journal bitmaps are still supersized, but the | 127 | * Journal bitmaps are still supersized, but the |
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 1494e087890e..9e2bf834f13a 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c | |||
@@ -5206,7 +5206,8 @@ static int adjust_insn_aux_data(struct bpf_verifier_env *env, u32 prog_len, | |||
5206 | 5206 | ||
5207 | if (cnt == 1) | 5207 | if (cnt == 1) |
5208 | return 0; | 5208 | return 0; |
5209 | new_data = vzalloc(sizeof(struct bpf_insn_aux_data) * prog_len); | 5209 | new_data = vzalloc(array_size(prog_len, |
5210 | sizeof(struct bpf_insn_aux_data))); | ||
5210 | if (!new_data) | 5211 | if (!new_data) |
5211 | return -ENOMEM; | 5212 | return -ENOMEM; |
5212 | memcpy(new_data, old_data, sizeof(struct bpf_insn_aux_data) * off); | 5213 | memcpy(new_data, old_data, sizeof(struct bpf_insn_aux_data) * off); |
@@ -5870,8 +5871,9 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr) | |||
5870 | return -ENOMEM; | 5871 | return -ENOMEM; |
5871 | log = &env->log; | 5872 | log = &env->log; |
5872 | 5873 | ||
5873 | env->insn_aux_data = vzalloc(sizeof(struct bpf_insn_aux_data) * | 5874 | env->insn_aux_data = |
5874 | (*prog)->len); | 5875 | vzalloc(array_size(sizeof(struct bpf_insn_aux_data), |
5876 | (*prog)->len)); | ||
5875 | ret = -ENOMEM; | 5877 | ret = -ENOMEM; |
5876 | if (!env->insn_aux_data) | 5878 | if (!env->insn_aux_data) |
5877 | goto err_free_env; | 5879 | goto err_free_env; |
diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 75d8e7cf040e..c6a3b6851372 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c | |||
@@ -793,7 +793,7 @@ static int kexec_purgatory_setup_sechdrs(struct purgatory_info *pi, | |||
793 | * The section headers in kexec_purgatory are read-only. In order to | 793 | * The section headers in kexec_purgatory are read-only. In order to |
794 | * have them modifiable make a temporary copy. | 794 | * have them modifiable make a temporary copy. |
795 | */ | 795 | */ |
796 | sechdrs = vzalloc(pi->ehdr->e_shnum * sizeof(Elf_Shdr)); | 796 | sechdrs = vzalloc(array_size(sizeof(Elf_Shdr), pi->ehdr->e_shnum)); |
797 | if (!sechdrs) | 797 | if (!sechdrs) |
798 | return -ENOMEM; | 798 | return -ENOMEM; |
799 | memcpy(sechdrs, (void *)pi->ehdr + pi->ehdr->e_shoff, | 799 | memcpy(sechdrs, (void *)pi->ehdr + pi->ehdr->e_shoff, |
diff --git a/lib/test_firmware.c b/lib/test_firmware.c index cee000ac54d8..b984806d7d7b 100644 --- a/lib/test_firmware.c +++ b/lib/test_firmware.c | |||
@@ -618,8 +618,9 @@ static ssize_t trigger_batched_requests_store(struct device *dev, | |||
618 | 618 | ||
619 | mutex_lock(&test_fw_mutex); | 619 | mutex_lock(&test_fw_mutex); |
620 | 620 | ||
621 | test_fw_config->reqs = vzalloc(sizeof(struct test_batched_req) * | 621 | test_fw_config->reqs = |
622 | test_fw_config->num_requests * 2); | 622 | vzalloc(array3_size(sizeof(struct test_batched_req), |
623 | test_fw_config->num_requests, 2)); | ||
623 | if (!test_fw_config->reqs) { | 624 | if (!test_fw_config->reqs) { |
624 | rc = -ENOMEM; | 625 | rc = -ENOMEM; |
625 | goto out_unlock; | 626 | goto out_unlock; |
@@ -720,8 +721,9 @@ ssize_t trigger_batched_requests_async_store(struct device *dev, | |||
720 | 721 | ||
721 | mutex_lock(&test_fw_mutex); | 722 | mutex_lock(&test_fw_mutex); |
722 | 723 | ||
723 | test_fw_config->reqs = vzalloc(sizeof(struct test_batched_req) * | 724 | test_fw_config->reqs = |
724 | test_fw_config->num_requests * 2); | 725 | vzalloc(array3_size(sizeof(struct test_batched_req), |
726 | test_fw_config->num_requests, 2)); | ||
725 | if (!test_fw_config->reqs) { | 727 | if (!test_fw_config->reqs) { |
726 | rc = -ENOMEM; | 728 | rc = -ENOMEM; |
727 | goto out; | 729 | goto out; |
diff --git a/lib/test_kmod.c b/lib/test_kmod.c index 0e5b7a61460b..e3ddd836491f 100644 --- a/lib/test_kmod.c +++ b/lib/test_kmod.c | |||
@@ -779,8 +779,9 @@ static int kmod_config_sync_info(struct kmod_test_device *test_dev) | |||
779 | struct test_config *config = &test_dev->config; | 779 | struct test_config *config = &test_dev->config; |
780 | 780 | ||
781 | free_test_dev_info(test_dev); | 781 | free_test_dev_info(test_dev); |
782 | test_dev->info = vzalloc(config->num_threads * | 782 | test_dev->info = |
783 | sizeof(struct kmod_test_device_info)); | 783 | vzalloc(array_size(sizeof(struct kmod_test_device_info), |
784 | config->num_threads)); | ||
784 | if (!test_dev->info) | 785 | if (!test_dev->info) |
785 | return -ENOMEM; | 786 | return -ENOMEM; |
786 | 787 | ||
diff --git a/lib/test_rhashtable.c b/lib/test_rhashtable.c index f4000c137dbe..fb6968109113 100644 --- a/lib/test_rhashtable.c +++ b/lib/test_rhashtable.c | |||
@@ -285,12 +285,14 @@ static int __init test_rhltable(unsigned int entries) | |||
285 | if (entries == 0) | 285 | if (entries == 0) |
286 | entries = 1; | 286 | entries = 1; |
287 | 287 | ||
288 | rhl_test_objects = vzalloc(sizeof(*rhl_test_objects) * entries); | 288 | rhl_test_objects = vzalloc(array_size(entries, |
289 | sizeof(*rhl_test_objects))); | ||
289 | if (!rhl_test_objects) | 290 | if (!rhl_test_objects) |
290 | return -ENOMEM; | 291 | return -ENOMEM; |
291 | 292 | ||
292 | ret = -ENOMEM; | 293 | ret = -ENOMEM; |
293 | obj_in_table = vzalloc(BITS_TO_LONGS(entries) * sizeof(unsigned long)); | 294 | obj_in_table = vzalloc(array_size(sizeof(unsigned long), |
295 | BITS_TO_LONGS(entries))); | ||
294 | if (!obj_in_table) | 296 | if (!obj_in_table) |
295 | goto out_free; | 297 | goto out_free; |
296 | 298 | ||
@@ -706,7 +708,8 @@ static int __init test_rht_init(void) | |||
706 | test_rht_params.max_size = max_size ? : roundup_pow_of_two(entries); | 708 | test_rht_params.max_size = max_size ? : roundup_pow_of_two(entries); |
707 | test_rht_params.nelem_hint = size; | 709 | test_rht_params.nelem_hint = size; |
708 | 710 | ||
709 | objs = vzalloc((test_rht_params.max_size + 1) * sizeof(struct test_obj)); | 711 | objs = vzalloc(array_size(sizeof(struct test_obj), |
712 | test_rht_params.max_size + 1)); | ||
710 | if (!objs) | 713 | if (!objs) |
711 | return -ENOMEM; | 714 | return -ENOMEM; |
712 | 715 | ||
@@ -753,10 +756,10 @@ static int __init test_rht_init(void) | |||
753 | pr_info("Testing concurrent rhashtable access from %d threads\n", | 756 | pr_info("Testing concurrent rhashtable access from %d threads\n", |
754 | tcount); | 757 | tcount); |
755 | sema_init(&prestart_sem, 1 - tcount); | 758 | sema_init(&prestart_sem, 1 - tcount); |
756 | tdata = vzalloc(tcount * sizeof(struct thread_data)); | 759 | tdata = vzalloc(array_size(tcount, sizeof(struct thread_data))); |
757 | if (!tdata) | 760 | if (!tdata) |
758 | return -ENOMEM; | 761 | return -ENOMEM; |
759 | objs = vzalloc(tcount * entries * sizeof(struct test_obj)); | 762 | objs = vzalloc(array3_size(sizeof(struct test_obj), tcount, entries)); |
760 | if (!objs) { | 763 | if (!objs) { |
761 | vfree(tdata); | 764 | vfree(tdata); |
762 | return -ENOMEM; | 765 | return -ENOMEM; |
diff --git a/net/core/ethtool.c b/net/core/ethtool.c index 8be6be2d9c7b..e677a20180cf 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c | |||
@@ -1852,7 +1852,7 @@ static int ethtool_get_strings(struct net_device *dev, void __user *useraddr) | |||
1852 | WARN_ON_ONCE(!ret); | 1852 | WARN_ON_ONCE(!ret); |
1853 | 1853 | ||
1854 | gstrings.len = ret; | 1854 | gstrings.len = ret; |
1855 | data = vzalloc(gstrings.len * ETH_GSTRING_LEN); | 1855 | data = vzalloc(array_size(gstrings.len, ETH_GSTRING_LEN)); |
1856 | if (gstrings.len && !data) | 1856 | if (gstrings.len && !data) |
1857 | return -ENOMEM; | 1857 | return -ENOMEM; |
1858 | 1858 | ||
@@ -1952,7 +1952,7 @@ static int ethtool_get_stats(struct net_device *dev, void __user *useraddr) | |||
1952 | return -EFAULT; | 1952 | return -EFAULT; |
1953 | 1953 | ||
1954 | stats.n_stats = n_stats; | 1954 | stats.n_stats = n_stats; |
1955 | data = vzalloc(n_stats * sizeof(u64)); | 1955 | data = vzalloc(array_size(n_stats, sizeof(u64))); |
1956 | if (n_stats && !data) | 1956 | if (n_stats && !data) |
1957 | return -ENOMEM; | 1957 | return -ENOMEM; |
1958 | 1958 | ||
@@ -1996,7 +1996,7 @@ static int ethtool_get_phy_stats(struct net_device *dev, void __user *useraddr) | |||
1996 | return -EFAULT; | 1996 | return -EFAULT; |
1997 | 1997 | ||
1998 | stats.n_stats = n_stats; | 1998 | stats.n_stats = n_stats; |
1999 | data = vzalloc(n_stats * sizeof(u64)); | 1999 | data = vzalloc(array_size(n_stats, sizeof(u64))); |
2000 | if (n_stats && !data) | 2000 | if (n_stats && !data) |
2001 | return -ENOMEM; | 2001 | return -ENOMEM; |
2002 | 2002 | ||
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index ee018564b2b4..50809748c127 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c | |||
@@ -4161,7 +4161,7 @@ static char *alloc_one_pg_vec_page(unsigned long order) | |||
4161 | return buffer; | 4161 | return buffer; |
4162 | 4162 | ||
4163 | /* __get_free_pages failed, fall back to vmalloc */ | 4163 | /* __get_free_pages failed, fall back to vmalloc */ |
4164 | buffer = vzalloc((1 << order) * PAGE_SIZE); | 4164 | buffer = vzalloc(array_size((1 << order), PAGE_SIZE)); |
4165 | if (buffer) | 4165 | if (buffer) |
4166 | return buffer; | 4166 | return buffer; |
4167 | 4167 | ||