Commit 9f2378d9 authored by Kees Cook's avatar Kees Cook Committed by Greg Kroah-Hartman

drivers/staging/gasket: Use 2-factor allocator calls

As already done treewide, switch from open-coded multiplication to using
2-factor allocator helpers.
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 7383f87d
...@@ -1697,9 +1697,9 @@ static int gasket_mmap(struct file *filp, struct vm_area_struct *vma) ...@@ -1697,9 +1697,9 @@ static int gasket_mmap(struct file *filp, struct vm_area_struct *vma)
return -EPERM; return -EPERM;
} }
num_map_regions = bar_desc->num_mappable_regions; num_map_regions = bar_desc->num_mappable_regions;
map_regions = kzalloc( map_regions = kcalloc(num_map_regions,
num_map_regions * sizeof(*bar_desc->mappable_regions), sizeof(*bar_desc->mappable_regions),
GFP_KERNEL); GFP_KERNEL);
if (map_regions) { if (map_regions) {
memcpy(map_regions, bar_desc->mappable_regions, memcpy(map_regions, bar_desc->mappable_regions,
num_map_regions * num_map_regions *
......
...@@ -136,23 +136,26 @@ int gasket_interrupt_init( ...@@ -136,23 +136,26 @@ int gasket_interrupt_init(
interrupt_data->wire_interrupt_offsets = wire_int_offsets; interrupt_data->wire_interrupt_offsets = wire_int_offsets;
/* Allocate all dynamic structures. */ /* Allocate all dynamic structures. */
interrupt_data->msix_entries = kzalloc( interrupt_data->msix_entries = kcalloc(num_interrupts,
sizeof(struct msix_entry) * num_interrupts, GFP_KERNEL); sizeof(struct msix_entry),
GFP_KERNEL);
if (!interrupt_data->msix_entries) { if (!interrupt_data->msix_entries) {
kfree(interrupt_data); kfree(interrupt_data);
return -ENOMEM; return -ENOMEM;
} }
interrupt_data->eventfd_ctxs = kzalloc( interrupt_data->eventfd_ctxs = kcalloc(num_interrupts,
sizeof(struct eventfd_ctx *) * num_interrupts, GFP_KERNEL); sizeof(struct eventfd_ctx *),
GFP_KERNEL);
if (!interrupt_data->eventfd_ctxs) { if (!interrupt_data->eventfd_ctxs) {
kfree(interrupt_data->msix_entries); kfree(interrupt_data->msix_entries);
kfree(interrupt_data); kfree(interrupt_data);
return -ENOMEM; return -ENOMEM;
} }
interrupt_data->interrupt_counts = kzalloc( interrupt_data->interrupt_counts = kcalloc(num_interrupts,
sizeof(ulong) * num_interrupts, GFP_KERNEL); sizeof(ulong),
GFP_KERNEL);
if (!interrupt_data->interrupt_counts) { if (!interrupt_data->interrupt_counts) {
kfree(interrupt_data->eventfd_ctxs); kfree(interrupt_data->eventfd_ctxs);
kfree(interrupt_data->msix_entries); kfree(interrupt_data->msix_entries);
......
...@@ -1674,9 +1674,9 @@ int gasket_alloc_coherent_memory(struct gasket_dev *gasket_dev, u64 size, ...@@ -1674,9 +1674,9 @@ int gasket_alloc_coherent_memory(struct gasket_dev *gasket_dev, u64 size,
gasket_dev->page_table[index]->num_coherent_pages = num_pages; gasket_dev->page_table[index]->num_coherent_pages = num_pages;
/* allocate the physical memory block */ /* allocate the physical memory block */
gasket_dev->page_table[index]->coherent_pages = kzalloc( gasket_dev->page_table[index]->coherent_pages =
num_pages * sizeof(struct gasket_coherent_page_entry), kcalloc(num_pages, sizeof(struct gasket_coherent_page_entry),
GFP_KERNEL); GFP_KERNEL);
if (!gasket_dev->page_table[index]->coherent_pages) if (!gasket_dev->page_table[index]->coherent_pages)
goto nomem; goto nomem;
*dma_address = 0; *dma_address = 0;
......
...@@ -137,9 +137,9 @@ static void put_mapping(struct gasket_sysfs_mapping *mapping) ...@@ -137,9 +137,9 @@ static void put_mapping(struct gasket_sysfs_mapping *mapping)
device = mapping->device; device = mapping->device;
legacy_device = mapping->legacy_device; legacy_device = mapping->legacy_device;
num_files_to_remove = mapping->attribute_count; num_files_to_remove = mapping->attribute_count;
files_to_remove = kzalloc( files_to_remove = kcalloc(num_files_to_remove,
num_files_to_remove * sizeof(*files_to_remove), sizeof(*files_to_remove),
GFP_KERNEL); GFP_KERNEL);
for (i = 0; i < num_files_to_remove; i++) for (i = 0; i < num_files_to_remove; i++)
files_to_remove[i] = mapping->attributes[i].attr; files_to_remove[i] = mapping->attributes[i].attr;
...@@ -238,9 +238,9 @@ int gasket_sysfs_create_mapping( ...@@ -238,9 +238,9 @@ int gasket_sysfs_create_mapping(
kref_init(&mapping->refcount); kref_init(&mapping->refcount);
mapping->device = device; mapping->device = device;
mapping->gasket_dev = gasket_dev; mapping->gasket_dev = gasket_dev;
mapping->attributes = kzalloc( mapping->attributes = kcalloc(GASKET_SYSFS_MAX_NODES,
GASKET_SYSFS_MAX_NODES * sizeof(*mapping->attributes), sizeof(*mapping->attributes),
GFP_KERNEL); GFP_KERNEL);
mapping->attribute_count = 0; mapping->attribute_count = 0;
if (!mapping->attributes) { if (!mapping->attributes) {
gasket_nodev_error("Unable to allocate sysfs attribute array."); gasket_nodev_error("Unable to allocate sysfs attribute array.");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment